Population puzzle
Scott Rossi
scott at tactilemedia.com
Mon Aug 25 02:27:04 EDT 2014
If I understand the challenge, the goal is to find some combination of the
numbers that adds up to 100000000. If this isn't right, ignore the
following.
If the above is true, then here's a brute force randomized solution that
arrives at the answer by chance, has no mathematical logic, and will
likely require multiple executions to get the answer.
[ in a button script ]
on mouseUp
repeat 1000000
put 0 into theTotal
put empty into theList
put theNumbers() into theSet
put number of items of theSet into theCount
repeat
put random(number of items of theSet) into itemNumber
put item itemNumber of theSet into theNumber
delete item itemNumber of theSet
put theNumber & cr after theList
add theNumber to theTotal
if theTotal > 100000000 then exit repeat
if theTotal = 100000000 then
put "Solution:" & cr & theList
exit mouseUp
end if
end repeat
--
end repeat
put "Solution not found" && seconds()
end mouseUp
function theNumbers
return
18897109,12828837,9461105,6371773,5965343,5946800,5582170,5564635,5268860,4
552402,4335391,4296250,4224851,4192887,3439809,3279833,3095313,2812896,2783
243,2710489,2543482,2356285,2226009,2149127,2142508,2134411
end theNumbers
Stupid, yes, but hey, it (eventually) works.
Regards,
Scott Rossi
Creative Director
Tactile Media, UX/UI Design
On 8/24/14 4:52 PM, "Michael Doub" <mikedoub at gmail.com> wrote:
>I know that some of the folks on this list enjoy puzzles. A friend sent
>me this one this afternoon and I thought it would be interesting to see
>the different approaches folks come up with and how fast it can be
>solved. enjoyŠ
>
>The 2010 Census puts populations of 26 largest US metro areas at
>18897109, 12828837, 9461105, 6371773, 5965343,5946800, 5582170, 5564635,
>5268860, 4552402, 4335391, 4296250, 4224851, 4192887, 3439809, 3279833,
>3095313,2812896, 2783243, 2710489, 2543482, 2356285, 2226009, 2149127,
>2142508, and 2134411.
>
>Can you find a subset of these areas where a total of exactly 100,000,000
>people live, assuming the census estimates are exactly right?
>_______________________________________________
>use-livecode mailing list
>use-livecode at lists.runrev.com
>Please visit this url to subscribe, unsubscribe and manage your
>subscription preferences:
>http://lists.runrev.com/mailman/listinfo/use-livecode
More information about the Use-livecode
mailing list