Debo admitirlo...no fué nada fácil...Racket es impresionante pero extraño...toma un poco de tiempo acostumbrarse a usarlo...pero cuando las cosas funcionan...funcionan bien -;)
Aquí está el código fuente...
LED.rkt |
---|
#lang racket (define (showLED num) (display(get_led(toList num num 0 1) 1 num))) (define (toList num num_o start end) (cond [(number? num) (toList(number->string num) (number->string num_o) start end)] [(and (string? num) (> (string-length num_o) 1)) (append (cons(substring num start end) '()) (toList num (substring num_o 1 (string-length num_o)) (add1 start)(add1 end)))] [(and (string? num) (= (string-length num_o) 1)) (append (cons(substring num_o 0 1) '()))])) (define (get_led x n num) (cond [(> (length x) 0) (append (cons(make_led_digit (string->number(first x)) n) '()) (get_led(rest x) n num))] [(and (= (length x) 0) (< n 3)) (append '("\n") (get_led(toList num num 0 1) (add1 n) num) )] [(and (= (length x) 0) (>= n 3)) append '()])) (define (make_led_digit a b) (cond [(and (= a 0)(= b 1)) " _ "] [(and (= a 0)(= b 2)) "| | "] [(and (= a 0)(= b 3)) "|_| "] [(and (= a 1)(= b 1)) " "] [(and (= a 1)(= b 2)) "| "] [(and (= a 1)(= b 3)) "| "] [(and (= a 2)(= b 1)) " _ "] [(and (= a 2)(= b 2)) " _| "] [(and (= a 2)(= b 3)) "|_ "] [(and (= a 3)(= b 1)) "_ "] [(and (= a 3)(= b 2)) "_| "] [(and (= a 3)(= b 3)) "_| "] [(and (= a 4)(= b 1)) " "] [(and (= a 4)(= b 2)) "|_| "] [(and (= a 4)(= b 3)) " | "] [(and (= a 5)(= b 1)) " _ "] [(and (= a 5)(= b 2)) "|_ "] [(and (= a 5)(= b 3)) " _| "] [(and (= a 6)(= b 1)) " _ "] [(and (= a 6)(= b 2)) "|_ "] [(and (= a 6)(= b 3)) "|_| "] [(and (= a 7)(= b 1)) "_ "] [(and (= a 7)(= b 2)) " | "] [(and (= a 7)(= b 3)) " | "] [(and (= a 8)(= b 1)) " _ "] [(and (= a 8)(= b 2)) "|_| "] [(and (= a 8)(= b 3)) "|_| "] [(and (= a 9)(= b 1)) " _ "] [(and (= a 9)(= b 2)) "|_| "] [(and (= a 9)(= b 3)) " _| "])) |
Así es como se ve cuando lo ejecutamos...
Bueno...debo seguir aprendiendo...así que...nos vemos pronto -;)
Saludos,
Blag.
Development Culture.
No comments:
Post a Comment