solveProblem' pb@(a, ms) = 
  let m   = head ms
      ms' = tail ms
      loGuess = 0
      hiGuess = fromIntegral $ (m `div` a) + 1
      num = computeNumMotes a (m+1) loGuess hiGuess
      val = sumAbsorbedMotes a num 
      numRec = solveProblem' (val, ms)
  in  if a > m
         then solveProblem' ((a + m), ms')
         else if (num > length ms) || (num == 0) || (num + numRec >= length ms)
                 then length ms -- delete everything that is left
                 else num + numRec
solveProblem' pb@(a, ms) = 
  let m   = head ms
      ms' = tail ms
      loGuess = 0
      hiGuess = fromIntegral $ (m `div` a) + 1
      num = computeNumMotes a (m+1) loGuess hiGuess
      val = sumAbsorbedMotes a num 
      numRec = solveProblem' (val, ms)
  in  if a > m
         then solveProblem' ((a + m), ms')
         else if (num > length ms) || (num == 0) || (num + numRec >= length ms)
                 then length ms -- delete everything that is left
                 else num + numRec
solveProblem' pb@(a, ms) = 
  let m   = head ms
      ms' = tail ms
      loGuess = 0
      hiGuess = fromIntegral $ (m `div` a) + 1
      num = computeNumMotes a (m+1) loGuess hiGuess
      val = sumAbsorbedMotes a num 
      numRec = solveProblem' (val, ms)
  in  if a > m
         then solveProblem' ((a + m), ms')
         else if (num > length ms) || (num == 0) || (num + numRec >= length ms)
                 then length ms -- delete everything that is left
                 else num + numRec