Skip to content

Instantly share code, notes, and snippets.

@purcell
Created October 20, 2011 10:07
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 purcell/1300810 to your computer and use it in GitHub Desktop.
Save purcell/1300810 to your computer and use it in GitHub Desktop.
(defn follow-chain [base-url number]
(let [result (slurp (str base-url number))]
(if-let [next-number
(if (re-find #"^Yes" result)
(/ (Integer/parseInt number) 2)
(let [idx (.indexOf result "and the next")]
(when (>= idx 0)
(last (string/split (subs result idx) #" ")))))]
(do
(println result)
(recur base-url next-number))
result)))
@purcell
Copy link
Author

purcell commented Oct 20, 2011

Obviously without the println and resulting do block, this would look neater.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment