From cd29ee0a5354ffdbeb9a97fde63847439339b2eb Mon Sep 17 00:00:00 2001 From: Peachpit Date: Sun, 17 Nov 2024 22:48:51 -0800 Subject: [PATCH] Make trig app purely functional --- examples/trig.pf | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/examples/trig.pf b/examples/trig.pf index c260e862..9baa6428 100644 --- a/examples/trig.pf +++ b/examples/trig.pf @@ -1,3 +1,7 @@ +// We wish to calculate the top (dT), bottom (dB), and height (q) of a symmetric +// parallelogram such that n of them will exactly circumscribe a symmetric truncated +// cone having top radius rT, bottom radius rB, and height h. + import NULL::"math" @@ -5,31 +9,16 @@ NULL::"math" const PI = 3.141592 -// We wish to calculate the top (dT), bottom (dB), and height q of a symmetric -// parallelogram such that n of them will exactly circumscribe a symmetric truncated -// cone having top radius rT, bottom radius rB, and height h. +def -cmd - -main : - get answer from Input("What is the radius of the top of the cone? ") - rT = float(answer) - get answer from Input("What is the radius of the bottom of the cone? ") - rB = float(answer) - get answer from Input("What is the vertical height of the cone? ") - h = float(answer) - get answer from Input("How many sides should the truncated pyramid have? ") - n = int(answer) - post fmt.printf("dT is %f, dB is %f, and q is %f", dT, dB, q) +solveFor(rT, rB, h float, n int) : + fmt.sprintf("dT is %f, dB is %f, and q is %f", dT, dB, q) given : dT = circumscribingLength(rT, n) dB = circumscribingLength(rB, n) S = sqrt(h squared - (rB-rT) squared) q = sqrt(S squared - ((dB-dT)/2) squared) - -def - (x float) squared : x * x