Skip to content

Instantly share code, notes, and snippets.

@vietnt
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vietnt/f8b26d91e3937c98663f to your computer and use it in GitHub Desktop.
Save vietnt/f8b26d91e3937c98663f to your computer and use it in GitHub Desktop.
let inline isPhom x y z =
let sx, sy, sz = x%13,y%13,z%13
if sx = sy && sy = sz then true
else
let tx, ty, tz = x/13, y/13, z/13
if tx = ty && ty = tz then
let a = max sx sy |> max sz
let c = min sx sy |> min sz
let b = (sx + sy + sz)/3
a = b + 1 && a = c + 2
else false
let checkUf (cards: int []) =
let group = Array.init 10 (fun _ -> 0)
let loop f =
let mutable found = false
for i = 0 to 9-2 do
if not found && group.[i] = 0 then
for j = i+1 to 9-1 do
if not found && group.[j] = 0 then
for k = j+1 to 9 do
if not found && group.[k] = 0 then
found <- f i j k
found
let mask i j k b = group.[i] <- b; group.[j] <- b; group.[k] <- b
let rec check i j k depth =
if isPhom cards.[i] cards.[j] cards.[k] then
if depth = 3 then
true
else
mask i j k depth
if loop (fun x y z -> check x y z (depth + 1)) then true
else
mask i j k 0
false
else false
loop (fun x y z -> check x y z 1), group
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment