Created
July 31, 2012 05:42
-
-
Save alcidesfp/3214045 to your computer and use it in GitHub Desktop.
Kata Números Romanos en Scheme R5 (Kawa y Chicken)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; -*- coding: utf-8; mode: Scheme -*- | |
| ;; $Id: num-roman.scm,v 1.3 2012/07/31 05:39:03 alcides_fp Exp $ | |
| (cond-expand (chicken (require-extension srfi-1)) | |
| (kawa (require 'srfi-1))) | |
| ;;------------------------------------------------------------------------ | |
| (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) )) | |
| ;;------------------------------------------------------------------------ | |
| (define (dec->list numero) | |
| "Obtiene lista de cifras de un número base 10 en orden inverso" | |
| (do ((cantidad numero (quotient cantidad 10)) | |
| (retval '() (append retval (list (remainder cantidad 10))) )) | |
| ((= cantidad 0) retval) )) | |
| ;;------------------------------------------------------------------------ | |
| (define (num->roman arabigo) | |
| "Convierte número arábigo a romano" | |
| (let* ((digitos (dec->list arabigo)) | |
| (posiciones (iota (length digitos))) | |
| (retval (map numeral digitos posiciones))) | |
| (apply string-append (reverse retval)) )) | |
| ;;------------------------------------------------------------------------ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment