Skip to content

Instantly share code, notes, and snippets.

@purcell
Created October 20, 2011 10:07
Show Gist options
  • Select an option

  • Save purcell/1300810 to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown
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