カテゴリ
全体プログラミング scheme verilog 未分類 以前の記事
2016年 04月2016年 03月 2016年 02月 2016年 01月 2015年 12月 2015年 11月 2015年 10月 2015年 09月 2015年 08月 2015年 07月 2015年 06月 2015年 03月 お気に入りブログ
PHPで競技プログラミングメモ帳
最新のトラックバック
ライフログ
検索
タグ
racket
その他のジャンル
ブログパーツ
最新の記事
外部リンク
ファン
記事ランキング
ブログジャンル
画像一覧
|
p. 89のMediamです。the number of guessesは、推測回数という意味らしいです。
#lang racket
(require 2htdp/universe 2htdp/image) (struct stat (small big count)) (define WIDTH 600) (define HEIGHT 300) (define TEXT-X 100) (define TEXT-UPPER-Y 50) (define TEXT-LOWER-Y 250) (define (app-text body #:size [size 20] #:color [color "blue"]) (text body size color)) (define HELP-TEXT (app-text "↑ for larger numbers, ↓ for smaller ones")) (define HELP-TEXT2 (app-text "Press = when your number is guessed; q to quit.")) (define MT-SC (place-image/align HELP-TEXT TEXT-X TEXT-UPPER-Y "left" "top" (place-image/align HELP-TEXT2 TEXT-X TEXT-LOWER-Y "left" "bottom" (empty-scene WIDTH HEIGHT)))) (define (smaller w) (stat (stat-small w) (max (stat-small w) (sub1 (guess w))) (add1 (stat-count w)))) (define (bigger w) (stat (min (stat-big w) (add1 (guess w))) (stat-big w) (add1 (stat-count w)))) (define (guess w) (quotient (+ (stat-small w) (stat-big w)) 2)) (define (start lower upper) (big-bang (stat lower upper 1) ; init {on-key (lambda (s key) (case key [("up") (bigger s)] [("down") (smaller s)] [("=") (stop-with s)] [("q") (stop-with s)] [else s]))} {to-draw (lambda (s) (overlay (app-text (number->string (guess s)) #:color "red" #:size 100) (overlay/offset (app-text (string-append "trial " (number->string (stat-count s)))) -200 0 MT-SC)))} {stop-when (lambda (s) (= (stat-small s) (stat-big s))) (lambda (s) (overlay (app-text "End" #:color "red" #:size 100) (overlay/offset (app-text (string-append "trial " (number->string (stat-count s)))) -200 0 MT-SC)))}))
by tempurature
| 2015-12-15 20:56
| scheme
| ||||||||||||||||||||||
ファン申請 |
||