Browse Source

[Haskell][25] Adding Solution

Vinicius Teshima 4 tháng trước cách đây
mục cha
commit
a8bafc5a2b
1 tập tin đã thay đổi với 17 bổ sung0 xóa
  1. 17 0
      haskell/src/0025.hs

+ 17 - 0
haskell/src/0025.hs

@@ -0,0 +1,17 @@
+
+import Utils
+
+import Data.Tuple
+
+fibonacciWhile :: (Integer -> Bool) -> (Int, Integer)
+fibonacciWhile f = go' 1 1 1
+  where
+    go' i f1 f2
+      | f f1      = go' (i+1) (f1+f2) f1
+      | otherwise = (i, f1)
+
+solution :: Int
+solution = (fibonacciWhile (\x -> (length $ show x) < 1000) |> fst) + 1
+
+main :: IO ()
+main = putStrLn ("Solution: " ++ show solution)