s c h e m e w i k i . o r g

/ Scm.recipe-decToroman

This Web


WebHome 
WebChanges 
WebTopicList 
WebStatistics 

All Webs


Chicken
Cookbook
Erlang
Know
Main
Plugins
Sandbox
Scm
TWiki  

Schematics


Schematics Home
TWiki Shorthand

Offsite Links


Schemers.org
Lambda the Ultimate
twiki.org
; decimal->roman : integer -> string ; format the integer num using roman numerals (define (decimal->roman num) (let ((decimal-numbers (list 1000 900 500 400 100 90 50 40 10 9 5 4 1)) (roman-numbers (list "M" "CM" "D" "CD" "C" "XC" "L" "XL" "X" "IX" "V" "IV" "I"))) (decimal->roman-aux num "" decimal-numbers roman-numbers)))

; decimal->roman-aux : integer string (list number) (list string) -> string ; append the numbers num formatted as roman numerals to the string s, ; using the roman numerals in roman-numbers with corresponding ; decimal values in decimal-values (define (decimal->roman-aux num s decimal-numbers roman-numbers) (if (null? decimal-numbers) s (if (>= num (car decimal-numbers)) (decimal->roman-aux (- num (car decimal-numbers)) (string-append s (car roman-numbers)) decimal-numbers roman-numbers) (decimal->roman-aux num s (cdr decimal-numbers) (cdr roman-numbers)))))

 
 
© 2004 by the contributing authors. / You are Main.guest