This file contains 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
;; nabeatu | |
;; 3 - アホ | |
;; 5 - 犬 | |
;; 15 - アホ 犬 | |
(use srfi-1) | |
(define (number->list% n) | |
(map (lambda (x) | |
(string->number (x->string x))) | |
(string->list (number->string n)))) | |
(number->list% 1234567890) | |
; -> (1 2 3 4 5 6 7 8 9 0) | |
(define (number->list n) | |
(map (compose string->number (cut x->string <>)) | |
(string->list (number->string n)))) | |
(number->list 1234567890) | |
; -> (1 2 3 4 5 6 7 8 9 0) | |
(define (contain? n m) | |
(any (cut = m <>)(number->list n))) | |
(contain? 12345 3) | |
; -> #t | |
(contain? 12345 10) | |
; -> #f | |
(define (make-nabe min max) | |
(map (lambda (n) | |
(let ((p (compose zero? (cut modulo n <>)))) | |
(cond ((p 15) "アホ犬") | |
((p 5) "犬") | |
((or (p 3) | |
(contain? n 3)) "アホ") | |
(else n)))) | |
(iota max min))) | |
(define (fizzbuzz) | |
(make-nabe 1 100)) | |
(display (fizzbuzz)) | |
; -> (1 2 アホ 4 犬 アホ 7 8 アホ 犬 11 アホ アホ 14 アホ犬 16 17 アホ 19 犬 アホ 22 アホ アホ 犬 26 アホ 28 29 アホ犬 アホ アホ アホ アホ 犬 アホ アホ アホ アホ 犬 41 アホ アホ 44 アホ犬 46 47 アホ 49 犬 アホ 52 アホ アホ 犬 56 アホ 58 59 アホ犬 61 62 アホ 64 犬 アホ 67 68 アホ 犬 71 アホ アホ 74 アホ犬 76 77 アホ 79 犬 アホ 82 アホ アホ 犬 86 アホ 88 89 アホ犬 91 92 アホ 94 犬 アホ 97 98 アホ 犬)#<undef> |
なんとなく正規表現は使いませんでした。
そういえば、恥ずかしながら「正規表現」を知ったのはプログラマになってから2年以上も後のことでした。その間、社内で正規表現を見かけなかった環境って一体・・・。
追記
会社のせいにしちゃあいけないですね。
0 件のコメント:
コメントを投稿