forked from suhailshergill/TTFI
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Guillaume Masse
authored and
Guillaume Masse
committed
Feb 6, 2015
1 parent
58f785d
commit ffc544b
Showing
2 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import TTFI._ | ||
|
||
import org.specs2._ | ||
class Fix_Spec extends Specification { | ||
def is = s2""" | ||
Fix should not blow the stack $stackSafe | ||
""" | ||
|
||
def stackSafe = { | ||
|
||
// en.wikipedia.org/wiki/Ackermann_function | ||
def acktabs(ack: ((Int, Int)) => Int)(in: ((Int, Int))): Int = { | ||
val (m, n) = in | ||
if (m <= 0) n + 1 | ||
else if (n <= 0) ack((m - 1, 1)) | ||
else ack((m - 1, ack((m, n - 1)))) | ||
} | ||
|
||
Final.TreeSem.OpenRecursion.fix(acktabs)((5, 5)) ==== 0 | ||
} | ||
} |