Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. (ql:quickload :lisp-unit)
  2. (use-package :lisp-unit)
  3. (setf *print-failures* t)
  4.  
  5. (defun one-more-mult (n)
  6. "* Make sure you know how to use (mod x n) to figure out if x is
  7. divisible by n. Write a function that takes in an integer and returns
  8. true when the integer is one more than a multiple of 8."
  9. nil)
  10.  
  11. (define-test test-one-more-mult
  12. "Test one-more-mult"
  13. (assert-false (one-more-mult 8))
  14. (assert-false (one-more-mult 4))
  15. (assert-false (one-more-mult 5))
  16. (assert-false (one-more-mult 15))
  17. (assert-true (one-more-mult 9))
  18. (assert-true (one-more-mult 17)))
  19.  
  20. (defun all-6-by-17 (xs)
  21. "* Given a list of integers, return all of the elements that are
  22. either greater than 100 or leave a remainder of 6 when divided by 17."
  23. (list -1))
  24.  
  25. (define-test test-all-6-by-17
  26. "Test all-6-by-17"
  27. (assert-equal `(103 105 23 40 -28)
  28. (all-6-by-17 `(50 60 70 -30 103 80 105 22 23 24 34 40 51 -28))))
  29.  
  30.  
  31. (defun long-words (wordlist)
  32. "* Given a list of words, return the number of words in the list that
  33. are longer than 6 letters."
  34. 0)
  35.  
  36. (define-test test-longwords
  37. "Vocab check"
  38. (assert-equal 3
  39. (long-words (list "short" "transcendental" "transmogrify"
  40. "longer" "stuff" "cuddles" "finish"))))
  41.  
  42. (defun good-lists (ys)
  43. "Given a list of lists `ys`, if a sublist y of ys begins with the
  44. symbol `GOOD`, then put every element from the list y in the answer."
  45. '(GOOD LUCK))
  46.  
  47. (define-test test-good-lists
  48. "Example to help you decode the question."
  49. (assert-equal `(GOOD LUCK GOOD RIDDANCE)
  50. (good-lists `((BAD START) (GOOD LUCK) (EVIL EMPIRE)
  51. (GOOD RIDDANCE) (YEET)))))
  52.  
  53. (defun x010 (pts)
  54. "* (`x010`) Return a list of all of the x values that are in the interval [0,10]."
  55. (list 0))
  56.  
  57. (define-test test-x010
  58. (assert-equal '(0 3 1 9)
  59. (x010 `((0 5) (3 8) (-7 4) (1 13) (15 3) (9 20)))))
  60.  
  61. (defun y200 (pts)
  62. "* (`y200`) Return a list of all of the points whose y values are
  63. either greater than 200 or less than -200."
  64. (list (list 0 1)))
  65.  
  66. (define-test test-y200
  67. (assert-equal '((40 -300) (50 201) (5 -200) (50 500))
  68. (y200 '((40 -300) (50 201) (-205 90)
  69. (5 -200) (50 500) (400 95)))))
  70.  
  71. (defun ptf (pts)
  72. "* (`ptf`) Find the greatest value of $f(x,y) = x^2 + 3 y^2 - 2 x y$ using the
  73. points in the list."
  74. 0)
  75.  
  76. (define-test test-ptf
  77. "What is the greatest value of ptf?"
  78. (assert-equal 225000 (ptf '((40 20) (50 200) (-90 40)))))
  79.  
  80. (defun smd (pts)
  81. "* (`smd`) Find the smallest difference $\abs{x-y}$ in the list."
  82. 0)
  83.  
  84. (define-test test-smd
  85. "What is the smallest difference? |x-y|"
  86. (assert-equal 10 (ptf '((40 20) (50 200) (-90 -80) (800 30)))))
  87.  
  88.  
  89. (defun aop (pts)
  90. "* (`aop`) If every point is on the parabola $y=x^2$ then return true (otherwise false)."
  91. nil)
  92.  
  93. (define-test test-aop
  94. "Are points on parabola?"
  95. (assert-true (aop '((5 25) (6 36) (9 81))))
  96. (assert-false (aop '((5 25) (6 36) (7 50) (9 81)))))
  97.  
  98. (defun isfar (pts)
  99. "* (`isfar`) If any point has $\abs{y - x^2} > 10$, then return true."
  100. nil)
  101.  
  102. (define-test test-isfar
  103. "isFar(), technically"
  104. (assert-true (isfar '((5 25) (6 47) (9 81))))
  105. (assert-true (isfar '((5 25) (6 25) (9 81))))
  106. (assert-false (isfar '((5 24) (6 37) (9 79)))))
  107.  
  108. (defun not10x (pts)
  109. "* (`not10x`) If $y \not= 10^x$ for at least one (x,y) pair in the list, return true."
  110. nil)
  111.  
  112. (define-test test-not10x
  113. "Not 10x"
  114. (assert-false (not10x '((2 100) (3 1000))))
  115. (assert-true (not10x '((2 10000) (4 100000)))))
  116.  
  117. (defun xyzTrip (pts)
  118. "* (`xyzTrip`) Given a list of triples $(x,y,z)$, which we write `(list x y z)`,
  119. return a list containing `(list x y)` for every point where $z=x^2+y^2$."
  120. (list (list 0 1)))
  121.  
  122. (define-test test-xyzTrip
  123. "Triples?!"
  124. (assert-equal '((5 12) (20 21))
  125. (xyzTrip '((5 12 169) (8 15 17) (20 21 841)))))
  126.  
  127. (run-tests)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement