Skip to content

Commit

Permalink
Make trig app purely functional
Browse files Browse the repository at this point in the history
  • Loading branch information
peachpit-site committed Nov 18, 2024
1 parent e4e3680 commit cd29ee0
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions examples/trig.pf
Original file line number Diff line number Diff line change
@@ -1,35 +1,24 @@
// 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"
"fmt"

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

Expand Down

0 comments on commit cd29ee0

Please sign in to comment.