Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
32
Task/Hailstone-sequence/Futhark/hailstone-sequence.futhark
Normal file
32
Task/Hailstone-sequence/Futhark/hailstone-sequence.futhark
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
fun hailstone_step(x: int): int =
|
||||
if (x % 2) == 0
|
||||
then x/2
|
||||
else (3*x) + 1
|
||||
|
||||
fun hailstone_seq(x: int): []int =
|
||||
let capacity = 100
|
||||
let i = 1
|
||||
let steps = replicate capacity (-1)
|
||||
let steps[0] = x
|
||||
loop ((capacity,i,steps,x)) = while x != 1 do
|
||||
let (steps, capacity) =
|
||||
if i == capacity then
|
||||
(concat steps (replicate capacity (-1)),
|
||||
capacity * 2)
|
||||
else (steps, capacity)
|
||||
let x = hailstone_step x
|
||||
let steps[i] = x
|
||||
in (capacity, i+1, steps, x)
|
||||
in (split i steps).0
|
||||
|
||||
fun hailstone_len(x: int): int =
|
||||
let i = 1
|
||||
loop ((i,x)) = while x != 1 do
|
||||
(i+1, hailstone_step x)
|
||||
in i
|
||||
|
||||
fun max (x: int) (y: int): int = if x < y then y else x
|
||||
|
||||
fun main (x: int) (n: int): ([]int, int) =
|
||||
(hailstone_seq x,
|
||||
reduce max 0 (map hailstone_len (map (1+) (iota (n-1)))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue