diff --git a/fibonacci/bb/code.clj b/fibonacci/bb/code.clj new file mode 100644 index 00000000..7ebcb6c0 --- /dev/null +++ b/fibonacci/bb/code.clj @@ -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)) \ No newline at end of file diff --git a/hello-world/bb/code.clj b/hello-world/bb/code.clj new file mode 100644 index 00000000..2cb98fb9 --- /dev/null +++ b/hello-world/bb/code.clj @@ -0,0 +1 @@ +(println "Hello, World!") \ No newline at end of file diff --git a/loops/bb/code.clj b/loops/bb/code.clj new file mode 100644 index 00000000..12dc4f5f --- /dev/null +++ b/loops/bb/code.clj @@ -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 diff --git a/run.sh b/run.sh index 50297c6b..bb04871f 100755 --- a/run.sh +++ b/run.sh @@ -51,6 +51,7 @@ run "Haskell" "" "./hs/code" run "V" "" "./v/code" run "Chez Scheme" "chez --program" "./chez/code.so" run "Clojure" "java -cp clojure/classes:$(clojure -Spath)" "./clojure/code" +run "Babashka" "bb" "./bb/code.clj" run "COBOL" "" "./cobol/main" #run "MAWK" "mawk -f" "./awk/code.awk" #run "Babashka" "bb -cp clojure -m" "./babashka/code"