0

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.

  • Does the order matter? i.e. is $11234$ a different error than $12134$? – wgrenard Jan 12 '18 at 16:40
  • Order shouldn't matter since each digit represents a portion of the whole. The most ideal, "correct" number would be 1234, but 1324 works just as well. The key is that there is one 1, one 2, one 3, and one 4. – Lux Claridge Jan 12 '18 at 17:18
  • You cannot differentiate between 112344 and 122334 just by sum (or even number of entries and sum). – Paul Sinclair Jan 12 '18 at 23:23
  • Crum, you are right. I want to say that it will be impossible to have multiple fours with how I have things programmed, but never underestimate the power of the end user. Perhaps it's best that I just do this by hand and somehow transpose it to my program later. – Lux Claridge Jan 15 '18 at 18:14

0 Answers0