Instantly share code, notes, and snippets.

Embed
What would you like to do?
Higher Order fizzbuzz from reddit post
;; From reddit comments
;; https://www.reddit.com/r/Clojure/comments/8lizcb/rclojure_fizz_buzz_contest_hardmode/
$clear-stack
doc higher-fizzbuzz
"( map seq -- seq ) Returns modified seq with map target factors."
fn higher-fizzbuzz
*xs <> setl
*m <> setl
let factor-map m
doc first-target-factor "( n -- fb-result )"
fn first-target-factor
*n <> setl
;; In order to sort it, turn it into a vector of map entries
[] factor-map into sort
(dup first n <> mod zero?
if [over second true <>] ? <> drop else drop nil then) <> map
(first true?) <> filter
*second <> map
*str <> reduce
dup nil? if drop n then
endfn
*first-target-factor xs map
endfn
{2 "blah" 3 "fizz" 5 "buzz"} 1 20 range higher-fizzbuzz
.s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment