Hacker News new | past | comments | ask | show | jobs | submit login
Code Riffs (fogus.me)
27 points by janvdberg on Jan 7, 2023 | hide | past | favorite | 2 comments



Sequencing is a structure.

Choice is another.

Repetition/Recursion is a third.

Now write a program.

cf https://www.artcollectorz.com/assets/managed/images/cache/AA...


Like this?

  (defn any-mod-cycle-buzz
   "Given a number and a sequence of words mapping to prime factors,
    either return the corresponding word-version for the number position,
    or the number itself, if no prime factor exists.

    Basically, the set of words should map to set of prime factors.

    We also don't make any assumptions about order of words here. It is up
    to the caller to choose whatever sequence they please."
    [num & words]
    (or (not-empty (reduce str words))
        num))
  
  ;; invoked as...
  (map any-mod-cycle-buzz
       (range 1 16)
       (cycle [nil nil "Fizz"])
       (cycle [nil nil nil nil "Buzz"]))

edit: indentation




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: