This file contains 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
#!/usr/bin/env stack | |
-- stack --resolver lts-6.15 script | |
{-# LANGUAGE OverloadedStrings #-} | |
-- import qualified Data.ByteString.Lazy.Char8 as L8 | |
-- targetSum -> currentSum -> subArray -> remainingNums -> subarray if it sums to targetSum OR [] otherwise | |
target_sum :: Integer -> Integer -> [Integer] -> [Integer] -> [Integer] | |
target_sum ts _ [] (n:ns) = target_sum ts n [n] ns {- our base case: there's nothing in the sub array -} | |
target_sum ts cs a _ {- yay! the current sum is the target sum! return the subarray -} | |
| ts == cs = a |
This file contains 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
{ | |
} |