For those who are familiar with Clojure might find it easy but for me it took a while and I couldn't solve it so I decided to start solving it with Ruby first.
This is my solution.
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
pi = ->x = 0 do | |
puts x | |
->{ pi[x + 1] } | |
end | |
# result | |
> pi[][][][][][][] | |
0 | |
1 | |
2 | |
3 | |
4 | |
5 | |
6 |
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
(defn pi | |
([] (pi 0)) | |
([x] (println x) #(pi (+ x 1)))) | |
; result | |
=> (((((((pi))))))) | |
0 | |
1 | |
2 | |
3 | |
4 | |
5 | |
6 |
No comments:
Post a Comment