Code Review
Compare your solutions
#| Для этого упражнения нет проверок.
Любое решение будет считаться успешным ответом. |#
(define (A x y)
(cond ((= y 0) 0)
((= x 0) (* 2 y))
((= y 1) 2)
(else (A (- x 1)
(A x (- y 1))))))
; (A 1 10)
; (A 0 (A 1 9))
; (A 0 (A 0 (A 1 8)))
; (A 0 (A 0 (A 0 (A 1 7))))
; ...
; (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 1 1))))))))))
; (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 2)))))))))
; (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 4))))))))
; (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 8)))))))
; ...
; (A 0 512)
; 1024
; (A 2 4)
; (A 1 (A 2 3))
; (A 1 (A 1 (A 2 2)))
; (A 1 (A 1 (A 1 (A 2 1))))
; (A 1 (A 1 (A 1 2)))
; (A 1 (A 1 (A 0 (A 1 1))))
; (A 1 (A 1 (A 0 2)))
; (A 1 (A 1 4))
; (A 1 (A 0 (A 1 3)))
; (A 1 (A 0 (A 0 (A 1 2))))
; (A 1 (A 0 (A 0 (A 0 (A 1 1)))))
; (A 1 (A 0 (A 0 (A 0 2))))
; (A 1 (A 0 (A 0 4)))
; (A 1 (A 0 8))
; (A 1 16)
; ...
; 65536
; (A 3 3)
; (A 2 (A 3 2))
; (A 2 (A 2 (A 3 1)))
; (A 2 (A 2 2))
; ...
; (A 2 (A 0 2))
; (A 2 4)
; ...
; 65536
(define (f n) (A 0 n)) ; 2 * n
(define (g n) (A 1 n)) ; 2 ^ n
(define (h n) (A 2 n)) ; 2 ^ (n ^ 2)
; Tests
(define (assert condition message)
(if (not condition)
(error message)))
(define (** n m)
(define (iter result counter)
(if (= counter 1)
result
(iter (* result n) (- counter 1))))
(if (= m 0)
1
(iter n m)))
(assert (= (A 1 10) 1024) "1 test failed")
(assert (= (A 2 4) 65536) "2 test failed")
(assert (= (A 3 3) 65536) "3 test failed")
(assert (= (f 4) (* 2 4)) "4 test failed")
(assert (= (g 4) (** 2 4)) "5 test failed")
(assert (= (h 4) (** 2 (** 4 2))) "6 test failed")
(display "Test passed")
#| Для этого упражнения нет проверок.
Любое решение будет считаться успешным ответом. |#
(define (A x y)
(cond ((= y 0) 0)
((= x 0) (* 2 y))
((= y 1) 2)
(else (A (- x 1)
(A x (- y 1))))))
; (A 1 10)
; (A 0 (A 1 9))
; (A 0 (A 0 (A 1 8)))
; (A 0 (A 0 (A 0 (A 1 7))))
; ...
; (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 1 1))))))))))
; (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 2)))))))))
; (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 4))))))))
; (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 8)))))))
; ...
; (A 0 512)
; 1024
; (A 2 4)
; (A 1 (A 2 3))
; (A 1 (A 1 (A 2 2)))
; (A 1 (A 1 (A 1 (A 2 1))))
; (A 1 (A 1 (A 1 2)))
; (A 1 (A 1 (A 0 (A 1 1))))
; (A 1 (A 1 (A 0 2)))
; (A 1 (A 1 4))
; (A 1 (A 0 (A 1 3)))
; (A 1 (A 0 (A 0 (A 1 2))))
; (A 1 (A 0 (A 0 (A 0 (A 1 1)))))
; (A 1 (A 0 (A 0 (A 0 2))))
; (A 1 (A 0 (A 0 4)))
; (A 1 (A 0 8))
; (A 1 16)
; ...
; 65536
; (A 3 3)
; (A 2 (A 3 2))
; (A 2 (A 2 (A 3 1)))
; (A 2 (A 2 2))
; ...
; (A 2 (A 0 2))
; (A 2 4)
; ...
; 65536
(define (f n) (A 0 n)) ; 2 * n
(define (g n) (A 1 n)) ; 2 ^ n
(define (h n) (A 2 n)) ; 2 ↑↑ n
; Tests
(define (assert condition message)
(if (not condition)
(error message)))
(define (** n m)
(define (iter result counter)
(if (= counter 1)
result
(iter (* result n) (- counter 1))))
(if (= m 0)
1
(iter n m)))
(define (tetration n m)
(define (iter result counter)
(if (= counter 1)
result
(iter (** n result) (- counter 1))))
(iter n m))
(assert (= (A 1 10) 1024) "1 test failed")
(assert (= (A 2 4) 65536) "2 test failed")
(assert (= (A 3 3) 65536) "3 test failed")
(assert (= (f 4) (* 2 4)) "4 test failed")
(assert (= (g 4) (** 2 4)) "5 test failed")
(assert (= (h 4) (tetration 2 4)) "6 test failed")
(display "Test passed")
#| Для этого упражнения нет проверок.
Любое решение будет считаться успешным ответом. |#
(define (A x y)
(cond ((= y 0) 0)
((= x 0) (* 2 y))
((= y 1) 2)
(else (A (- x 1)
(A x (- y 1))))))
; (A 1 10)
; (A 0 (A 1 9))
; (A 0 (A 0 (A 1 8)))
; (A 0 (A 0 (A 0 (A 1 7))))
; ...
; (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 1 1))))))))))
; (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 2)))))))))
; (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 4))))))))
; (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 8)))))))
; ...
; (A 0 512)
; 1024
; (A 2 4)
; (A 1 (A 2 3))
; (A 1 (A 1 (A 2 2)))
; (A 1 (A 1 (A 1 (A 2 1))))
; (A 1 (A 1 (A 1 2)))
; (A 1 (A 1 (A 0 (A 1 1))))
; (A 1 (A 1 (A 0 2)))
; (A 1 (A 1 4))
; (A 1 (A 0 (A 1 3)))
; (A 1 (A 0 (A 0 (A 1 2))))
; (A 1 (A 0 (A 0 (A 0 (A 1 1)))))
; (A 1 (A 0 (A 0 (A 0 2))))
; (A 1 (A 0 (A 0 4)))
; (A 1 (A 0 8))
; (A 1 16)
; ...
; 65536
; (A 3 3)
; (A 2 (A 3 2))
; (A 2 (A 2 (A 3 1)))
; (A 2 (A 2 2))
; ...
; (A 2 (A 0 2))
; (A 2 4)
; ...
; 65536
(define (f n) (A 0 n)) ; 2 * n
(define (g n) (A 1 n)) ; 2 ^ n
(define (h n) (A 2 n)) ; 2 ↑↑ n
; Tests
(define (assert condition message)
(if (not condition)
(error message)))
(define (** n m)
(define (iter result counter)
(if (= counter 1)
result
(iter (* result n) (- counter 1))))
(if (= m 0)
1
(iter n m)))
(define (tetration n m)
(define (iter result counter)
(if (= counter 1)
result
(iter (** n result) (- counter 1))))
(iter n m))
(assert (= (A 1 10) 1024) "1 test failed")
(assert (= (A 2 4) 65536) "2 test failed")
(assert (= (A 3 3) 65536) "3 test failed")
(assert (= (f 4) (* 2 4)) "4 test failed")
(assert (= (g 4) (** 2 4)) "5 test failed")
(assert (= (h 4) (tetration 2 4)) "6 test failed")
(display "Test passed")
#| Для этого упражнения нет проверок.
Любое решение будет считаться успешным ответом. |#
(define (A x y)
(cond ((= y 0) 0)
((= x 0) (* 2 y))
((= y 1) 2)
(else (A (- x 1)
(A x (- y 1))))))
; (A 1 10)
; (A 0 (A 1 9))
; (A 0 (A 0 (A 1 8)))
; (A 0 (A 0 (A 0 (A 1 7))))
; ...
; (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 1 1))))))))))
; (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 2)))))))))
; (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 4))))))))
; (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 8)))))))
; ...
; (A 0 512)
; 1024
; (A 2 4)
; (A 1 (A 2 3))
; (A 1 (A 1 (A 2 2)))
; (A 1 (A 1 (A 1 (A 2 1))))
; (A 1 (A 1 (A 1 2)))
; (A 1 (A 1 (A 0 (A 1 1))))
; (A 1 (A 1 (A 0 2)))
; (A 1 (A 1 4))
; (A 1 (A 0 (A 1 3)))
; (A 1 (A 0 (A 0 (A 1 2))))
; (A 1 (A 0 (A 0 (A 0 (A 1 1)))))
; (A 1 (A 0 (A 0 (A 0 2))))
; (A 1 (A 0 (A 0 4)))
; (A 1 (A 0 8))
; (A 1 16)
; ...
; 65536
; (A 3 3)
; (A 2 (A 3 2))
; (A 2 (A 2 (A 3 1)))
; (A 2 (A 2 2))
; ...
; (A 2 (A 0 2))
; (A 2 4)
; ...
; 65536
(define (f n) (A 0 n)) ; 2 * n
(define (g n) (A 1 n)) ; 2 ^ n
(define (h n) (A 2 n)) ; 2 ^ (n ^ 2)
; Tests
(define (assert condition message)
(if (not condition)
(error message)))
(define (** n m)
(define (iter result counter)
(if (= counter 1)
result
(iter (* result n) (- counter 1))))
(if (= m 0)
1
(iter n m)))
(assert (= (A 1 10) 1024) "1 test failed")
(assert (= (A 2 4) 65536) "2 test failed")
(assert (= (A 3 3) 65536) "3 test failed")
(assert (= (f 4) (* 2 4)) "4 test failed")
(assert (= (g 4) (** 2 4)) "5 test failed")
(assert (= (h 4) (** 2 (** 4 2))) "6 test failed")
(display "Test passed")
#| Для этого упражнения нет проверок.
Любое решение будет считаться успешным ответом. |#
(define (A x y)
(cond ((= y 0) 0)
((= x 0) (* 2 y))
((= y 1) 2)
(else (A (- x 1)
(A x (- y 1))))))
; (A 1 10)
; (A 0 (A 1 9))
; (A 0 (A 0 (A 1 8)))
; (A 0 (A 0 (A 0 (A 1 7))))
; ...
; (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 1 1))))))))))
; (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 2)))))))))
; (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 4))))))))
; (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 8)))))))
; ...
; (A 0 512)
; 1024
; (A 2 4)
; (A 1 (A 2 3))
; (A 1 (A 1 (A 2 2)))
; (A 1 (A 1 (A 1 (A 2 1))))
; (A 1 (A 1 (A 1 2)))
; (A 1 (A 1 (A 0 (A 1 1))))
; (A 1 (A 1 (A 0 2)))
; (A 1 (A 1 4))
; (A 1 (A 0 (A 1 3)))
; (A 1 (A 0 (A 0 (A 1 2))))
; (A 1 (A 0 (A 0 (A 0 (A 1 1)))))
; (A 1 (A 0 (A 0 (A 0 2))))
; (A 1 (A 0 (A 0 4)))
; (A 1 (A 0 8))
; (A 1 16)
; ...
; 65536
; (A 3 3)
; (A 2 (A 3 2))
; (A 2 (A 2 (A 3 1)))
; (A 2 (A 2 2))
; ...
; (A 2 (A 0 2))
; (A 2 4)
; ...
; 65536
(define (f n) (A 0 n)) ; 2 * n
(define (g n) (A 1 n)) ; 2 ^ n
(define (h n) (A 2 n)) ; 2 ↑↑ n
; Tests
(define (assert condition message)
(if (not condition)
(error message)))
(define (** n m)
(define (iter result counter)
(if (= counter 1)
result
(iter (* result n) (- counter 1))))
(if (= m 0)
1
(iter n m)))
(define (tetration n m)
(define (iter result counter)
(if (= counter 1)
result
(iter (** n result) (- counter 1))))
(iter n m))
(assert (= (A 1 10) 1024) "1 test failed")
(assert (= (A 2 4) 65536) "2 test failed")
(assert (= (A 3 3) 65536) "3 test failed")
(assert (= (f 4) (* 2 4)) "4 test failed")
(assert (= (g 4) (** 2 4)) "5 test failed")
(assert (= (h 4) (tetration 2 4)) "6 test failed")
(display "Test passed")
#| Для этого упражнения нет проверок.
Любое решение будет считаться успешным ответом. |#
(define (A x y)
(cond ((= y 0) 0)
((= x 0) (* 2 y))
((= y 1) 2)
(else (A (- x 1)
(A x (- y 1))))))
; (A 1 10)
; (A 0 (A 1 9))
; (A 0 (A 0 (A 1 8)))
; (A 0 (A 0 (A 0 (A 1 7))))
; ...
; (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 1 1))))))))))
; (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 2)))))))))
; (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 4))))))))
; (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 8)))))))
; ...
; (A 0 512)
; 1024
; (A 2 4)
; (A 1 (A 2 3))
; (A 1 (A 1 (A 2 2)))
; (A 1 (A 1 (A 1 (A 2 1))))
; (A 1 (A 1 (A 1 2)))
; (A 1 (A 1 (A 0 (A 1 1))))
; (A 1 (A 1 (A 0 2)))
; (A 1 (A 1 4))
; (A 1 (A 0 (A 1 3)))
; (A 1 (A 0 (A 0 (A 1 2))))
; (A 1 (A 0 (A 0 (A 0 (A 1 1)))))
; (A 1 (A 0 (A 0 (A 0 2))))
; (A 1 (A 0 (A 0 4)))
; (A 1 (A 0 8))
; (A 1 16)
; ...
; 65536
; (A 3 3)
; (A 2 (A 3 2))
; (A 2 (A 2 (A 3 1)))
; (A 2 (A 2 2))
; ...
; (A 2 (A 0 2))
; (A 2 4)
; ...
; 65536
(define (f n) (A 0 n)) ; 2 * n
(define (g n) (A 1 n)) ; 2 ^ n
(define (h n) (A 2 n)) ; 2 ↑↑ n
; Tests
(define (assert condition message)
(if (not condition)
(error message)))
(define (** n m)
(define (iter result counter)
(if (= counter 1)
result
(iter (* result n) (- counter 1))))
(if (= m 0)
1
(iter n m)))
(define (tetration n m)
(define (iter result counter)
(if (= counter 1)
result
(iter (** n result) (- counter 1))))
(iter n m))
(assert (= (A 1 10) 1024) "1 test failed")
(assert (= (A 2 4) 65536) "2 test failed")
(assert (= (A 3 3) 65536) "3 test failed")
(assert (= (f 4) (* 2 4)) "4 test failed")
(assert (= (g 4) (** 2 4)) "5 test failed")
(assert (= (h 4) (tetration 2 4)) "6 test failed")
(display "Test passed")