From 8777ff071f7bb37631baa7b6717ad29961e50911 Mon Sep 17 00:00:00 2001 From: "H.J" Date: Wed, 9 Oct 2024 11:36:55 -0400 Subject: sorting by language --- leetcode/lc-415-add-strings.rkt | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 leetcode/lc-415-add-strings.rkt (limited to 'leetcode/lc-415-add-strings.rkt') 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 -- cgit v1.2.3