Created
December 8, 2011 06:57
-
-
Save anonymous/1446330 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; flengyel's solution to Sequs Horribilis | |
;; https://4clojure.com/problem/112 | |
(fn [n s] | |
(letfn [(sequs [n s] | |
(loop [acc 0 v [] s s] | |
(if (or (empty? s) (< n acc)) | |
[acc v] | |
(let [elt (first s)] | |
(if (vector? elt) | |
(let [[m t] (sequs (- n acc) elt) | |
newacc (+ acc m)] | |
(recur newacc (if (empty? t) v (conj v t)) (rest s))) | |
(let [newacc (+ acc elt)] | |
(recur newacc (if (< n newacc) v (conj v elt)) (rest s))))))))] | |
(second (sequs n s)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment