Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,40 @@
default(f32)
type complex = (f32, f32)
fun dot(c: complex): f32 =
let (r, i) = c
in r * r + i * i
fun multComplex(x: complex, y: complex): complex =
let (a, b) = x
let (c, d) = y
in (a*c - b * d,
a*d + b * c)
fun addComplex(x: complex, y: complex): complex =
let (a, b) = x
let (c, d) = y
in (a + c,
b + d)
fun divergence(depth: int, c0: complex): int =
loop ((c, i) = (c0, 0)) = while i < depth && dot(c) < 4.0 do
(addComplex(c0, multComplex(c, c)),
i + 1)
in i
fun mandelbrot(screenX: int, screenY: int, depth: int, view: (f32,f32,f32,f32)): [screenX][screenY]int =
let (xmin, ymin, xmax, ymax) = view
let sizex = xmax - xmin
let sizey = ymax - ymin
in map (fn (x: int): [screenY]int =>
map (fn (y: int): int =>
let c0 = (xmin + (f32(x) * sizex) / f32(screenX),
ymin + (f32(y) * sizey) / f32(screenY))
in divergence(depth, c0))
(iota screenY))
(iota screenX)
fun main(screenX: int, screenY: int, depth: int, xmin: f32, ymin: f32, xmax: f32, ymax: f32): [screenX][screenY]int =
mandelbrot(screenX, screenY, depth, (xmin, ymin, xmax, ymax))