this repo has no description
1module Lib
2 ( judgeMatchCount
3 ) where
4
5import Data.Bits
6
7nextVal :: Int -> Int -> Int
8nextVal factor x = rem (x * factor) 2147483647
9
10nextVal2 :: Int -> Int -> Int -> Int
11nextVal2 factor multOf x =
12 let v = nextVal factor x
13 in if rem v multOf == 0 then v else nextVal2 factor multOf v
14
15judgeMatchCount :: Int -> Int -> Int -> Int
16judgeMatchCount startA startB total = go startA startB 0 0
17 where first16 x = x .&. 0xffff
18 go :: Int -> Int -> Int -> Int -> Int
19 go prevA prevB n count
20 | n == total = count
21 | otherwise = let nextA = nextVal2 16807 4 prevA
22 nextB = nextVal2 48271 8 prevB
23 in case (first16 nextA == first16 nextB) of
24 True -> go nextA nextB (n + 1) (count + 1)
25 False -> go nextA nextB (n + 1) count