-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #223 from PEZ/babashka
Babashka: Use separate code from Clojure
- Loading branch information
Showing
4 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
(defn- fibonacci [n] | ||
(case n | ||
0 0 | ||
1 1 | ||
(+ (fibonacci (- n 1)) | ||
(fibonacci (- n 2))))) | ||
|
||
(defn main [u] | ||
(println (reduce + (map fibonacci (range u))))) | ||
|
||
(main (-> *command-line-args* first parse-long)) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(println "Hello, World!") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
(defn main [u] | ||
(let [r (rand-int 10000) ; Get a random number 0 <= r < 10k | ||
v' (vec (repeat 10000 0)) ; Vector of 10k elements initialized to 0 | ||
v (mapv (fn [initial-value] | ||
(let [inner-sum (reduce (fn [sum j] | ||
(+ sum (rem j u))) ; Simple sum | ||
initial-value | ||
(range 100000))] ; 100k inner loop iterations, per outer loop iteration | ||
(+ inner-sum r))) ; Add a random value to each element in array | ||
v')] ; 10k outer loop iterations | ||
(println (nth v r)))) ; Print out a single element from the array | ||
|
||
(main (-> *command-line-args* first parse-long)) ; Get an input number from the command line |
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