Arithmetic progression determination

54 Views Asked by At

I love math but I really suck at and I definitely don't know cool tricks (I stem more from the science part of STEM) so I may even have the wrong term in the title.

That said here is my problem. I'm writing a function for a database and have an increasingly robust error handler. I have a check put in place that when the code works without a problem the variable equals 1234. If the user types any extra keywords in the function the variable can have one set repeating numbers (e.g. 11234, 12234, so on). I found the relationship that if I take the sum of the digits, I can create an error message specific to what the repeat is (Because 1+1+2+3+4 = 11, 1+2+2+3+4 = 12 and a repeat of 1 means something specific while a repeat of 2 means something else entirely). I realized today that there's a potential to have two or maybe more sets of repeating numbers (112234, 123234, etc). I'm trying to think of every possible scenario that the user could mess up.

Is there a nifty math trick where I can find all of the terms of a sum knowing the sum and that the terms will be a combination of numbers between 1 and 4? (Specifically the numbers will be 1, 2, 3, and 4. All should be present at least once.) For example, I know that the sum can be 16 and the terms can be 1+2+2+3+4+4. I'd prefer to not do each sum by hand.