Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
17
Task/Roman-numerals-Decode/Racket/roman-numerals-decode.rkt
Normal file
17
Task/Roman-numerals-Decode/Racket/roman-numerals-decode.rkt
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#lang racket
|
||||
(define (decode/roman number)
|
||||
(define letter-values
|
||||
(map cons '(#\M #\D #\C #\L #\X #\V #\I) '(1000 500 100 50 10 5 1)))
|
||||
(define (get-value letter)
|
||||
(cdr (assq letter letter-values)))
|
||||
(define lst (map get-value (string->list number)))
|
||||
(+ (last lst)
|
||||
(for/fold ((sum 0))
|
||||
((i (in-list lst)) (i+1 (in-list (cdr lst))))
|
||||
(+ sum
|
||||
(if (> i+1 i)
|
||||
(- i)
|
||||
i)))))
|
||||
|
||||
(map decode/roman '("MCMXC" "MMVIII" "MDCLXVI"))
|
||||
;-> '(1990 2008 1666)
|
||||
Loading…
Add table
Add a link
Reference in a new issue