This problem can be solved by pre-school children in 5-10 minutes. By programmers in one hour. By people with a higher education… Well, check it out yourself and post the answer in the comments when you have solved it. Now, those who want to solve it, do not cheat to see if anyone has posted the answer. But then, posting just the answer does not explain the logic here.
This took me just few minutes, so I guess I have a pre-school mentality….
Now, think outside the box, folks. There are a couple links to clues below the problem if you get frustrated, as well as a link to the answer and logic used to solve the problem.
8809 = 6
7111 = 0
2172 = 0
6666 = 4
1111 = 0
3213 = 0
7662 = 2
9313 = 1
0000 = 4
2222 = 0
3333 = 0
5555 = 0
8913 = 3
8096 = 5
7777 = 0
9999 = 4
7756 = 1
6855 = 3
9881 = 5
5531 = 0
2581 = ????
source: Can You Solve This Problem? « Motley News and Photos
Now, instead of solving this problem with logic, solve it with SAS.
Below is my dirty solution (hidden as white text):
data have;
array n[4];
array a[0:9] zero one two three four five six seven eight nine;
infile cards dlm='2c'x;
input (n1-n4 answer) (:) @@;
call pokelong( repeat(put(0,rb8.),9) , addrlong(a[0]) , 80 );
do x=1 to 4;
a[n
end;
drop x n1-n4;
cards;
8,8,0,9,6,7,1,1,1,0,2,1,7,2,0,6,6,6,6,4,1,1,1,1,0
3,2,1,3,0,7,6,6,2,2,9,3,1,3,1,0,0,0,0,4,2,2,2,2,0
3,3,3,3,0,5,5,5,5,0,8,1,9,3,3,8,0,9,6,5,7,7,7,7,0
9,9,9,9,4,7,7,5,6,1,6,8,5,5,3,9,8,8,1,5,5,5,3,1,0
2,5,8,1,.
;
run;
ods exclude all;
proc reg data=have;
model answer=zero--nine /noint selection=none;
output out=scores p=expected;
run;
ods exclude none;
proc print data=scores(firstobs=21) noobs label split='*';
var expected;
label expected='The Answer is*2581 = ';
run;
The Answer is
2581
=
2
I wrote my answer in white below
2
Count the number of loops in the digits. 0, 4, 6, 9 have one loop, 8 has two loops.
PG
Well, so much for that trick... Preview shows it all in black :smileylaugh:
I wrote my answer in white below
2
Count the number of loops in the digits. 0, 4, 6, 9 have one loop, 8 has two loops.
PG
Well, so much for that trick... Preview shows it all in black :smileylaugh:
PG, that's the correct logical solution but this is meant to be a programming exercise...
OK, here is a string based solution :
data _null_;
input dig $ @@;
s = lengthn(trimn(compress(tranwrd(translate(dig,"1 1 1 21","0123456789"),'2','11'))));
put dig "= " s;
datalines;
8809 7111 2172 6666 1111 3213 7662 9313 0000
2222 3333 5555 8913 8096 7777 9999 7756 6855
9881 5531 2581
;
PG
Or we could use REG to figure out the weights for the digits.
242 data puzzle;
243 input str $ @@;
244 score = lengthn(trimn(compress(tranwrd(translate(str,"1 1 1 21","0123456789"),'2','11'))));
245 if str='2581' then score=.;
246 array dig(0:9) dig0 - dig9 ;
247 do _n_=0 to 9; dig(_n_)=0; end;
248 do _n_=1 to 4; dig(input(substr(str,_n_,1),1.))+1; end;
249 datalines;
NOTE: SAS went to a new line when INPUT statement reached past the end of a line.
NOTE: The data set WORK.PUZZLE has 21 observations and 12 variables.
253 ;
254
255 proc reg noprint;
256 model score=dig0-dig9 / noint ;
257 output out=scores p=expected ;
258 run;
NOTE: The data set WORK.SCORES has 21 observations and 13 variables.
259 data _null_;
260 set scores;
261 if score=. then put str= expected= 2. ;
262 run;
str=2581 expected=2
NOTE: There were 21 observations read from the data set WORK.SCORES.
Quite nice idea Tom. But then you can't guess the weight that 4 would have, since none of the examples contains a 4.
PG
Hi FE,
Sorry, I looked at the clues.
data have;
input dig $ @@;
datalines;
8809 7111 2172 6666 1111 3213 7662 9313 0000
2222 3333 5555 8913 8096 7777 9999 7756 6855
9881 5531 2581
;
data want (keep=dig s);
set have;
ndig=translate(dig,"1000001021","0123456789");
array _n(*) a1-a4 ;
do i=1 to 4;
_n(i)=substr(ndig,i,1);
end;
s=sum(of _n(*));
run;
proc print;run;
The solutions posted all rely on logically solving the problem first, which is obviously good, but was not really my intention for the exercise.
I do not think you can presume anything for the value of 4 since it does not have training data and can easily break the logical rule depending on the font used to write it (http://www.enchantedlearning.com/books/howmany/4/0small.GIF).
Hi Fried, I think there was no alternative to solving the problem logically first. There is no way even a powerful algorithm could have covered all the possibilities offered by the imagination of preschoolers. The solution could have been related to a nursery rime, to cartoon characters, to ways of counting on your fingers, to the difference between consecutive digits, etc. The possibilities are endless. Assigning a value or a weight to each digit explores only a tiny fraction of the solution space. - PG
PG, I disagree. The problem states it is mathematically based and provides a series of training data. While the logical solution is to count the number of circles present in the numbers the riddle part is that you are told about toddlers and assume there is some sort of outside relationship as you describe. In my opinion the riddle presents a humerus problem solvable through a least squares analysis of the training data which took only a few minutes to write and run in SAS without any need to solve the problem logically beforehand.
Hi Fried, interesting discussion. What technique would identify the very simple mathematical rule behind the following training set :
8809 = 1
7111 = 0
2172 = 2
6666 = 0
1111 = 0
3213 = 2
7662 = 1
9313 = 0
0000 = 0
2222 = 0
3333 = 0
5555 = 0
8913 = 1
8096 = 2
7777 = 0
9999 = 0
7756 = 1
6855 = 1
9881 = 2
5531 = 0
2581 = 3
Now don't cheat and use logic or intuition !
PG
I'm with PG on this one. The SAS "solution" posted can only be written by somebody who's already guessed that f(x) might be a sum of individual digit scores. But at that point, they've already done 99% of the heavy lifting. Somebody who has that idea in mind doesn't even need SAS; it's easy enough to figure out the digit values and verify the results by eye.
You are absolutely correct Geoffrey, I came to that conclusion late last night while driving. Sorry for the confusion PG.
I doubt very much this problem, as presented, was solved by any pre-school child, unless they are in the Mensa pre-school.
The part about preschoolers is probably made up, it is simply a subtle way of giving the reader a very good clue. As a side effect, it might contribute to the frustration of those who can't find the answer. - PG
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.