November 24, 2022, 8:30pm
What am I supposed to do about this?
Calculates the diameter of a pizza from the amount of sauce applied (4/5)
(is (= 32.573500793528d0 (size-from-sauce 250)))
(is (= 20.601290774570113d0 (size-from-sauce 100)))
(is (= 37.424103185095554d0 (size-from-sauce 330)))
(is (= 46.52426491681278d0 (size-from-sauce 510)))
(is (= 53.72159374714264d0 (size-from-sauce 680)))
which is not
I’m working in the web editor.
November 24, 2022, 9:32pm
Not sure right now, I submitted my solution again to check if it’s still passing and it passed.
Can you please share your code?
This is off topic but since you wrote in another thread that you had a difficult time getting into lisp… I would have a hard time getting into Lisp as well if I would try it without good editor support and a REPL. And I already had a hard time getting into Lisp when I started out.
Feel free to hit me up on slack if you need help with setting up an environment.
November 24, 2022, 9:38pm
Since you’re an experienced Exercism user I assume you know but maybe someone else comes across this post and doesn’t know: You can download the exercise and submit a failing solution through the CLI. That way you can ask for mentorship.
November 24, 2022, 10:29pm
Here’s my code. Perhaps the tests don’t need to compare to the 15th decimal place though…
(:export :dough-calculator :pizzas-per-cube
(defvar base-dough 200) ; amount of dough in grams for the "base" (i.e. non-crust) of the pizza
(defvar dough-per-length-of-crust 45) ; amount of dough in grams per length of crust
(defvar len 20) ; size in cm of a "length of crust"
(defun perimeter (diameter) (* pi diameter))
(defun lengths-of-crust (diameter)
(/ (perimeter diameter) len)
(defun crust-dough (diameter)
(* (lengths-of-crust diameter) dough-per-length-of-crust)
(defun dough-calculator (pizzas diameter)
(round (* pizzas (+ (crust-dough diameter) base-dough)))
(defvar sauce-unit 3/10) ; amount of sauce in mL per cm^2 of pizza
;; given an area of a circle, return the diameter
(defun diameter-from-area (area)
; a = pi r^2 => r = sqrt(a / pi) => d = 2 * sqrt(a/pi)
(* 2 (sqrt (/ area pi)))
(defun size-from-sauce (sauce)
(diameter-from-area (/ sauce sauce-unit))
;; n = (2 * (l^3))/(3 * pi * (d^2))
(defun pizzas-per-cube (cube-size diameter)
(print (list 'numerator (* 2 cube-size cube-size cube-size)))
(print (list 'denominator (* 3 * pi * diameter * diameter)))
(/ (* 2 cube-size cube-size cube-size)
(* 3 pi diameter diameter)
(defun fair-share-p (pizzas friends))
November 24, 2022, 11:03pm
Yeah, you’re running into a type conversion issue. My theory was that it’s a problem with defining the
sauce-unit as a fraction but converting it to a float didn’t help.
+1 for not matching floating point numbers to the 15th decimal.
I learned that you should always only match up to a certain precision when testing floating-point numbers.
If you transfer the formula like it’s written in the problem description, without transforming it, your test should pass:
square-root of ((40 * sauce-applied) / (3 * pi))
November 24, 2022, 11:30pm
Since community contributions
are currently paused I’ll leave my suggested fix here in the forum:
(defvar epsilon 0.00000001)
(defun compare-floats (float1 float2)
(< (abs (- float1 float2)) epsilon))
(test splash-of-sauces "Calculates the diameter of a pizza from the amount of sauce applied"
(is (compare-floats 32.573500793528d0 (size-from-sauce 250)
(is (compare-floats 20.601290774570113d0 (size-from-sauce 100)))
(is (compare-floats 37.424103185095554d0 (size-from-sauce 330)))
(is (compare-floats 46.52426491681278d0 (size-from-sauce 510)))
(is (compare-floats 53.72159374714264d0 (size-from-sauce 680))))
Looks like a problem with floating point equality. Thought I had those solved in the exercises but it seems that I have not.
Sorry about this.
Looking at another exercise that leans heavily on floats:
space-age I see it was solved with:
(defun rounds-to (expected actual)
(flet ((to-2-places (n) (/ (round (* 100 n)) 100.0)))
(is (= (to-2-places expected) (to-2-places actual)))))
So that is how I’d likely fix it for pizza-pier (and should have been fixed with that in the first place :( )
PR opened and ready for review:
02:34AM - 26 Nov 22 UTC
The ROUNDS-TO function was used in SPACE-AGE which has the same
- [ ] If docs where changed run `./bin/configlet generate` to ensure all documents are properly generated.
- [ ] CI is green
@glennj / @fap - would love either/both of your feedback on my proposed solution.
@glennj the fix to the exercise was merged so hopefully you should be seeing it on the web site. Has it fixed the problem? Can we mark this topic ‘solved’?