Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;; -*- coding: utf-8; mode: scheme -*-
- ;; $Id: num-roman.rkt,v 1.14 2012/02/16 04:02:35 alcides_fp Exp $
- #lang racket
- (provide numeral)
- (define (numeral digito posicion)
- (let ((matriz-numerales
- #(#("" "I" "II" "III" "IV" "V" "VI" "VII" "VIII" "IX")
- #("" "X" "XX" "XXX" "XL" "L" "LX" "LXX" "LXXX" "XC")
- #("" "C" "CC" "CCC" "CD" "D" "DC" "DCC" "DCCC" "CM")
- #("" "M" "MM" "MMM"))))
- (vector-ref (vector-ref matriz-numerales posicion) digito) ) )
- ;;------------------------------------------------------------------------
- (provide dec->list)
- (define (dec->list numero)
- "Obtiene lista de cifras de un número base 10 en orden inverso"
- (let loop ([cantidad numero][retval '()])
- (if (= cantidad 0) retval
- (loop (quotient cantidad 10)
- (append retval (list (remainder cantidad 10))) ) ) ) )
- ;;------------------------------------------------------------------------
- (provide num-roman)
- (define (num-roman arabigo)
- (let ((cifras (dec->list arabigo)))
- (for/fold ((retval ""))
- (((digito posicion)(in-indexed cifras)))
- (string-append (numeral digito posicion) retval) ) ) )
- ;;------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement