Skip to content

Instantly share code, notes, and snippets.

@benzap
Created May 28, 2018 07:22
Show Gist options
  • Save benzap/d1e5ab6eec4f16827ff49dc2f21b382e to your computer and use it in GitHub Desktop.
Save benzap/d1e5ab6eec4f16827ff49dc2f21b382e to your computer and use it in GitHub Desktop.
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