4 ms·
In racket I would probably use a wheel for a more general solution: (define wheel '(#f #f "fizz" #f "buzz" "fizz" #f #f "fizz" "buzz" #f "fizz" #f #f "fizz
by bjoli 8y ago
In racket I would probably use a wheel for a more general solution:
(define wheel '(#f #f "fizz" #f "buzz" "fizz" #f #f "fizz" "buzz" #f "fizz" #f #f "fizzbuzz"))
(for ((fb? (in-cycle wheel)) (i (in-range 1 101)))
(displayln (or fb? i)))
It would be more elegant in a lazy language, but it is probably quite fast since it doesn't need any division (?? My assumption here might be wrong). I typed this out on my phone, so it might not work, and racket isn't my daily driver.
Edit: My initial assumption was correct, but the in-cycle sequence creator has a very large overhead. The final solution for racket (Ugly, because mlist doesn't have any nice things included): https://pastebin.com/aB2BLY1U https://pastebin.com/aB2BLY1U
The mutable list solution (as one would write it in scheme) is more than twice as fast as the remainder one, and I expect it to be for other languages as well.