Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 1.19 KB | None | 0 0
  1. ;; zadanie 1
  2. (define (st-app2 f . xs)
  3.   (define (helper lst s rs)
  4.     (if (null? lst)
  5.         (cons (reverse rs) s)
  6.         (let ([rx ((car lst) s)])
  7.           (helper (cdr lst) (res-state rx) (cons (res-val rx) rs)))))
  8.   (lambda (s)
  9.     (let ([rx (helper xs s '())])
  10.       (res (apply f (car rx))
  11.            (cdr rx)))))
  12.  
  13. (define (rename3 t)
  14.   (define (rename-st t)
  15.     (cond [(leaf? t)
  16.            (st-app2 (lambda (x y) x)
  17.                    get-st
  18.                    (modify-st inc))]
  19.           [(node? t)
  20.            (st-app2 node
  21.                    (rename-st (node-left  t))
  22.                    (rename-st (node-right t)))]))
  23.   (res-val ((rename-st t) 0)))
  24.  
  25. ;; zadanie 2
  26. ;; generator liczb pseudolosowych
  27. (define (rand max)
  28.   (lambda (i)
  29.     (let ([v (modulo (+ (* 1103515245 i) 12345) (expt 2 32))])
  30.       (res (modulo v max) v))))
  31.  
  32.  
  33. (define (rename-rand t)
  34.   (define (rename-st t)
  35.     (cond [(leaf? t)
  36.            (st-app (lambda (x y) x)
  37.                    get-st
  38.                    (rand 100))]
  39.           [(node? t)
  40.            (st-app node
  41.                    (rename-st (node-left t))
  42.                    (rename-st (node-right t)))]))
  43.   (res-val ((rename-st t) 0)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement