Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local
- (* an exception we hopefully don't need *)
- exception Error of string;
- (* isinList == check if char is in char list *)
- fun isinList (c:char) ([]:char list) = false
- | isinList (c:char) ((clh::clt):char list) = if clh = c then true else isinList c clt;
- (* checkList == check if a row or column has only the following character set 1,2,3,4,5,6,7,8,9 *)
- fun checkList ([]) ([]) = true
- | checkList (l::ls) ((h::tl):char list) = if l = h then checkList (ls) (tl) else if (isinList l tl) then checkList (l::ls) (tl@[h]) else false
- | checkList _ _ = false;
- (* makeColumn == make char list list of the Columns *)
- fun makeColumn ([[], [], [], [], [], [], [], [], []]:char list list) (accl:char list list) = accl
- | makeColumn ([(h1::cl1):char list, (h2::cl2):char list, (h3::cl3):char list, (h4::cl4):char list, (h5::cl5):char list, (h6::cl6):char list, (h7::cl7):char list, (h8::cl8):char list, (h9::cl9):char list]:char list list) (accl:char list list) =
- makeColumn ([cl1:char list, cl2:char list, cl3:char list, cl4, cl5, cl6, cl7, cl8, cl9]) ([h1, h2, h3, h4, h5, h6, h7, h8, h9]::accl)
- | makeColumn (_) (_) = raise Error "Error in makeColumn";
- in
- (* rscheck : char list list -> bool *)
- fun rscheck ([]:char list list) = true
- | rscheck ([cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9]:char list list) = if
- (checkList(cl1) ([#"1",#"2",#"3",#"4",#"5",#"6",#"7",#"8",#"9"])) andalso
- (checkList(cl2) ([#"1",#"2",#"3",#"4",#"5",#"6",#"7",#"8",#"9"])) andalso
- (checkList(cl3) ([#"1",#"2",#"3",#"4",#"5",#"6",#"7",#"8",#"9"])) andalso
- (checkList(cl4) ([#"1",#"2",#"3",#"4",#"5",#"6",#"7",#"8",#"9"])) andalso
- (checkList(cl5) ([#"1",#"2",#"3",#"4",#"5",#"6",#"7",#"8",#"9"])) andalso
- (checkList(cl6) ([#"1",#"2",#"3",#"4",#"5",#"6",#"7",#"8",#"9"])) andalso
- (checkList(cl7) ([#"1",#"2",#"3",#"4",#"5",#"6",#"7",#"8",#"9"])) andalso
- (checkList(cl8) ([#"1",#"2",#"3",#"4",#"5",#"6",#"7",#"8",#"9"])) andalso
- (checkList(cl9) ([#"1",#"2",#"3",#"4",#"5",#"6",#"7",#"8",#"9"])) then case (makeColumn([cl1,cl2,cl3,cl4,cl5,cl6,cl7,cl8,cl9]) ([])) of ([clc1, clc2, clc3, clc4, clc5, clc6, clc7, clc8, clc9]):char list list
- => if
- (checkList(clc1) ([#"1",#"2",#"3",#"4",#"5",#"6",#"7",#"8",#"9"])) andalso
- (checkList(clc2) ([#"1",#"2",#"3",#"4",#"5",#"6",#"7",#"8",#"9"])) andalso
- (checkList(clc3) ([#"1",#"2",#"3",#"4",#"5",#"6",#"7",#"8",#"9"])) andalso
- (checkList(clc4) ([#"1",#"2",#"3",#"4",#"5",#"6",#"7",#"8",#"9"])) andalso
- (checkList(clc5) ([#"1",#"2",#"3",#"4",#"5",#"6",#"7",#"8",#"9"])) andalso
- (checkList(clc6) ([#"1",#"2",#"3",#"4",#"5",#"6",#"7",#"8",#"9"])) andalso
- (checkList(clc7) ([#"1",#"2",#"3",#"4",#"5",#"6",#"7",#"8",#"9"])) andalso
- (checkList(clc8) ([#"1",#"2",#"3",#"4",#"5",#"6",#"7",#"8",#"9"])) andalso
- (checkList(clc9) ([#"1",#"2",#"3",#"4",#"5",#"6",#"7",#"8",#"9"])) then true else false
- | _ => raise Error "Error in return of makeColumn"
- else false;
- end;
- (* Testcase1 => true *)
- val test1 =[[#"1",#"2",#"3",#"4",#"5",#"6",#"7",#"8",#"9"],
- [#"9",#"1",#"2",#"3",#"4",#"5",#"6",#"7",#"8"],
- [#"8",#"9",#"1",#"2",#"3",#"4",#"5",#"6",#"7"],
- [#"7",#"8",#"9",#"1",#"2",#"3",#"4",#"5",#"6"],
- [#"6",#"7",#"8",#"9",#"1",#"2",#"3",#"4",#"5"],
- [#"5",#"6",#"7",#"8",#"9",#"1",#"2",#"3",#"4"],
- [#"4",#"5",#"6",#"7",#"8",#"9",#"1",#"2",#"3"],
- [#"3",#"4",#"5",#"6",#"7",#"8",#"9",#"1",#"2"],
- [#"2",#"3",#"4",#"5",#"6",#"7",#"8",#"9",#"1"]];
- rscheck (test1);
- (* Testcase2 => false *)
- val test2 =[[#"1",#"2",#"3",#"4",#"5",#"6",#"7",#"8",#"9"],
- [#"9",#"1",#"2",#"3",#"4",#"5",#"6",#"7",#"8"],
- [#"8",#"9",#"1",#"2",#"3",#"4",#"5",#"6",#"7"],
- [#"7",#"8",#"9",#"1",#"2",#"3",#"4",#"5",#"6"],
- [#"6",#"7",#"8",#"9",#"1",#"2",#"3",#"4",#"5"],
- [#"5",#"6",#"7",#"8",#"9",#"1",#"2",#"3",#"4"],
- [#"4",#"5",#"6",#"7",#"8",#"9",#"1",#"2",#"3"],
- [#"3",#"4",#"5",#"6",#"7",#"8",#"9",#"1",#"2"],
- [#"3",#"2",#"4",#"5",#"6",#"7",#"8",#"9",#"1"]];
- rscheck (test2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement