diff options
author | HJ <thechairman@thechairman.info> | 2023-01-17 12:46:04 -0500 |
---|---|---|
committer | HJ <thechairman@thechairman.info> | 2023-01-17 12:46:04 -0500 |
commit | fafbeaf9e3c09ba7a5bea7e47d5736001f8a5aa1 (patch) | |
tree | d586a28650cbbfb20ece931a85bcce4c29e5e40b /leetcode/lc-645-set-mismatch.rkt | |
parent | bc5387512ba529072338648d6337ddab731b8b8c (diff) | |
download | gleam_aoc-fafbeaf9e3c09ba7a5bea7e47d5736001f8a5aa1.tar.gz gleam_aoc-fafbeaf9e3c09ba7a5bea7e47d5736001f8a5aa1.zip |
adding old leetcode solutions
Diffstat (limited to 'leetcode/lc-645-set-mismatch.rkt')
-rw-r--r-- | leetcode/lc-645-set-mismatch.rkt | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/leetcode/lc-645-set-mismatch.rkt b/leetcode/lc-645-set-mismatch.rkt new file mode 100644 index 0000000..a9d9a61 --- /dev/null +++ b/leetcode/lc-645-set-mismatch.rkt @@ -0,0 +1,24 @@ +#lang racket + +(define/contract (find-error-nums nums) + (-> (listof exact-integer?) (listof exact-integer?)) + (define nums-set (list->set nums)) + (define range-set (apply set (range 1 (+ 2 (set-count nums-set))))) + (define missing-num (first (set->list (set-subtract range-set nums-set)))) + (define necessary-num + (if (set-member? nums-set (- missing-num 1)) + (+ missing-num 1) + (- missing-num 1))) + (list missing-num necessary-num)) + +(find-error-nums '(1 2 2 4)) + +(define fact-stream + (letrec ([f (lambda (x y) + (cond + [(zero? (modulo (- y 1) 3)) (cons (* 3 x) (lambda() (f (* x + y) (+ y 1))))] + [else (cons x (lambda() (f (* x y) (+ y 1))))]) + [else (cons x (lambda() (f (* x y) (+ y 1))))] + (lambda () (f 1 2)) + )])))
\ No newline at end of file |