------------------------------------------------------------ Technology/Programming, (sdf.org), 12/05/2018 ------------------------------------------------------------ Disclaimer: I'm not a mathematician. My older son(14) got an itch in his twitch and decided that he wanted to use math to engineer the coolest single-move win that he could in the game of Mancala[1]. Briefly, one of the versions of Mancala we play involves a wooden board with 14 trays carved in the top, and a bunch of pebbles (in this case, clear glass ones) that you have to move around, with each player accumulating in their score tray. I think it's Egyptian Mancala, where if your last drop is in your score tray, you get a bonus turn. It was this version that inspired him to ask "what if I could, in a single move, always drop into my score tray at the end, and get bonus moves until I was done? How would my pieces have to start out?" The cool thing is, this kid is the antithesis of self-motivated. I heard him mention the above the other day, and he stayed with it and figured it out without any help. That alone is awesome to me. Here's what he proudly showed me this afternoon; he came up with the algorithm. It doesn't reflect an actual competitive game of Mancala, just a setup board where one person disposes of 21 pieces in a single turn (you'll need to have played or read the rules to get it, I suppose.) I'll explain it as he explained it to me: Steps for a perfect Mancala run - Number your trays from 0 to 7; 0 is your score tray, directly to the left is tray 1, and up through 7, which is your opponents first tray (the game moves around the board in a circle.) - Starting with tray 7, solve for (y+x)/x, where x is the tray number, and with y starting at 0. - Take the remainder(r). The number of pebbles in that tray(z) is z=r-x - Take the quotient(f) and add it to y, y=y+f - Decrement the tray number(x), x=x-1 and solve for the next tray. Continue until all the trays are solved. For fun, I helped him write it up in QBASIC, so he could quickly solve for any number of trays (and pebbles), which he really wanted to do. Here's the code: 'Sam's Mancala Move Solver SCREEN 0: CLS x = 7 ' Number of trays to solve for y = 0 DIM z(x) ' var for holding solved values FOR i = x TO 1 STEP -1 ' Step through each tray and solve r = (y + i) MOD i ' Get the remainder of the equation f = FIX((y + i) / i) ' Get the quotient of the equation z(i) = i - r ' Save the solution for this tray ' Show the results PRINT "I="; i; "X="; i; "Y="; y; PRINT "F="; f; "R="; r; "Z="; z(i) y = y + f ' Add the quotient of the equation NEXT i I love it when kids see the value of things like math and programming. For a lot of kids, it's really hard to explain why these skills are valuable; when there's a real world problem- especially a fun one- that they need these things for, it just drives it home in a real and solid way. If you want to try the perfect mancala run, but don't have QBASIC and don't want to do the math, set it up like this and take your one glorious turn (tray numbers outside, pebble amounts inside): 7 +---+---+---+---++---+---+---+---+ | | 7 | | || | | | | | +---+---+---||---+-------+ 0 | | | 5 | 3 | 1 || 2 | 2 | 1 | | +---+---+---+---++---+---+---+---+ 6 5 4 3 2 1 Just remember this rule when playing out the turn: Starting from tray 1 each time, eliminate the lowest tray that has exactly the same number of pebbles as the tray number (which will land the last pebble in 0.) If you don't go in this order, you can't complete the move (it's a good rule for this Mancala ruleset anyway.) And, if you teach your kids math and want a great resource that will make them think in odd ways, "Life of Fred" is where it's at (and no, they're not sponsoring this gopher post.) [1] gopher://gopherpedia.com:70/0/Mancala