Add justfile to build for correct out dir

main
trivernis 10 months ago
parent 6ae8d0b8e4
commit 4c9edbfadb
Signed by: Trivernis
GPG Key ID: 7E6D18B61C8D2F4B

@ -5,8 +5,8 @@ app "fibonacci"
main : Task.Task {} I32 main : Task.Task {} I32
main = main =
numStrings = numStrings =
List.range {start: At 0u128, end: At 186u128} # 186 is all we can do with 128 bit List.range { start: At 0u128, end: At 186u128 } # 186 is all we can do with 128 bit
|> List.walk [] fibWalk |> List.walk [] fibWalk
|> List.map Num.toStr |> List.map Num.toStr
|> Str.joinWith "\n" |> Str.joinWith "\n"
@ -15,9 +15,10 @@ main =
fibWalk : List (Num a), Num a -> List (Num a) fibWalk : List (Num a), Num a -> List (Num a)
fibWalk = \l, n -> fibWalk = \l, n ->
next = when l is next =
[] | [_] -> fib n when l is
[.., a, b] -> a + b [] | [_] -> fib n
[.., a, b] -> a + b
List.append l next List.append l next
fib : Num a -> Num a fib : Num a -> Num a

@ -0,0 +1,13 @@
set shell := ["nu", "-c"]
default:
print "Select a command"
dev target +FLAGS="": (build target FLAGS)
if ('out/{{target}}' | path exists) { out/{{target}} } else { ^$"out/('{{target}}' | str replace -r '\.roc$' '')" }
build target +FLAGS="--optimize": init
roc build {{FLAGS}} ('{{target}}.roc' | str replace -r '\.roc\.roc$' '.roc') --output out/
init:
mkdir out/

@ -5,8 +5,8 @@ app "prime"
main : Task.Task {} I32 main : Task.Task {} I32
main = main =
numStrings = numStrings =
List.range {start: At 0u64, end: At 1_000_000u64} List.range { start: At 0u64, end: At 1_000_000u64 }
|> List.map \e -> isPrimePre e |> List.map \e -> isPrimePre e
|> List.walk [] primeWalk |> List.walk [] primeWalk
|> List.map Num.toStr |> List.map Num.toStr
@ -21,11 +21,13 @@ primeWalk = \l, n ->
when n is when n is
Yes n2 -> Yes n2 ->
List.append l n2 List.append l n2
Maybe n2 -> Maybe n2 ->
if isPrimePost l n2 then if isPrimePost l n2 then
List.append l n2 List.append l n2
else else
l l
No _ -> l No _ -> l
isPrimePre : U64 -> PrimeResult isPrimePre : U64 -> PrimeResult
@ -34,23 +36,23 @@ isPrimePre = \n ->
No n No n
else if n < 4 then else if n < 4 then
Yes n Yes n
else if ( firstPrimes |> List.any \p -> n > p && n % p == 0 ) then else if (firstPrimes |> List.any \p -> n > p && n % p == 0) then
No n No n
else else
Maybe n Maybe n
isPrimePost : List U64, U64 -> Bool isPrimePost : List U64, U64 -> Bool
isPrimePost = \l, n -> isPrimePost = \l, n ->
nFloat = (Num.toF64 n) nFloat = Num.toF64 n
valLimit = Num.ceiling (Num.sqrt nFloat) valLimit = Num.ceiling (Num.sqrt nFloat)
# approximate the number of primes < sqrt(n) to limit the range we have to check with a 25% error tolerance # approximate the number of primes < sqrt(n) to limit the range we have to check with a 25% error tolerance
valLimitF = Num.toF64 valLimit valLimitF = Num.toF64 valLimit
limit = Num.ceiling (valLimitF * 1.25 / (Num.log valLimitF)) limit = Num.ceiling (valLimitF * 1.25 / (Num.log valLimitF))
l l
|> List.sublist {start: 0, len: limit} |> List.sublist { start: 0, len: limit }
|> List.dropIf \p -> p > valLimit |> List.dropIf \p -> p > valLimit
|> List.any \p -> n % p == 0 |> List.any \p -> n % p == 0
|> Bool.not |> Bool.not
firstPrimes = firstPrimes =
[2, 3, 5, 7, 9, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 51, 67, 71, 73, 79, 83, 89, 97] [2, 3, 5, 7, 9, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 51, 67, 71, 73, 79, 83, 89, 97]

Loading…
Cancel
Save