mirror of
https://github.com/janet-lang/janet
synced 2026-08-31 22:58:51 +00:00
Rename seq abstraction to iterator. Add random functions.
This commit is contained in:
+3
-3
@@ -2,7 +2,7 @@
|
||||
"Solve the 3SUM problem O(n^2) time."
|
||||
[s]
|
||||
(def tab @{})
|
||||
(def solutions [])
|
||||
(def solutions @{})
|
||||
(def len (length s))
|
||||
(for [k 0 len]
|
||||
(put tab (get s k) k))
|
||||
@@ -10,5 +10,5 @@
|
||||
(for [j 0 len]
|
||||
(def k (get tab (- 0 (get s i) (get s j))))
|
||||
(when (and k (not= k i) (not= k j) (not= i j))
|
||||
(array-push solutions [i j k]))))
|
||||
solutions)
|
||||
(put solutions {i true j true k true} true))))
|
||||
(iter2array (map (fn [x] (iter2array (keys x))) (keys solutions))))
|
||||
|
||||
@@ -4,8 +4,7 @@
|
||||
"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)]
|
||||
_ (foreach s (fn [x]
|
||||
(let [n (get freqs x)]
|
||||
(put freqs x (if n (+ 1 n) 1)))))]
|
||||
freqs))
|
||||
|
||||
Reference in New Issue
Block a user