Created
October 3, 2014 02:50
-
-
Save sugitach/2c31d6da180836daba4b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(* おおもとのデータ *) | |
let src = [1;2;3;1;3] | |
(* 0〜max までのリスト *) | |
let rec nums_in m lst = | |
if m >= 0 | |
then nums_in (m-1) (m::lst) | |
else lst | |
let nums m = nums_in m [] | |
(* lst から m の数を数えて返す *) | |
let rec count_in m lst c = | |
match lst with | |
[] -> c | |
| car::cdr -> | |
if car = m | |
then count_in m cdr (c+1) | |
else count_in m cdr c | |
let count m lst = count_in m lst 0 | |
(* lst から mlst(list) に含まれない数を数えて返す *) | |
let rec count_not_in mlst lst c = | |
match lst with | |
[] -> c | |
| car::cdr -> | |
if count car mlst > 0 | |
then count_not_in mlst cdr c | |
else count_not_in mlst cdr (c+1) | |
let count_not mlst lst = count_not_in mlst lst 0 | |
(* | |
a => 1の数 | |
b => 2の数 | |
c => 3の数 | |
d => 1〜3以外の数 | |
*) | |
let q_in5 a b c d result = | |
if (count 1 (List.append [a;b;c;d] src) = a) && | |
(count 2 (List.append [a;b;c;d] src) = b) && | |
(count 3 (List.append [a;b;c;d] src) = c) && | |
(count_not [1;2;3] (List.append [a;b;c;d] src) = d) | |
then (a, b, c, d)::result | |
else result | |
let rec q_in4 a b c dlst result = | |
match dlst with | |
[] -> result | |
| car::cdr -> q_in4 a b c cdr (q_in5 a b c car result) | |
let rec q_in3 a b clst dlst result = | |
match clst with | |
[] -> result | |
| car::cdr -> q_in3 a b cdr dlst (q_in4 a b car dlst result) | |
let rec q_in2 a blst clst dlst result = | |
match blst with | |
[] -> result | |
| car::cdr -> q_in2 a cdr clst dlst (q_in3 a car clst dlst result) | |
let rec q_in1 alst blst clst dlst result = | |
match alst with | |
[] -> result | |
| car::cdr -> q_in1 cdr blst clst dlst (q_in2 car blst clst dlst result) | |
let quiz1 = q_in1 (nums 9) (nums 9) (nums 9) (nums 9) [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment