Skip to content

Instantly share code, notes, and snippets.

View adgarcia's full-sized avatar

Alex adgarcia

  • One Garcia
  • maybe Oakland?
View GitHub Profile
#!/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