I haven't participated in this discussion, as yet, but unfortunately looked at it while I was waiting for another (long) program to finish running.
I think the part about preschoolers is important, as that limits their capabilities to just counting. As for any solution not assigning a value to 4, I think that is irrelevant as 4 has never been introduced into the problem.
The following, I think, mimics the way a preschooler might approach reaching a solution:
data have;
input n1-n4 answer;
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
;
run;
data eliminate (keep=e:);
array n[4];
array a[0:9] e0-e9;
retain a;
set have end=lastone;
if answer eq 0 then do;
do i=1 to 4;
if a(n(i)) in (.,0) then a(n(i))=0;
else a(n(i))=0;
end;
end;
if lastone then do;
do i=0 to 9;
if a(i) ne 0 then a(i)=1;
end;
output;
end;
run;
data test1;
if _n_ eq 1 then set eliminate;
set have;
array n[4];
array a[0:9] e0-e9;
array recode[4] r1-r4;
do i=1 to 4;
recode(i)=a(n(i));
if recode(i) eq 0 then n(i)=0;
end;
test=sum(of recode(*));
if test ne answer then output;
run;
data commonalities (keep=c:);
set test1 (keep=n:) end=lastone;
array common(0:9) c0-c9;
array n(4);
do i=0 to 9;
if i in n then common(i)+1;
end;
if lastone then do;
do i=0 to 9;
if common(i) ne _n_ then common(i)=0;
else common(i)=1;
end;
output;
end;
run;
data test2;
if _n_ eq 1 then do;
set commonalities;
set eliminate;
end;
set have;
array n[4];
array e[0:9] e0-e9;
array c(0:9) c0-c9;
array t(0:9) t0-t9;
array recode[4] r1-r4;
do i=1 to 4;
recode(i)=e(n(i));
end;
do i=0 to 9;
if c(i) then do;
do j=0 to 9;
if i eq j then t(j)=2;
else t(j)=e(j);
end;
do k=1 to 4;
recode(k)=t(n(k));
end;
_test=sum(of recode(*));
if _test eq answer then _true=1;
else _true=0;
output;
end;
end;
run;
proc sort data=test2;
by i;
run;
data test2 (keep=t:);
set test2;
by i;
if first.i then do;
_total=0;
recs=0;
end;
_total+_true;
recs+1;
if last.i then do;
if _total=recs then output;
end;
run;
data answer;
input n1-n4;
if _n_ eq 1 then set test2;
array n[4];
array t(0:9) t0-t9;
array recode[4] r1-r4;
do i=1 to 4;
recode(i)=t(n(i));
end;
answer=sum(of recode(*));
cards;
2 5 8 1
;
run;
Hi Art,
Very impressive! How long does it take you to come up the code?
Linlin: About an hour. It wasn't meant to be impressive, just an attempt to code what may or may not really be a child's thought process. I didn't bother to expand the code to account for additional complexities like what to do if the solution called for point values beyond 0, 1 and 2, as the solution was reached with just considering those possibilities and I don't have ANY plans for putting the code into "production".
You psychologists... Nice work Art. This is the spirit by which I meant to post the question to receive. I suppose I explained that poorly. I've been on the road for the past 2 weeks, 55 hours behind the wheel so far. Under 10 hours left.
In second grade we played a flash card game called around the world. One student would stand up and walk around to each classmate and both would be standing as the teacher raises a flash card with an equation on it. the first person to say the correct answer wins. The winner goes to the next student until they lose. I never lost and I was banned from the game for the rest of the year. Anyway moral of the story is that kids can do simple math extremely fast. You take longer when older because you have a wider range of explanations as to why it can equal those answers. So I fail to see the point in making this a programming exercise unless you are using Python which helps when using Action Script. other than that umm the preschooler comment is probably mostly trying to tell you which operations to use when figuring this out. preschoolers only know + and - think about it. Not even close to being farfetched that a kid could solve that problem faster than you.
Theres a reason why kids can solve this in less than 5 minutes. I did it in 30 seconds. I dont know how any of you were taught to logically solve problems early but I defnitely saw something like this on IQ tests. This is simply about pattern recognition. The reason why young kids can get this so fast is because its one of the only few forms of math they know at that age.
From this list you can automatically determine that every digit has a place value like binary but this would be something else..im having a brainfart at the moment. Anyway so you can already take all the numbers that equal 0 and assign them all values of 0. So now we have 1=0 2=0 3=0 5=0 7=0 and now we can take another number and figure out its value. so let me try to type it out properly with the value above the number. Keep in mind our goal is to figure out 2851.
right now we have 0+0+?+0=?
2 5 8 1=?
Now we see that 0000=4 and 9999=4 so we can say that 0 and 9=1 Now our list looks as follows:
0=1
1=0
2=0
3=0
4=?
5=0
6=?
7=0
8=?
9=1
So now we only need 8's value to solve this problem.
8193=3 now expand it. ?+0+1+0=3 8=2 Im sorry but im not going to white this out. if people are smart enough theyd already know the answer before coming here
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.