mirror of
https://github.com/janet-lang/janet
synced 2026-09-19 15:50:41 +00:00
Move pretty printer into boot.dst
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
# A simple fizz buzz example
|
||||
|
||||
(defn fizzbuzz
|
||||
"Prints the fizzbuzz problem."
|
||||
[]
|
||||
(for [i 1 101]
|
||||
(let [fizz (zero? (% i 3))
|
||||
buzz (zero? (% i 5))]
|
||||
(print (cond
|
||||
(and fizz buzz) "fizzbuzz"
|
||||
fizz "fizz"
|
||||
buzz "buzz"
|
||||
i)))))
|
||||
@@ -0,0 +1,11 @@
|
||||
# Get the number of occurences of elements in a set
|
||||
|
||||
(defn frequencies
|
||||
"Get the number of occurences of each value in a sequence."
|
||||
[s]
|
||||
(let [freqs @{}
|
||||
fop (fn [x]
|
||||
(let [n (get freqs x)]
|
||||
(put freqs x (if n (+ 1 n) 1))))
|
||||
_ (domap fop s)]
|
||||
freqs))
|
||||
@@ -0,0 +1,3 @@
|
||||
# Prints hello
|
||||
|
||||
(print "hello, world!")
|
||||
@@ -0,0 +1,14 @@
|
||||
# Return an array of primes. This is a trivial and extremely naive algorithm.
|
||||
|
||||
(defn primes
|
||||
"Returns a list of prime numbers less than n."
|
||||
[n]
|
||||
(def list [])
|
||||
(for [i 2 n]
|
||||
(var isprime? true)
|
||||
(def len (length list))
|
||||
(for [j 0 len]
|
||||
(def trial (get list j))
|
||||
(if (zero? (% i trial)) (varset! isprime? false)))
|
||||
(if isprime? (array-push list i)))
|
||||
list)
|
||||
Reference in New Issue
Block a user