#!/usr/local/bin/maple # -*- maplev -*- # Nathaniel Shar # HW 10 # Experimental Mathematics # It is okay to link to this assignment on the course webpage. Help := proc(): print(`LegalMovesG(Board, i), FG(Board, r), LegalMoves(Board, i), FP(Board, r), FR(Board, r), average(S), F(Board, r)`): end: ############# # Problem 1 # ############# LegalMovesG := proc(Board, i) local S, j, k: S := {}: for j from 1 to nops(Board) do: if j < i and Board[j] > 0 then: if {seq(Board[k], k=j+1..nops(Board))} = {0} then: S := S union {subsop(j=Board[j]-1, Board)}: return S: fi: elif j = i and Board[j] > 0 then: S := S union {subsop(j=Board[j]-1, Board)}: return S: elif Board[j] > 0 then: S := S union {subsop(j=Board[j]-1, j-i=Board[j-i]+1, Board)}: return S: fi: od: end: FG := proc(Board, r) option remember: if select(x->x<>0, {op(Board)}) = {} then: return 0: fi: return 1+add(min(seq(FG(b, r), b in LegalMovesG(Board, j))), j in 1..r)/r: end: ############# # Problem 2 # ############# LegalMoves := proc(Board, i) local S, j, k: S := {}: for j from 1 to nops(Board) do: if j < i and Board[j] > 0 then: if {seq(Board[k], k=j+1..nops(Board))} = {0} then: S := S union {subsop(j=Board[j]-1, Board)}: return S: fi: elif j = i and Board[j] > 0 then: S := S union {subsop(j=Board[j]-1, Board)}: elif Board[j] > 0 then: S := S union {subsop(j=Board[j]-1, j-i=Board[j-i]+1, Board)}: fi: od: return S: end: FP := proc(Board, r) option remember: if select(x->x<>0, {op(Board)}) = {} then: return 0: fi: return 1+add(max(seq(FP(b, r), b in LegalMoves(Board, j))), j in 1..r)/r: end: ############# # Problem 3 # ############# FR := proc(Board, r) option remember: if select(x->x<>0, {op(Board)}) = {} then: return 0: fi: return 1+add(average({seq(FR(b, r), b in LegalMoves(Board, j))}), j in 1..r)/r: end: average := proc(S): return add(i, i in S)/nops(S): end: ############# # Problem 4 # ############# F := proc(Board, r) option remember: if select(x->x<>0, {op(Board)}) = {} then: return 0: fi: return 1+add(min(seq(F(b, r), b in LegalMoves(Board, j))), j in 1..r)/r: end: # Basically, F < FG < FR < FP, except for some fringe cases where # various equalities hold (such as # the board of length 2, where F = FG, or when there is only one # piece).