Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
104
Task/Amicable-pairs/ATS/amicable-pairs.ats
Normal file
104
Task/Amicable-pairs/ATS/amicable-pairs.ats
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
(* ****** ****** *)
|
||||
//
|
||||
#include
|
||||
"share/atspre_staload.hats"
|
||||
#include
|
||||
"share/HATS/atspre_staload_libats_ML.hats"
|
||||
//
|
||||
(* ****** ****** *)
|
||||
//
|
||||
fun
|
||||
sum_list_vt
|
||||
(xs: List_vt(int)): int =
|
||||
(
|
||||
case+ xs of
|
||||
| ~list_vt_nil() => 0
|
||||
| ~list_vt_cons(x, xs) => x + sum_list_vt(xs)
|
||||
)
|
||||
//
|
||||
(* ****** ****** *)
|
||||
|
||||
fun
|
||||
propDivs
|
||||
(
|
||||
x0: int
|
||||
) : List0_vt(int) =
|
||||
loop(x0, 2, list_vt_sing(1)) where
|
||||
{
|
||||
//
|
||||
fun
|
||||
loop
|
||||
(
|
||||
x0: int, i: int, res: List0_vt(int)
|
||||
) : List0_vt(int) =
|
||||
(
|
||||
if
|
||||
(i * i) > x0
|
||||
then list_vt_reverse(res)
|
||||
else
|
||||
(
|
||||
if x0 % i != 0
|
||||
then
|
||||
loop(x0, i+1, res)
|
||||
// end of [then]
|
||||
else let
|
||||
val res =
|
||||
cons_vt(i, res)
|
||||
// end of [val]
|
||||
val res =
|
||||
(
|
||||
if i * i = x0 then res else cons_vt(x0 / i, res)
|
||||
) : List0_vt(int) // end of [val]
|
||||
in
|
||||
loop(x0, i+1, res)
|
||||
end // end of [else]
|
||||
// end of [if]
|
||||
)
|
||||
) (* end of [loop] *)
|
||||
//
|
||||
} // end of [propDivs]
|
||||
|
||||
(* ****** ****** *)
|
||||
|
||||
fun
|
||||
sum_propDivs(x: int): int = sum_list_vt(propDivs(x))
|
||||
|
||||
(* ****** ****** *)
|
||||
|
||||
val
|
||||
theNat2 = auxmain(2) where
|
||||
{
|
||||
fun
|
||||
auxmain
|
||||
(
|
||||
n: int
|
||||
) : stream_vt(int) = $ldelay(stream_vt_cons(n, auxmain(n+1)))
|
||||
}
|
||||
|
||||
(* ****** ****** *)
|
||||
//
|
||||
val
|
||||
theAmicable =
|
||||
(
|
||||
stream_vt_takeLte(theNat2, 20000)
|
||||
).filter()
|
||||
(
|
||||
lam x =>
|
||||
let
|
||||
val x2 = sum_propDivs(x)
|
||||
in x < x2 && x = sum_propDivs(x2) end
|
||||
)
|
||||
//
|
||||
(* ****** ****** *)
|
||||
|
||||
val () =
|
||||
theAmicable.foreach()
|
||||
(
|
||||
lam x => println! ("(", x, ", ", sum_propDivs(x), ")")
|
||||
)
|
||||
|
||||
(* ****** ****** *)
|
||||
|
||||
implement main0 () = ()
|
||||
|
||||
(* ****** ****** *)
|
||||
Loading…
Add table
Add a link
Reference in a new issue