Data update
This commit is contained in:
parent
5af6d93694
commit
796d366b97
455 changed files with 7413 additions and 1900 deletions
51
Task/Faces-from-a-mesh/Koka/faces-from-a-mesh.koka
Normal file
51
Task/Faces-from-a-mesh/Koka/faces-from-a-mesh.koka
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
alias perimeter = list<int>
|
||||
alias face = (char, perimeter)
|
||||
alias edge = (int, int)
|
||||
|
||||
fun isSame(p1: perimeter, p2: perimeter, noSwitch: list<int> = []): div bool
|
||||
match (p1, p2)
|
||||
([], []) -> True
|
||||
(Cons(x1, xs1), Cons(x2, xs2)) | x1 == x2 -> isSame(xs1, xs2)
|
||||
_ ->
|
||||
match p2
|
||||
Nil -> False
|
||||
Cons(x2, xs2) ->
|
||||
if noSwitch.any(fn(x') x' == x2) then False else p1.isSame(xs2 ++ [x2], Cons(x2, noSwitch))
|
||||
|
||||
fun show(f: face)
|
||||
val (c, p) = f
|
||||
c.core/show ++ " " ++ p.core/show
|
||||
|
||||
fun findRemove(l: list<a>, acc: ctx<list<a>>, pred: (a) -> bool): maybe<(a, list<a>)>
|
||||
match l
|
||||
[] -> Nothing
|
||||
Cons(x, xs) -> match pred(x)
|
||||
True -> Just((x, acc ++. xs))
|
||||
False -> findRemove(xs, acc ++ ctx Cons(x, _), pred)
|
||||
|
||||
fun toPerimeter(search: int, edges: list<edge>, acc: ctx<perimeter>): <div,exn> perimeter
|
||||
match edges
|
||||
[] -> acc ++. Cons(search, Nil) // Assume the search matches the first edge's missing
|
||||
_ -> match edges.findRemove(ctx _, fn((a, b)) a == search || b == search)
|
||||
Just(((a, b), xs')) -> if search == a then
|
||||
toPerimeter(b, xs', acc ++ ctx Cons(a, _))
|
||||
else
|
||||
toPerimeter(a, xs', acc ++ ctx Cons(b, _))
|
||||
Nothing -> throw("Cannot find the next edge for " ++ search.show ++ " current perimeter is " ++ (acc ++. Nil).show ++ " and the rest of the edges are: " ++ edges.show-list(fn(s) s.show-tuple(show, show)))
|
||||
|
||||
fun main()
|
||||
val fp = [(('P', [8, 1, 3]), ('R', [1, 3, 8])),
|
||||
(('U', [18, 8, 14, 10, 12, 17, 19]), ('V', [8, 14, 10, 12, 17, 19, 18]))]
|
||||
fp.foreach() fn((f1, f2))
|
||||
val same = f1.snd.isSame(f2.snd)
|
||||
print(f1.show ++ (if same then " is " else " is not ") ++ "the same as " ++ f2.show ++ "\n")
|
||||
val fe = [('E', [(1, 11), (7, 11), (1, 7)]),
|
||||
('F', [(11, 23), (1, 17), (17, 23), (1, 11)]),
|
||||
('G', [(8, 14), (17, 19), (10, 12), (10, 14), (12, 17), (8, 18), (18, 19)]),
|
||||
('H', [(1, 3), (9, 11), (3, 11), (1, 11)])]
|
||||
fe.foreach() fn((f, edges))
|
||||
match edges
|
||||
[] -> ()
|
||||
Cons((initX, _), edges') ->
|
||||
val p = toPerimeter(initX, edges', ctx _)
|
||||
print(f.show ++ " perimeter is " ++ p.show ++ "\n")
|
||||
Loading…
Add table
Add a link
Reference in a new issue