-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproblem04.ml
More file actions
29 lines (21 loc) · 737 Bytes
/
problem04.ml
File metadata and controls
29 lines (21 loc) · 737 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
let rec isPal x i n =
if (i >= n -i - 1) then true
else
if (x.[i] = x.[n-i-1]) then isPal x (i+1) n else false
let isPalindrome x =
match x with
| "" -> true
| x -> isPal x 0 (String.length x)
let rec mklist num acc =
match num with
| 999 -> 999::acc
| _ -> mklist (num+1) (num::acc)
let rec mult lst acc =
match lst with
| [] -> flatten acc
| (h::t) -> mult t ((fold_left (fun lst x -> (h,x)::lst) [] (h::t))::acc) ;;
let solve = fold_left ( fun a (x,y) ->
let res = x*y in
if (isPalindrome(string_of_int(res))) then
if (res > a) then res else a
else a ) 0 (mult (mklist 100 []) []);;