4 ms·
10 rem Using GW-Basic 15 end_of_list=10000000 20 For x=1 to x=end_of_list 30 a(x) = a(x) + 1 40 next x 50 rem Done counting, print the result 60 for x=1 t
by woliveirajr 9y ago
10 rem Using GW-Basic
15 end_of_list=10000000
20 For x=1 to x=end_of_list
30 a(x) = a(x) + 1
40 next x
50 rem Done counting, print the result
60 for x=1 to x=end_of_list
70 print "Value " x " has " a(x) " repetitions"
80 next x
- contravariant 9y agoYou're going to build an array of 2^64 ints?
- woliveirajr 9y agoIt would build an array of n distinct elements. And for efficiency, this comment [0] is about the drawbacks of the solutions used in the article. [0] https://news.ycombinator.com/item?id=14407404 https://news.ycombinator.com/item?id=14407404
- contravariant 9y agoFor the line "70 print "Value " x " has " a(x) " repetitions"" to work you'd need an array with 2^64 elements. That said the code as you wrote it would just result in an array filled with 10 million entries, all of which are 1 (assuming the array is initialized to 0).
- woliveirajr 9y agoYou're right, I was just thinking in the counting of repeated values. Can't edit to correct now...