Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: laurentpetit/paradigms
base: 8f738c668c
...
head fork: laurentpetit/paradigms
compare: 32ff3013cf
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Showing with 82 additions and 0 deletions.
  1. +24 −0 FindString.oz
  2. +11 −0 FlattenList.oz
  3. +47 −0 IsBalanced.oz
View
24 FindString.oz
@@ -0,0 +1,24 @@
+declare
+fun {Prefix L1 L2}
+ case L1
+ of nil then true
+ [] H|T then
+ case L2
+ of nil then false
+ [] H1|T1 then
+ if H==H1 then {Prefix T T1}
+ else false end
+ end
+ end
+end
+
+{Browse {Prefix nil nil}}
+
+declare
+fun {FindString L1 L2}
+ if {Prefix L1 L2} then true
+ elseif L2==nil then false
+ else {FindString L1 L2.2} end
+end
+
+{Browse {FindString [a] [a]}}
View
11 FlattenList.oz
@@ -0,0 +1,11 @@
+declare
+fun {FlattenList L}
+ case L
+ of nil then nil
+ [] nil|T then {FlattenList T}
+ [] (H1|T1)|T then {FlattenList H1|T1|T}
+ [] X|T then X | {FlattenList T}
+ end
+end
+
+{Browse {FlattenList [[1 nil [3] 4]]}}
View
47 IsBalanced.oz
@@ -0,0 +1,47 @@
+declare
+Tree=btree(1
+ left:btree(2 left:leaf right:leaf)
+ right:btree(3
+ left:btree(2 left:leaf right:leaf)
+ right:leaf))
+
+{Browse Tree}
+
+declare
+fun {NumLeaves Tree}
+ local Help in
+ fun {Help Trees Acc}
+ case Trees
+ of nil then Acc
+ [] T|Ts then
+ case T
+ of leaf then {Help Ts Acc+1}
+ [] btree(V left:T1 right:T2) then
+ {Help T1|T2|Ts Acc}
+ end
+ end
+ end
+ {Help [Tree] 0}
+ end
+end
+
+{Browse {NumLeaves leaf}}
+{Browse {NumLeaves btree(1 left:leaf right:leaf)}}
+{Browse {NumLeaves Tree}}
+
+declare
+fun {IsBalanced Tree}
+ case Tree
+ of leaf then true
+ [] btree(V left:T1 right:T2) then
+ {And
+ {And {IsBalanced T1} {IsBalanced T2}}
+ {Abs {NumLeaves T1} - {NumLeaves T2}} < 2}
+ end
+end
+
+{Browse {Abs 1-2}}
+{Browse {NumLeaves 3}}
+{Browse {And [true false false]}}
+{Browse {IsBalanced leaf}}
+{Browse {IsBalanced Tree}}

No commit comments for this range

Something went wrong with that request. Please try again.