aboutsummaryrefslogtreecommitdiff
path: root/Puzzle3.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Puzzle3.hs')
-rw-r--r--Puzzle3.hs5
1 files changed, 5 insertions, 0 deletions
diff --git a/Puzzle3.hs b/Puzzle3.hs
new file mode 100644
index 0000000..4076ace
--- /dev/null
+++ b/Puzzle3.hs
@@ -0,0 +1,5 @@
+f :: Int -> Int
+f n = floor $ (sqrt (fromIntegral n - 0.5) + 1) / 2
+
+solve1 :: Int -> Int
+solve1 n = let k = f n in abs ((n - 2 - (2 * k - 1)) `mod` (2 * k) - k) + k