SourceSecond » 履歴 » バージョン 4
Yuumi Yoshida, 2015-08-03 22:24
| 1 | 1 | Yuumi Yoshida | |
|---|---|---|---|
| 2 | 4 | Yuumi Yoshida | # 第2回目のソースコード |
| 3 | 3 | Yuumi Yoshida | |
| 4 | |||
| 5 | 1 | Yuumi Yoshida | リスト1:ジャンケン(Javaの場合) |
| 6 | 4 | Yuumi Yoshida | |
| 7 | ~~~ |
||
| 8 | 1 | Yuumi Yoshida | // Java |
| 9 | import static java.lang.Math.*; |
||
| 10 | public class Jyanken { |
||
| 11 | |||
| 12 | public static String guu_choki_pa(double r) { |
||
| 13 | if (r < 0.33) { |
||
| 14 | return "Guu"; |
||
| 15 | } else if (r < 0.66) { |
||
| 16 | return "Choki"; |
||
| 17 | } else { |
||
| 18 | return "Pa"; |
||
| 19 | } |
||
| 20 | } |
||
| 21 | |||
| 22 | public static void jyanken() { |
||
| 23 | System.out.println(guu_choki_pa(random())); |
||
| 24 | } |
||
| 25 | |||
| 26 | public static void main(String args[]) { |
||
| 27 | for (int i = 0; i < 10; i++) { |
||
| 28 | jyanken(); |
||
| 29 | } |
||
| 30 | } |
||
| 31 | } |
||
| 32 | 4 | Yuumi Yoshida | ~~~ |
| 33 | 3 | Yuumi Yoshida | |
| 34 | 1 | Yuumi Yoshida | リスト2:ジャンケン(Gaucheの場合) |
| 35 | 4 | Yuumi Yoshida | |
| 36 | ~~~ |
||
| 37 | 1 | Yuumi Yoshida | (use srfi-27) |
| 38 | |||
| 39 | (define (guu-choki-pa r) |
||
| 40 | (cond ((< r 0.33) "Guu") |
||
| 41 | ((< r 0.66) "Choki") |
||
| 42 | (else "Pa"))) |
||
| 43 | |||
| 44 | (define (jyanken) |
||
| 45 | (print (guu-choki-pa (random-real)))) |
||
| 46 | |||
| 47 | (dotimes (i 10) (jyanken)) |
||
| 48 | 4 | Yuumi Yoshida | ~~~ |
| 49 | 3 | Yuumi Yoshida | |
| 50 | 1 | Yuumi Yoshida | リスト5:S式を与えると対応するHTMLを出力するプログラム |
| 51 | 4 | Yuumi Yoshida | |
| 52 | ~~~ |
||
| 53 | 1 | Yuumi Yoshida | (define (print-html e) |
| 54 | (cond ((list? e) |
||
| 55 | (print-open-tag (car e)) |
||
| 56 | (print-html-list (cdr e)) |
||
| 57 | (print-close-tag (car e))) |
||
| 58 | (else (display e)))) |
||
| 59 | |||
| 60 | (define (print-html-list s) |
||
| 61 | (cond ((null? s) #f) |
||
| 62 | (else |
||
| 63 | (print-html (car s)) |
||
| 64 | (print-html-list (cdr s))))) |
||
| 65 | |||
| 66 | (define (print-open-tag tag) |
||
| 67 | (display "<") |
||
| 68 | (display tag) |
||
| 69 | (display ">")) |
||
| 70 | |||
| 71 | (define (print-close-tag tag) |
||
| 72 | (display "</") |
||
| 73 | (display tag) |
||
| 74 | (display ">")) |
||
| 75 | |||
| 76 | (define gauche-page |
||
| 77 | '(html |
||
| 78 | (head (title "Gauche Web")) |
||
| 79 | (body (h1 "Gauche Web Page") |
||
| 80 | (table (tr (td 1)(td "lisp")) |
||
| 81 | (tr (td 2)(td "scheme")))))) |
||
| 82 | |||
| 83 | (print-html gauche-page) |
||
| 84 | 4 | Yuumi Yoshida | ~~~ |