Skip to content

Instantly share code, notes, and snippets.

@domgetter
Last active January 6, 2016 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save domgetter/2939fd3f5c45fd082a25 to your computer and use it in GitHub Desktop.
Save domgetter/2939fd3f5c45fd082a25 to your computer and use it in GitHub Desktop.
(def words ["or" "line" "important" "may" "life" "mountain" "went"
"change" "along" "water" "through" "just" "look" "because" "than" "into"
"three" "after" "does" "stop" "get" "eye" "small" "world" "carry" "play"
"all" "really" "before" "don't" "family" "river" "enough" "another" "came"
"number" "why" "might" "write" "must" "other" "air" "something" "even" "own"
"children" "in" "keep" "saw" "kind" "see" "without" "country" "left" "night"
"story" "about" "but" "cut" "at" "few" "question" "began" "almost" "let" "put"
"again" "side" "good" "four" "always" "mile" "soon" "know" "man" "should"
"live" "begin" "more"])
(defn rows [[full pending] word]
(if (> (apply + (count word) (map count pending)) 35) ; if the row would be more than 35 character total
[(conj full pending) [word]] ; put the word in a new row
[full (conj pending word)])) ; otherwise, tack it on the end of the current row
(apply conj (reduce rows [[] []] words))
; [["or" "line" "important" "may" "life" "mountain" "went"]
; ["change" "along" "water" "through" "just" "look"]
; ["because" "than" "into" "three" "after" "does" "stop"]
; ["get" "eye" "small" "world" "carry" "play" "all" "really"]
; ["before" "don't" "family" "river" "enough" "another"]
; ["came" "number" "why" "might" "write" "must" "other" "air"]
; ["something" "even" "own" "children" "in" "keep" "saw"]
; ["kind" "see" "without" "country" "left" "night" "story"]
; ["about" "but" "cut" "at" "few" "question" "began" "almost"]
; ["let" "put" "again" "side" "good" "four" "always" "mile"]
; ["soon" "know" "man" "should" "live" "begin" "more"]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment