make leet-code into a test case

This commit is contained in:
Fitz1987
2021-07-27 10:36:54 -05:00
parent c0df7230fd
commit a5fe10352f
2 changed files with 13 additions and 18 deletions

View File

@@ -1,20 +1,14 @@
(defun :Void main []
(defun :Array<Int> twosum [:Array<Int> numbers target]
// solution to: https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/
(function :Array<Int> twosum [:Array<Int> numbers target]
(let [di (new Map<Int,Int>)]
(doFor [i num] (zip (collect (range numbers.length)) numbers Throw)
(print "$i $num" )
(if (di.exists (- target num))
(return [( + 1 (dictGet di (- target num) )) ( + i 1)])
)
(dictSet di num i)
)
)
(return null)
)
(print (twosum [1 2 3 4 5 6 ] 5) )
)
(doFor [i num] (enumerate numbers)
// (print "$i $num")
(if (di.exists (- target num))
(return [(+ 1 (dictGet di (- target num))) (+ i 1)]))
(dictSet di num i)))
(return null))
(assert (= (.toString [2 3]) (.toString (twosum [1 2 3 4 5 6] 5))))
(assert (= (.toString [1 2]) (.toString (twosum [2 7 11 15] 9))))
(assert (= (.toString [1 3]) (.toString (twosum [2 3 4] 6))))
(assert (= (.toString [1 2]) (.toString (twosum [-1 0] -1))))