Skip to content

Instantly share code, notes, and snippets.

@hamptonmoore
Last active August 27, 2022 23:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hamptonmoore/ba27ca94986ba8f21fb437606900aaff to your computer and use it in GitHub Desktop.
Save hamptonmoore/ba27ca94986ba8f21fb437606900aaff to your computer and use it in GitHub Desktop.
let replicate
: forall (a : Type) . Natural -> a -> List a
= \n -> \x -> Natural/fold n (\xs -> [ x ] + xs) []
let generate
: forall (a : Type) . Natural -> (Natural -> a) -> List a
= \n -> \f -> List/map (\x -> f x.index) (List/indexed (replicate n { }))
let divide:
Natural -> Natural -> Natural -> Real -> Real
= \x -> \y -> \scale -> \inc ->
let xb = x*scale
# Get a list of numbers 0, y, 2*y, y*3, ... y*xb
let l = generate xb (\xs -> (xs)*y) : List Natural
# Add by inc for each value less than x * scale
let d = List/fold { cons: \next -> \acc ->
let next = next : Natural
in if Real/lessThan next xb
then acc+inc
else acc
, nil: 0 } (l)
in (d)
in {
"Prompt": "Plug in any two numbers (integers, within reason) to divide them",
"Divide":\input1 -> \input2 -> divide input1 input2 10 0.1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment