I have to admit...it wasn't easy...Racket is nice but weird...takes some time to get used to it...but when things work...they just work -;)
Here's the source code...
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)) " _| "])) |
Here's how it looks like when we run it...
Well...gotta keep learning...so...see you soon -;)
Greetings,
Blag.
Development Culture.
2 comentarios:
http://pastebin.com/4F4veyLP
Thanks anonymous...whoever you are -:) I still need to learn a lot of Racket to get to your level of coding -;)
Greetings,
Blag.
Development Culture.
Publicar un comentario