diff options
author | H.J <thechairman@thechairman.info> | 2024-10-09 11:36:55 -0400 |
---|---|---|
committer | H.J <thechairman@thechairman.info> | 2024-10-09 11:36:55 -0400 |
commit | 8777ff071f7bb37631baa7b6717ad29961e50911 (patch) | |
tree | 6d59c4ed58e454b960339c3d1151f0a879e8d7cb /leetcode/lc-2-add-two-numbers.rkt | |
parent | 6156a9ef7be4012063a042aafb4e9b0d7eadde8e (diff) | |
download | gleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.tar.gz gleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.zip |
sorting by language
Diffstat (limited to 'leetcode/lc-2-add-two-numbers.rkt')
-rw-r--r-- | leetcode/lc-2-add-two-numbers.rkt | 35 |
1 files changed, 0 insertions, 35 deletions
diff --git a/leetcode/lc-2-add-two-numbers.rkt b/leetcode/lc-2-add-two-numbers.rkt deleted file mode 100644 index 8062817..0000000 --- a/leetcode/lc-2-add-two-numbers.rkt +++ /dev/null @@ -1,35 +0,0 @@ -#lang racket -; Definition for singly-linked list: - - -; val : integer? -; next : (or/c list-node? #f) -(struct list-node - (val next) #:mutable #:transparent) - -; constructor -(define (make-list-node val [next-node #f]) - (list-node val next-node)) - - -(define/contract (add-two-numbers l1 l2) - (-> (or/c list-node? #f) (or/c list-node? #f) (or/c list-node? #f)) - (define (process-list node [acc '()]) - (if (list-node-next node) - (process-list (list-node-next node) (cons (list-node-val node) acc)) - (cons (list-node-val node) acc))) - (define sum-of-lists (+ (string->number (apply ~a (process-list l1))) - (string->number (apply ~a (process-list l2))))) - (define sum-list-digits - (reverse - (map (λ (x) (string->number (string x))) - (string->list (number->string sum-of-lists))))) - (define (build-list l) - (if (empty? l) - #f - (make-list-node (car l) (build-list (cdr l))))) - (build-list sum-list-digits)) - -(define list1 (make-list-node 2 (make-list-node 4 (make-list-node 3)))) -(define list2 (make-list-node 5 (make-list-node 6 (make-list-node 4)))) -(add-two-numbers list1 list2)
\ No newline at end of file |