fork download
  1. import Data.Word
  2.  
  3. main :: IO ()
  4. main = do
  5. let ls = [262734068,1284266430,850241238,1854436759,925227574,1072391605,
  6. 1593098480,753973039,1320460728,1653753372,1036510631,1372732547,
  7. 2027209822,1573664868]
  8. print $ map searchX ls
  9.  
  10. searchX :: Word32 -> Word32
  11. searchX x = f 0 maxBound
  12. where
  13. f l r
  14. | r - l > 0 = f l' r'
  15. | otherwise = r
  16. where
  17. (l', r') =
  18. case aboutX x m of
  19. 0 -> (r , m)
  20. 1 -> (l , m)
  21. -1 -> (m + 1, r)
  22. m = (+) =<< (`div` 2) . (r -) $ l
  23.  
  24. aboutX :: Word32 -> Word32 -> Word32
  25. aboutX x a =
  26. case compare a x of
  27. EQ -> 0
  28. GT -> 1
  29. LT -> -1
  30.  
Success #stdin #stdout 0s 6232KB
stdin
Standard input is empty
stdout
[262734069,1284266431,850241239,1854436767,925227575,1072391607,1593098481,753973055,1320460729,1653753373,1036510639,1372732551,2027209823,1573664869]