Skip to content

Instantly share code, notes, and snippets.

@r17x
Created January 31, 2024 17:26
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 r17x/992c2a563866d6cb4e2d2ec4cf85c648 to your computer and use it in GitHub Desktop.
Save r17x/992c2a563866d6cb4e2d2ec4cf85c648 to your computer and use it in GitHub Desktop.
HackerRankSolutions
-- Input: 10
-- Output: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
-- Signature
fn :: (Integral a) => a -> [a]
-- Solution with pattern-matching
fn 0x0 = []
fn n = if n - 1 < 0 then fn 0 else fn (n - 1) ++ [n]
-- n = -1
-- fn = fn(-1 -1 ? 0 : n-1) ++ [-1]
-- fn = [] ++ [-1]
-- fn = [-1]
-- n = 2 -> fn(2 - 1) ++ [2]
main = do
n <- readLn :: IO Int
print (fn n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment