Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. Задание 1:
  2.  
  3. (define mdig (lambda (x)
  4. (if (< x 10)
  5. x
  6. (if (< (remainder x 10) (mdig (quotient x 10))) (remainder x 10) (mdig (quotient x 10))) ))
  7.  
  8. )
  9.  
  10. Задание 2:
  11.  
  12. (define (eqdig x)
  13. (define eqdig_raw (lambda (x)
  14. (if (< x 10)
  15. x
  16. (if (eq? (remainder x 10) (eqdig_raw (quotient x 10))) (remainder x 10) #f) )))
  17.  
  18. (if (eq? (eqdig_raw x) #f) #f #t)
  19. )
  20.  
  21. Задание 3:
  22.  
  23. (define (fact? max)
  24. (define fact (lambda (n x max)
  25. (if (= max x)
  26. (- n 1)
  27. (if (> x max) #f (fact (+ n 1) (* x n) max)))) )
  28. (fact 1 1 max)
  29. )
  30.  
  31.  
  32. Задание 4:
  33.  
  34. (define (findFib x)
  35. (define (find x a b c)
  36. (if (> (+ b c) x)
  37. (if (< (- x c) (- (+ b c) x)) c (+ b c)
  38. )
  39. (find x b c (+ c b)) )
  40. )
  41. (find x 1 1 2) )
  42.  
  43. Задание 5:
  44.  
  45. (define (perfect x)
  46. (define (temp x S d)
  47. (if (and (= S x) (= x d) )
  48. #t
  49. (if (= (remainder x d) 0)
  50. (temp x (+ S d) (+ d 1))
  51. (if (< d x)
  52. (temp x S (+ d 1))
  53. #f)
  54. )
  55. ))
  56. (temp x 0 1) )
  57.  
  58. (define (perfect x)
  59. (define (temp x del sum)
  60. (if (= x 1)
  61. #f
  62. (if (= x sum)
  63. #t
  64. (if (< (* del del) x)
  65. (if (= (remainder x del) 0)
  66. (temp x (+ del 1) (+ sum del (/ x del)))
  67. (temp x (+ del 1) sum)
  68. )
  69. #f
  70. )
  71. )
  72. )
  73. )
  74. (temp x 2 1)
  75. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement