Created
January 31, 2024 17:26
-
-
Save r17x/992c2a563866d6cb4e2d2ec4cf85c648 to your computer and use it in GitHub Desktop.
HackerRankSolutions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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