Advertisement
Guest User

Untitled

a guest
Oct 15th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.15 KB | None | 0 0
  1. ;; =============== Q3 a) ===============
  2. (check-expect (absolutely-odd (cons -10 (cons 22 (cons 43 empty)))) 43)
  3. (check-expect (absolutely-odd (cons -13 (cons 3 (cons 7 empty)))) 23)
  4. (check-expect (absolutely-odd (cons 11 (cons -6 (cons 2 empty)))) 11)
  5.  
  6. (check-expect (absolutely-odd (cons -7 (cons 2 (cons 5 empty)))) 12)
  7. (check-expect (absolutely-odd (cons 0 (cons 176489 (cons -997789 empty))))
  8. 1174278)
  9. (check-expect (absolutely-odd (cons 4876 (cons -238762 (cons 11 empty))))
  10. 11)
  11. (check-expect (absolutely-odd (cons -123421 (cons 332233 empty))) 455654)
  12. (check-expect (absolutely-odd (cons 3 (cons -7 (cons 1 (cons 8 empty))))) 11)
  13. (check-expect (absolutely-odd (cons 12 (cons 22 (cons 8 empty)))) 0)
  14. (check-expect (absolutely-odd empty) 0)
  15. (check-expect (absolutely-odd
  16. (cons -223
  17. (cons 12345
  18. (cons 6 (cons -123421 (cons 123 empty))))))
  19. 136112)
  20. (check-expect (absolutely-odd (cons 0 (cons 0 (cons 0 empty)))) 0)
  21.  
  22. ;; =============== Q3 b) ===============
  23.  
  24. (check-expect
  25. (spiraling? (cons 100 (cons -1000 (cons -10000 empty))))
  26. false)
  27. (check-expect
  28. (spiraling? (cons 1 (cons -324 (cons 30000 empty))))
  29. true)
  30. (check-expect
  31. (spiraling? (cons 23 (cons -142 (cons 0 empty))))
  32. false)
  33. (check-expect
  34. (spiraling? (cons 54 (cons 100 (cons 240 empty))))
  35. false)
  36. (check-expect
  37. (spiraling? (cons -1 (cons 24 (cons -10000 empty))))
  38. true)
  39. (check-expect
  40. (spiraling? (cons 0 (cons -10 (cons 100 empty))))
  41. false)
  42. (check-expect
  43. (spiraling? (cons 100 (cons -10 (cons 1 empty))))
  44. false)
  45. (check-expect
  46. (spiraling? (cons 3 (cons 2 (cons -1 empty))))
  47. false)
  48. (check-expect
  49. (spiraling? (cons 123454 (cons -1012345 (cons 12456124 empty))))
  50. true)
  51. (check-expect
  52. (spiraling? (cons 1 empty))
  53. true)
  54. (check-expect
  55. (spiraling? empty)
  56. true)
  57.  
  58. ;; =============== Q3 c) ===============
  59.  
  60. (check-within
  61. (geometric-mean (cons 14(cons 0.2 (cons 45 empty))))
  62. 5.0133 0.0001)
  63. (check-within
  64. (geometric-mean (cons 123 (cons 425 (cons 0.41 empty))))
  65. 27.7774 0.0001)
  66. (check-within
  67. (geometric-mean (cons 55 (cons 212 (cons 4 empty))))
  68. 35.9959 0.0001)
  69. (check-within
  70. (geometric-mean (cons 132 (cons 23 (cons 6.23 empty))))
  71. 26.6438 0.0001)
  72. (check-within
  73. (geometric-mean (cons 2.5 (cons 14.2 (cons 46.2 empty))))
  74. 11.7929 0.0001)
  75. (check-within
  76. (geometric-mean (cons 123 (cons 2.5 (cons 0.01 empty))))
  77. 1.4541 0.0001)
  78. (check-within
  79. (geometric-mean (cons 5.4 (cons 21 (cons 55.2 empty))))
  80. 18.4296 0.0001)
  81. (check-within
  82. (geometric-mean (cons 98 (cons 25.1 (cons 1.1 empty))))
  83. 13.9346 0.0001)
  84. (check-within
  85. (geometric-mean (cons 1 empty))
  86. 1 0.0001)
  87. (check-within
  88. (geometric-mean (cons 9 (cons 0.5 empty)))
  89. 2.1213 0.0001)
  90.  
  91. ;; ================ Q4 a) ================
  92. (check-expect
  93. (rainbow? (cons 'orange (cons 'yellow (cons 'violet empty))))
  94. true)
  95. (check-expect
  96. (rainbow? (cons 'cars (cons 'planes (cons 'train empty))))
  97. false)
  98. (check-expect
  99. (rainbow? (cons 'blue (cons 'indigo (cons 'violet empty))))
  100. true)
  101. (check-expect
  102. (rainbow? (cons 'red empty))
  103. true)
  104. (check-expect
  105. (rainbow? (cons 'orange (cons 'green empty)))
  106. true)
  107. (check-expect
  108. (rainbow? (cons 'red (cons 'red (cons 'red empty))))
  109. false)
  110. (check-expect
  111. (rainbow? empty)
  112. true)
  113.  
  114. ;; ================ Q4 b) ================
  115. (check-expect
  116. (unicorn 'green (cons 'red (cons 'green (cons 'blue empty))))
  117. (cons 'red (cons 'blue empty)))
  118. (check-expect
  119. (unicorn 'orange (cons 'red (cons 'green (cons 'violet empty))))
  120. (cons 'red (cons 'green (cons 'violet empty))))
  121. (check-expect
  122. (unicorn 'red (cons 'red (cons 'yellow (cons 'blue empty))))
  123. (cons 'yellow (cons 'blue empty)))
  124. (check-expect
  125. (unicorn 'green (cons 'green empty)) empty)
  126. (check-expect
  127. (unicorn 'blue empty) empty)
  128. (check-expect
  129. (unicorn 'yellow (cons 'red
  130. (cons 'orange
  131. (cons 'yellow (cons 'green (cons 'blue empty))))))
  132. (cons 'red (cons 'orange (cons 'green (cons 'blue empty)))))
  133.  
  134. ;; ================ Q4 c) ================
  135. (check-expect
  136. (leprechaun 'red (cons 'yellow (cons 'blue empty)))
  137. (cons 'red (cons 'yellow (cons 'blue empty))))
  138. (check-expect
  139. (leprechaun 'green (cons 'red (cons 'yellow (cons 'blue empty))))
  140. (cons 'red (cons 'yellow (cons 'green (cons 'blue empty)))))
  141. (check-expect
  142. (leprechaun 'orange (cons 'orange (cons 'yellow (cons 'violet empty))))
  143. (cons 'orange (cons 'yellow (cons 'violet empty))))
  144. (check-expect
  145. (leprechaun 'yellow (cons 'red (cons 'green (cons 'blue empty))))
  146. (cons 'red (cons 'yellow (cons 'green (cons 'blue empty)))))
  147. (check-expect
  148. (leprechaun 'violet (cons 'yellow (cons 'blue empty)))
  149. (cons 'yellow (cons 'blue (cons 'violet empty))))
  150. (check-expect
  151. (leprechaun 'violet (cons 'blue empty))
  152. (cons 'blue (cons 'violet empty)))
  153. (check-expect
  154. (leprechaun 'orange empty)
  155. (cons 'orange empty))
  156. (check-expect
  157. (leprechaun 'indigo (cons 'red
  158. (cons 'yellow (cons 'blue (cons 'violet empty)))))
  159. (cons 'red (cons 'yellow (cons 'blue (cons 'indigo (cons 'violet empty))))))
  160. (check-expect
  161. (leprechaun 'violet (cons 'red empty))
  162. (cons 'red (cons 'violet empty)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement