+ Reply to Thread
Results 1 to 11 of 11

Number Puzzle Help - Why does 5th grader get such hard homework assignment.

  1. #1
    Forum Contributor
    Join Date
    05-02-2013
    Location
    Indiana
    MS-Off Ver
    Excel 2016
    Posts
    190

    Number Puzzle Help - Why does 5th grader get such hard homework assignment.

    My sons fifth grade math teacher assigned a nearly impossible homework assignment, for a fifth grader. Add two, three digit numbers, which yields a four digit answer, without any duplications. Ex) 423 + 675 = 1098. In other words, you have to use all ten digits 0 - 9. I busted my brain to figure it out with no luck. So I wrote a VBA code to calculate the possible answers. My program works, I think, I came up with 96 possibilities. I am not positive that is correct, but I am assuming that my program pinned all the possible answers. My question: Can someone come up with a more efficient algorithm that works a little nicer and faster than my code? My use of For Next Loops seems to be slow and rudimentary. Thanks to all that tackle this small problem.
    Attached Files Attached Files

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,091

    Re: Number Puzzle Help - Why does 5th grader get such hard homework assignment.

    Nearly impossible or challenging? Maybe your son's teacher has high expectations and thinks that your son (and/or his whole class) can cope with it. What's the point of setting something that doesn't make your pupils think? I hope you aren't going to do his homework for him.

    By the way, I was a teacher until I retired a month ago.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,765

    Re: Number Puzzle Help - Why does 5th grader get such hard homework assignment.

    I see that your For loops range from 100 to 999, but as both numbers have to be 3-digit then you only need to go up to 900 - that should save you a few iterations.

    Hope this helps.

    Pete

  4. #4
    Forum Contributor
    Join Date
    05-02-2013
    Location
    Indiana
    MS-Off Ver
    Excel 2016
    Posts
    190

    Re: Number Puzzle Help - Why does 5th grader get such hard homework assignment.

    You know, I never looked at that way. I think your right, it must have been given to expand his mind. That home work is already finished for him and the problem has been burning on my mind. I guess the math teacher is going to stretch both of our minds. Thanks for your comment, I believe it has helped me!
    Steve

  5. #5
    Forum Contributor
    Join Date
    05-02-2013
    Location
    Indiana
    MS-Off Ver
    Excel 2016
    Posts
    190

    Re: Number Puzzle Help - Why does 5th grader get such hard homework assignment.

    Yes, I have been working on that number, I came up with a starting number of 234. I know that the 1 will be the forth digit in the answer, so I can start with 2??. And since 1 and 2 are ruled out, I can use 23? and sense I have now used 1, 2, 3, I can assume my next digit will be 4. Therefore, I can start it with 234. I believe the ending number can be narrowed also to some certain number, but I will have to think about that for a while. Thanks for you input. Steve

  6. #6
    Valued Forum Contributor
    Join Date
    07-13-2021
    Location
    California, USA
    MS-Off Ver
    2010
    Posts
    513

    Re: Number Puzzle Help - Why does 5th grader get such hard homework assignment.

    I don't know why Pete believes the largest 3-digit number is 900.

    (In the final analysis, it turns out that he is right. The largest 3-digit number is 879. But how can we know that a priori?)

    Since each digit must be unique, I believe the range of 3-digit numbers is 203 to 987, noting that the minimum 4-digit sum is 1023 and the maximum sum is 1640 (987+653). That is, 1 is always the most-significant digit of the 4-digit sum.

    So, the max number of brute-force iterations is 616,225 (987-203+1 = 785, squared).

    However, the inner loop can be conceptually y=MAX(1023-x0, 203) to 987. That reduces the number of brute-force iterations to 425,572.

    I assume that 246+789 = 1035 is the same as 789+246 = 1035. So, I believe the number of solutions is 48, not 96.

    The VBA procedure below finds the 48 solutions in less than 0.15 sec on my computer. (YMMV) I don't know if it qualifies as ``more efficient algorithm that works a little nicer and faster``.

    If you want to count "duplicates", change #If 1 to #If 0. Ironically, it takes the same amount of time to find 96 solutions.

    -----

    That said, I believe an optimal algorithm requires at most 47,040 iterations. That is 8*7*7*6*5*4. 8*7 because the first digit of each 3-digit number is 2 to 9, and they are unique. 7*6*5*4 because the subsequent digits can include 0, and again, they are unique.

    But I suspect that implementation is messier. (TBD)

    -----

    My brute-force implementation....

    Errata.... Change Me.UsedRange.Clear to ActiveSheet.UsedRange.Clear if you put the procedure into a normal module instead of a worksheet module, as I did.

    Please Login or Register  to view this content.
    Last edited by curiouscat408; 08-07-2021 at 03:01 AM. Reason: small improvement to inner loop control

  7. #7
    Valued Forum Contributor
    Join Date
    07-13-2021
    Location
    California, USA
    MS-Off Ver
    2010
    Posts
    513

    Re: Number Puzzle Help - Why does 5th grader get such hard homework assignment.

    A much more straight-forward approach, building on the previous analysis.

    1. Generate all 3-digit numbers with unique digits between 203 and 987. 575 qualified numbers of 800 combinations.

    2. Generate the sums of all pairs of 3-digit numbers between 1023 and 1640 (987+653), and check for uniqueness of all digits. 165,025 iterations.

    The algorithm directly generates only the 48 unique pairs that qualify. No need to check for duplicate pairs.

    It executes in about 0.05 sec on my computer. (YMMV)

    Again, change Me.UsedRange.Clear to ActiveSheet.UsedRange.Clear if you put the procedure into a normal module instead of a worksheet module, as I did.

    Please Login or Register  to view this content.
    Last edited by curiouscat408; 08-07-2021 at 05:52 AM. Reason: small simplification in 3-digit generation

  8. #8
    Valued Forum Contributor
    Join Date
    07-13-2021
    Location
    California, USA
    MS-Off Ver
    2010
    Posts
    513

    Re: Number Puzzle Help - Why does 5th grader get such hard homework assignment.

    Sorry for the incessant postings; and I might be beating a dead horse. But I had an epiphany that might be helpful to future readers who must deal with "fifth grade" math.

    The problem might not be so intractable for young children who are taught "common core math". I don't know much that. But I believe it teaches students to look at the structure of numbers, not just the mechanics of arithmetic.

    So the expected reasoning might go something like this....

    1. The 4-digit number (z) must be 1023 to 1640 (897+653), because digits must be unique.
    Thus, z is of the form 10gh, 12gh, 13gh, 14gh, 15gh or 16gh.

    2. Also, #1 ==> ("implies") given x=abc and y=def ("is of the form of"),
    a+d or a+d+1 is 10, 12, 13, 14, 15 or 16.
    a+d+1 results from a carry from b+e.

    3. Suppose z=10gh.
    Then a+d is 2+8, 3+7, 4+6 if b+e<10 (no carry),
    or a+d is 1+8, 2+7, 3+6, 4+5 if b+e>9 (carry)

    4. Suppose z=10gh and x=3bc and y=7ef.
    That leaves 2,4,5,6,8,9 for the remaining digits.
    And #3 (b+e<10) ==> b+e is 2+4 or 4+5 if c+f<10 (no carry),
    or b+e is 2+5 if c+f>9 (carry),
    or b+e is 2+6 regardless of c+f (carry or not).

    5. Suppose x=32c and y=76f and z=108h (c+f<10; no carry).
    That leaves 4,5,9 for the remaining digits.
    Thus c=4, f=5 and h=9 (c+f).

    So, x=324, y=765 and z=1089.

    And due to commutativity, we also have 3 other solutions, to wit:
    x=325, y=764 and z=1089
    x=365, y=724 and z=1089
    x=364, y=725 and z=1089

    Of course, I got lucky with my choices. (wink)

    The solution might require more trial-and-error, iterating steps #3-5 for different choices of a+d and b+e, as well as for z (12gh, 13gh, etc).

    -----

    And to that end, it might be useful to note another structural relationship that we did not need for z=10gh.

    If z<>10gh, one 3-digit number includes zero.

    But zero cannot be the last digit, because xx0+yyy = zzzy. The last digit is not unique.

    Thus, if z<>10gh, x=a0c.

    And c+f>9 (carry) must be true, because otherwise, x0x+yyy = zzyz. The middle digit is not unique.

    (Similarly for y. But since A+B = B+A (commutativity), it does not matter which 3-digit number we choose to include zero.)
    Last edited by curiouscat408; 08-07-2021 at 08:31 PM.

  9. #9
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: Number Puzzle Help - Why does 5th grader get such hard homework assignment.

    Another brute-force takes 0.02 s

    i + k = t and i > k, so i start at 502
    1xxx reserve for total
    234567890 available for the rest


    Please Login or Register  to view this content.
    Attached Files Attached Files

  10. #10
    Forum Contributor
    Join Date
    05-02-2013
    Location
    Indiana
    MS-Off Ver
    Excel 2016
    Posts
    190

    Re: Number Puzzle Help - Why does 5th grader get such hard homework assignment.

    Curioscat408, I have had a great time going over your algorithm. I do not fully understand it, but I will study it for a few days. This seems to have stirred up some serious "I gotta figure it out." Well, it certainly has been a great project for all of us involved. Thank you for your time on this project. I guess it is not really a project, it is just a fun "I gotta figure it out." Thanks, Steve

  11. #11
    Forum Contributor
    Join Date
    05-02-2013
    Location
    Indiana
    MS-Off Ver
    Excel 2016
    Posts
    190

    Re: Number Puzzle Help - Why does 5th grader get such hard homework assignment.

    Bo_Ry, I see your program list the answers properly by not including the 48 duplicate answers. I look forward to diving into your program and see how you solve this intense problem. Hasn't this been a fun project? I may get back to you on your work if I can't figure out your logic, I hope that is ok!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] VBA newbie (HOMEWORK ASSIGNMENT) - Help needed for looping and comparing cells
    By CPsnugglebottom in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-29-2021, 04:00 AM
  2. [SOLVED] Filling up a Number Puzzle
    By tariqhasan75 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-21-2012, 05:52 AM
  3. number puzzle
    By mkron in forum Excel General
    Replies: 14
    Last Post: 01-28-2007, 12:13 AM
  4. basic vba homework assignment
    By mikemike in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-18-2006, 03:35 PM
  5. Number Puzzle
    By PetaPan via OfficeKB.com in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-30-2006, 12:45 PM
  6. [SOLVED] Quick Excel download for homework assignment
    By starme in forum Excel General
    Replies: 3
    Last Post: 03-23-2005, 08:06 PM
  7. Prime number puzzle
    By johnT in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-27-2005, 09:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1