But using my algorithm to generate increasing and decreasing numbers, I get 220 (for each) below 1000, which is a total of 440, which is less than the 475 expected (and I haven't even subtracted duplicates yet). So I am somehow missing numbers, but I can't figure out which :/

(explanation of the increasing function, if you need it, both increasing and decreasing work the same way)

The program I created is a recursive function, which increments each digit from the predecessor's value up to 9. If it is on the last digit, ie 56_ will have increasing values: 566, 567, 568, 569 so it returns 10-6=4

It keeps track of these sums along the way.

To invoke, execute input(0,n) where n is the number of digits, ie the increasing numbers below 100 would be input(0,2) the increasing numbers below a million would be input(0,6)

To invoke the decreasing function, execute input(9,n) which would then calculate all decreasing numbers below the number

Here is my code, written in Ruby:

**Note: # denotes comments**
[code]#recursive function that calculates increasing numbers

def increase(n, digit)

return 10-n if digit==1

sum=0

while n < 10

sum += increase(n, digit-1)

n+=1

end

return sum

end

#recursinve function that calculates decreasing numbers

def decrease(n, digit)

return n+1 if digit==1

sum=0

while n >= 0

sum += decrease(n, digit-1)

n-=1

end

return sum

end