• + 0 comments

    Here is my haskell solution. This will actually give you a list of all possible combos that sum to the target number. I just take the length of the returned list to get the amount of combos.

    _sop x n i r
      | nr < x = _sop x n i' r' ++ _sop x n i' r
      | nr == x = [r']
      | otherwise = []
     where
      nr = sum . map (^ n) $ r'
      r' = i : r
      i' = i + 1
      
    sumOfPowers x n = _sop x n 1 []
    
    solve s = show . length $ sumOfPowers x n
     where
      [x, n] = take 2 . map read $ lines s
      
    main = interact solve