Created
March 2, 2018 08:24
-
-
Save germ13/6cbaeb7bd5cc9ca39539c081be9bf7c0 to your computer and use it in GitHub Desktop.
Codewars Kata: Shell Game (Clojure)
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
(ns the-shell-game) | |
;;https://www.codewars.com/kata/the-shell-game/clojure | |
(defn switch [location swap] | |
(cond (= location (first swap)) | |
(last swap) | |
(= location (last swap)) | |
(first swap) | |
:else | |
location)) | |
(defn find-the-ball [start swaps] | |
"Given the starting position and a list of swaps, find the final position" | |
(if (nil? (first swaps)) | |
start | |
(find-the-ball | |
(switch start (first swaps)) | |
(rest swaps)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Maybe I'm restating what you just said.
Line 18 and 19 are the new values (the new state) in the recursive call.