aboutsummaryrefslogtreecommitdiff
path: root/leetcode/lc-415-add-strings.rkt
diff options
context:
space:
mode:
authorH.J <thechairman@thechairman.info>2024-10-09 11:36:55 -0400
committerH.J <thechairman@thechairman.info>2024-10-09 11:36:55 -0400
commit8777ff071f7bb37631baa7b6717ad29961e50911 (patch)
tree6d59c4ed58e454b960339c3d1151f0a879e8d7cb /leetcode/lc-415-add-strings.rkt
parent6156a9ef7be4012063a042aafb4e9b0d7eadde8e (diff)
downloadgleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.tar.gz
gleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.zip
sorting by language
Diffstat (limited to 'leetcode/lc-415-add-strings.rkt')
-rw-r--r--leetcode/lc-415-add-strings.rkt28
1 files changed, 0 insertions, 28 deletions
diff --git a/leetcode/lc-415-add-strings.rkt b/leetcode/lc-415-add-strings.rkt
deleted file mode 100644
index e140155..0000000
--- a/leetcode/lc-415-add-strings.rkt
+++ /dev/null
@@ -1,28 +0,0 @@
-#lang racket
-
-(define/contract (add-strings num1 num2)
- (-> string? string? string?)
- (define (char->integer c)
- ((compose string->number string) c))
- (define pad-length
- (add1 (apply max (map string-length (list num1 num2)))))
- (define (pad-with-zeroes n)
- (~a n
- #:align 'right
- #:min-width pad-length
- #:pad-string "0"))
- (define (string-reverse s)
- ((compose list->string reverse string->list) s))
- (define raw-sum
- (for/fold ([sum-string ""]
- [carry 0]
- #:result sum-string)
- ([n1 (string-reverse (pad-with-zeroes num1))]
- [n2 (string-reverse (pad-with-zeroes num2))])
- (let* ([digit-sum (+ carry (char->integer n1) (char->integer n2))]
- [sum-place (number->string (modulo digit-sum 10))]
- [sum-carry (quotient digit-sum 10)])
- (values (string-append sum-place sum-string)
- sum-carry))))
- (cond [(equal? raw-sum "00") "0"]
- [else (string-trim raw-sum "0" #:repeat? #t #:right? #f)])) \ No newline at end of file