Sunday, July 5, 2015

can a computer take a figure like 43 and break it down to all combinations of numbers that make up that sum? ie. 43=10+10+10+5+5+3? I may...

I'm not clear on the goal of your question.  Is your task
a computer programming task for which you are to produce a computer-based solution to
the problem for any two digit number?  Is it the number theory task of proposing an
algorithm that will produce the solution for any two digit number?  Or do you just want
a tool that will give you all the possibilities for a given two-digit
number? 


I'm going to try to answer the third because
that's the easiest, but I can't immediately think of a way to do it on Excel.  Here is a
Mathematica solution for 8 (easily adapted to any other number, two-digit or
otherwise).  It's anything but elegant, but I think it's easier to understand what I've
done written this way.


So that I don't have to worry about
redundant answers like 13 = 5 + 5 + 3 and 13 = 5 + 3 + 5, I'm just counting how many
times the number 5 shows up, and how many times the number 3 shows up, whatever the
order, in my first function.  I do that by asking Mathematica to record the count of how
many times each possible addend appears from 0 to the maximum number of times that
addend can fit in whatever is left after accounting for the higher-valued addends. 
Flatten and Partition are used just to keep from having lists within lists in my
output. 




countsfor8=Partition[Flatten[


Table[{n8,n7,n6,n5,n4,n3,n2,n1},


{n8,0,(8)/8},


{n7,0,(8-8*n8)/7},


{n6,0,(8-8*n8-7*n7)/6},


{n5,0,(8-8*n8-7*n7-6*n6)/5},


{n4,0,(8-8*n8-7*n7-6*n6-5*n5)/4},


{n3,0,(8-8*n8-7*n7-6*n6-5*n5-4*n4)/3},


{n2,0,(8-8*n8-7*n7-6*n6-5*n5-4*n4-3*n3)/2},


{n1,(8-8*n8-7*n7-6*n6-5*n5-4*n4-3*n3-2*n2),(8-8*n8-7*n7-6*n6-5*n5-4*n4-3*n3-2*n2)}]


],8]


Then
I wrote a second function to convert the lists of how many times a number appeared in
the sum into an actual
equation.


writeout8[{n8_,n7_,n6_,n5_,n4_,n3_,n2_,n1_}]:=


StringDrop[StringJoin[Flatten[{"8=",


Table["8+",{i,n8}],


Table["7+",{i,n7}],


Table["6+",{i,n6}],


Table["5+",{i,n5}],


Table["4+",{i,n4}],


Table["3+",{i,n3}],


Table["3+",{i,n2}],


Table["1+",{i,n1}]


}]],-1]



Below
are the results for the sum of 8.  I hope it's clear how to adjust the code for other
numbers and that you have access to mathematica on your
campus.


TableForm[Table[writeout8[countsfor8[[i]]],{i,Length[countsfor8]}]]




{


{8=1+1+1+1+1+1+1+1},


{8=2+1+1+1+1+1+1},


{8=2+2+1+1+1+1},


{8=2+2+2+1+1},


{8=2+2+2+2},


{8=3+1+1+1+1+1},


{8=3+2+1+1+1},


{8=3+2+2+1},


{8=3+3+1+1},


{8=3+3+2},


{8=4+1+1+1+1},


{8=4+2+1+1},


{8=4+2+2},


{8=4+3+1},


{8=4+4},


{8=5+1+1+1},


{8=5+2+1},


{8=5+3},


{8=6+1+1},


{8=6+2},


{8=7+1},


{8=8}


}

No comments:

Post a Comment

What is the meaning of the 4th stanza of Eliot's Preludes, especially the lines "I am moved by fancies...Infinitely suffering thing".

A century old this year, T.S. Eliot's Preludes raises the curtain on his great modernist masterpieces, The Love...