This is a course page of David Casperson |
|
There are 34=81 such functions
fun triangle 0 = 0 | triangle n = n + triangle (n-1) ;or (tail-recursively)
fun triangle n = let fun t2 (0,a) = a | t2 (n,a) = t2(n-1,n+a) in t2 (n,0) end
. .. . ... .. . .... ... .. .
fun pyramid 0 = 0 | pyramid n = triangle n + pyramid (n-1) ;
fun nDimSimplex (_,0) = 0 | nDimSimplex (0,_) = 1 | nDimSimplex (k,n) = nDimSimplex (k-1,n) + nDimSimplex(k,n-1) ;
winning
and losing
functions discussed in class.
See this
.pdf
file for a carefully worked solution.
A solution can be found on galaxy.unbc.ca
at /export/research/casper/cpsc370/doublingNim.sml
.
This solution found there is an exponential search rather than something clever.
val f = n => if n>100 then n-10 else
f(f(n+11))
We prove this by strong induction on the quantity 101-n.
The base case is 101-n ≤ 0. Here, clearly, the claim holds as the function returns n-10 which is greater than or equal to 91.
Now, inductively, suppose that the claim holds for all 101-n less than 101-k, that is, for all n > k.
If 0 ≤ 101-k ≤ 11, we have that f(k) = f(f(k+11)) = f(k+11-10) = f(k+1) which by our induction hypothesis is 91.
If on the other hand 11 < 101-k, then f(k) = f(f(k+11)) = f(91) by our induction hypothesis = 91.
fall-2024