Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Fwd: New Scientist Puzzle]

3 views
Skip to first unread message

Richard.Suchenwirth

unread,
Mar 1, 2001, 1:13:14 PM3/1/01
to
He sent it to a number of language groups. I think Tcl'ers could also be
interested...
--
Schoene Gruesse/best regards, Richard Suchenwirth - +49-7531-86 2703
RC DT2, Siemens ElectroCom, Buecklestr.1-5, D-78467 Konstanz,Germany
Personal opinions expressed only unless explicitly stated otherwise.

Donal K. Fellows

unread,
Mar 2, 2001, 5:33:59 AM3/2/01
to
"Richard.Suchenwirth" forwarded:
> This puzzle was originally posted on a mailing list for the Icon
> programming language. Thought members of this group might also
> want to give it a shot.
>
> VIER and NEUN represent 4-digit squares, each letter denoting a
> distinct digit. You are asked to find the value of each, given the
> further requirement that each uniquely determines the other.
>
> The "further requirement" means that of the numerous pairs of
> answers, choose the one in which each number only appears once
> in all of the pairs.

The problem is pretty easy to solve with a little software help to
generate lists of 4-digit squares that match the letter patterns. In
particular, NEUN is quite distinctive and is only matched by 5 different
squares. From there, it is pretty trivial to spot the answer (it took
me a couple of minutes with pen and paper) so much so that the effort of
developing a script to solve the whole problem automatically is probably
quite a bit greater...

Donal.
--
"While this is anecdotal, and thus bound to be ignored by all the pedanticism-
fascists out there, I have owned a fully-loaded copy of Emacs and many other
gnutilities for many years, and have never had a fatality yet."
-- Alistair J. R. Young <avatar...@arkane.demon.co.uk>

Phil Ehrens

unread,
Mar 2, 2001, 7:13:42 PM3/2/01
to
Pen and paper indeed...

It took me but a few seconds using a ouija board improvised from
an old playbill and a telegraph insulator (which I found on the way
to work this morning).

Vince Thomas

unread,
Mar 5, 2001, 10:51:43 PM3/5/01
to

"Donal K. Fellows" wrote:

>
> The problem is pretty easy to solve with a little software help to
> generate lists of 4-digit squares that match the letter patterns. In
> particular, NEUN is quite distinctive and is only matched by 5 different
> squares. From there, it is pretty trivial to spot the answer (it took
> me a couple of minutes with pen and paper) so much so that the effort of
> developing a script to solve the whole problem automatically is probably
> quite a bit greater...

I don't think it's about whether it is quicker to use a computer or do it in your
it in your head. It's about how easy is it to express the problem in a programming
language. Much as I love Tcl this seemed to me to be a natural fit for matrix
arithmetic so I used APL. I've change the syntax a bit because the apl characters
won't display. The idea is to form the outer product of NEUNVIER with itself using
the equal operator (ø.=) which gives a matrix
MB
1 0 0 1 0 0 0 0
0 1 0 0 0 0 1 0
0 0 1 0 0 0 0 0
1 0 0 1 0 0 0 0
0 0 0 0 1 0 0 0
0 0 0 0 0 1 0 0
0 1 0 0 0 0 1 0
0 0 0 0 0 0 0 1

I do the same with the candidate squares and if the matrix is the same I've solved
it.
("^/ " reduces along a dimension so that applying it twice reduces the two
dimensions down to a scalar 1 if all components are equal and 0 otherwise. FORMAT
converts the number to a character vector. The rest is APL's aging control
structures)

Z:= L FINDSQ R
n:=32
M:=Rø.=R
MB:=(R,L)ø.=R,L
LOOP:GOTO(0=^/^/M=outerSquareø.=outerSquare:=FORMAT n*2)/NEXT
m:=32
ILOOP:GOTO(^/^/MB=bothø.=both:=outerSquare,FORMAT m*2)/END
GOTO (100>m:=m+1)/ILOOP
NEXT: GOTO (100>n:=n+1)/LOOP
END:Z:=n,m,both

used as,
'VIER' FINDSQ 'NEUN'
gives,
39 66 15214356


Donal K. Fellows

unread,
Mar 6, 2001, 4:39:50 AM3/6/01
to
Vince Thomas wrote:
> I don't think it's about whether it is quicker to use a computer or do it
> in your it in your head. It's about how easy is it to express the problem
> in a programming language. Much as I love Tcl this seemed to me to be a
> natural fit for matrix arithmetic so I used APL. I've change the syntax a
> bit because the apl characters won't display. The idea is to form the outer
> product of NEUNVIER with itself using the equal operator (ø.=) which gives
> a matrix
[...]

> I do the same with the candidate squares and if the matrix is the same I've
> solved it.
> ("^/ " reduces along a dimension so that applying it twice reduces the two
> dimensions down to a scalar 1 if all components are equal and 0 otherwise.
> FORMAT converts the number to a character vector. The rest is APL's aging
> control structures)
[...]
> 39 66 15214356

Assuming that you mean 39 to be the square root of NEUN and 66 to be the
square root of VIER, your answer is wrong since you can substitute 84
for 66 and still get a solution with 39. There are multiple pairs that
match VIER and NEUN, but only one such that each uniquely determines the
other.

Donal.
--
Donal K. Fellows http://www.cs.man.ac.uk/~fellowsd/ fell...@cs.man.ac.uk
-- With a complex beast like Swing, it's not just a matter of "What button
should I push", but rather "How do I put myself into a nice metamorphosis
so that I am deemed acceptable by the Swing Gods." -- Anonymous

Steve Graham

unread,
Mar 7, 2001, 12:19:35 AM3/7/01
to
The correct answer is 6241,9409


Phil Ehrens

unread,
Mar 7, 2001, 1:47:21 PM3/7/01
to
Eh? Richard?

Richard.Suchenwirth

unread,
Mar 7, 2001, 2:04:18 PM3/7/01
to

If you mean my earlier life as Tcl-URL! editor, I'm not on duty (looks
like nobody is, this week). But I always though the correct answer was
42...

Tom Wilkason

unread,
Mar 7, 2001, 2:21:14 PM3/7/01
to
"Richard.Suchenwirth" <richard.s...@kst.siemens.de> wrote in message
news:3AA68632...@kst.siemens.de...
<snip>

| But I always though the correct answer was
| 42...

Me too...what was the question?

Tom

Kevin Kenny

unread,
Mar 7, 2001, 3:42:38 PM3/7/01
to
Steve Graham wrote (via Richard Suchenwirth):

> This puzzle was originally posted on a mailing list for the Icon
> programming language. Thought members of this group might also
> want to give it a shot.
>
> VIER and NEUN represent 4-digit squares, each letter denoting a
> distinct digit. You are asked to find the value of each, given the
> further requirement that each uniquely determines the other.
>
> The "further requirement" means that of the numerous pairs of
> answers, choose the one in which each number only appears once
> in all of the pairs.

(I waited to post this so as not to spoil the puzzle for others.)

The real puzzle here is, "express the stated problem in Tcl," rather than
"come up with the two target numbers." One solution:

proc solve {} {

# Step 1. List all the squares that have the digit pattern NEUN.
# Group them by the digit E.

for { set i 0 } { $i <= 9 } { incr i } {
set neun_values($i) {}
}
for { set sqrt_neun 32 } { $sqrt_neun <= 99 } { incr sqrt_neun } {
set neun [expr { $sqrt_neun * $sqrt_neun }]
foreach { N E U N2 } [split $neun {}] break
if { [string equal $N $N2] } {
lappend neun_values($E) $neun
}
}

# Step 2. List all the squares that have the pattern VIER for
# some value of NEUN. Cast out any for which there
# are duplicates among the digits V, I, E, R, N and U

for { set sqrt_vier 32 } { $sqrt_vier <= 99 } { incr sqrt_vier } {
set vier [expr { $sqrt_vier * $sqrt_vier }]
foreach { V I E R } [split $vier {}] break
foreach neun $neun_values($E) {
foreach { N E2 U N2 } [split $neun {}] break
foreach letter [list $V $I $E $R $N $U] {
if { [info exists have($letter)] } {
set duplicate {}
break
}
set have($letter) {}
}
unset have
if { ![info exists duplicate] } {
lappend pairs $vier $neun
}
catch { unset duplicate }
}
}

# Step 3. Count up the number of times each number appears in
# a pair

foreach { vier neun } $pairs {
if { [info exists vier_count($vier)] } {
incr vier_count($vier)
} else {
set vier_count($vier) 1
}
if { [info exists neun_count($neun)] } {
incr neun_count($neun)
} else {
set neun_count($neun) 1
}
}

# Step 4. Determine which pairs have each number uniquely determining
# the other

foreach { vier neun } $pairs {
if { $vier_count($vier) == 1 && $neun_count($neun) == 1 } {
lappend answer VIER $vier NEUN $neun
}
}

return $answer

}

array set answer [solve]
parray answer


--
73 de ke9tv/2, Kevin KENNY GE Corporate R&D, Niskayuna, New York, USA

Steve Graham

unread,
Mar 7, 2001, 7:59:02 PM3/7/01
to
Thanks, Kevin.


Steve Graham
===
"Kevin Kenny" <ken...@crd.ge.com> wrote in message
news:3AA69D3E...@crd.ge.com...

stillThinking

unread,
Mar 8, 2001, 6:14:34 AM3/8/01
to
Hi everyone!

Is there a *single* unique pair?
I found the following 2 solutions.
(maybe I did not understand the original question, anyway)

n=97 v=79, 9409 6241, N=9 E=4 U=0 V=6 I=2 R=1
n=41 v=87, 1681 7569, N=1 E=6 U=8 V=7 I=5 R=9

My code (sorry, its Perl, but I love Tcl too ;-)

for $n (32..99) {
$nn = $n*$n;
for $v (32..99) {
$vv = $v*$v;
$nnvv = $nn.$vv;
%m = map {($_,'x')} split(//,$nnvv);
print "n=$n v=$v, $nn $vv, N=$1 E=$2 U=$3 V=$4 I=$5 R=$6" if keys %m == 6 && ($nnvv) =~ /(.)(.)(.)\1(.)(.)\2(.)/;
}
}

_______________________________________________
Submitted via WebNewsReader of http://www.interbulletin.com

Donal K. Fellows

unread,
Mar 8, 2001, 8:07:29 AM3/8/01
to
stillThinking wrote:
> n=41 v=87, 1681 7569, N=1 E=6 U=8 V=7 I=5 R=9

This is not a solution because it fails the "each uniquely determines
the other" test, since 7569 can also match 4624. :^)

-- There are worse futures that burning in hell. Imagine aeons filled with
rewriting of your apps as WinN**X API will change through eternity...
-- Alexander Nosenko <n...@titul.ru>

Donal K. Fellows

unread,
Mar 8, 2001, 8:09:02 AM3/8/01
to
Tom Wilkason wrote:

> "Richard.Suchenwirth" <richard.s...@kst.siemens.de> wrote:
>| But I always though the correct answer was 42...
>
> Me too...what was the question?

"What do you get when you multiply six by nine?"

Frederic BONNET

unread,
Mar 8, 2001, 9:28:57 AM3/8/01
to

"Donal K. Fellows" wrote:
>
> Tom Wilkason wrote:
> > "Richard.Suchenwirth" <richard.s...@kst.siemens.de> wrote:
> >| But I always though the correct answer was 42...
> >
> > Me too...what was the question?
>
> "What do you get when you multiply six by nine?"

54

--
Frédéric BONNET frederi...@free.fr
---------------------------------------------------------------
"Theory may inform, but Practice convinces"
George Bain

Dan Smart

unread,
Mar 11, 2001, 11:43:16 AM3/11/01
to
Frederic BONNET <frederi...@free.fr> wrote in
<3AA795B2...@free.fr>:

>"Donal K. Fellows" wrote:
>>
>> Tom Wilkason wrote:
>> > "Richard.Suchenwirth" <richard.s...@kst.siemens.de> wrote:
>> >| But I always though the correct answer was 42...
>> >
>> > Me too...what was the question?
>>
>> "What do you get when you multiply six by nine?"
>
>54
>

Which is 42 base 13.

--
Dan Smart. C++ Programming and Mentoring.
cpp...@dansmart.com

Donal K. Fellows

unread,
Mar 12, 2001, 6:21:46 AM3/12/01
to
Dan Smart wrote:

> Frederic BONNET <frederi...@free.fr> wrote:
>>"Donal K. Fellows" wrote:
>>> Tom Wilkason wrote:
>>>> "Richard.Suchenwirth" <richard.s...@kst.siemens.de> wrote:
>>>>| But I always though the correct answer was 42...
>>>> Me too...what was the question?
>>> "What do you get when you multiply six by nine?"
>> 54
> Which is 42 base 13.

*sigh*

Larry Smith

unread,
Mar 12, 2001, 2:07:29 PM3/12/01
to
Dan Smart wrote:
>
> Frederic BONNET <frederi...@free.fr> wrote in
> <3AA795B2...@free.fr>:
>
> >"Donal K. Fellows" wrote:
> >>
> >> Tom Wilkason wrote:
> >> > "Richard.Suchenwirth" <richard.s...@kst.siemens.de> wrote:
> >> >| But I always though the correct answer was 42...
> >> >
> >> > Me too...what was the question?
> >>
> >> "What do you get when you multiply six by nine?"
> >
> >54
> >
>
> Which is 42 base 13.

Ooooooooooooooooh! NICE recovery, Dan! =)

--
.-. .-. .---. .---. .-..-. | Do not mistake my cynicism
| |__ / | \| |-< | |-< > / | for dispair for deep inside
`----'`-^-'`-'`-'`-'`-' `-' | me is an optimist forever
http://www.smith-house.org/ | asking, "Why not?"

Dan Smart

unread,
Mar 12, 2001, 8:23:36 PM3/12/01
to
Larry Smith <la...@smith-house.org> wrote in <3AAD1E71.42AB5A2E@smith-
house.org>:

>Dan Smart wrote:
>> Frederic BONNET <frederi...@free.fr> wrote in
>> <3AA795B2...@free.fr>:
>> >"Arthur Dent" wrote:
>> >> Tom Wilkason wrote:
>> >> > "Richard.Suchenwirth" <richard.s...@kst.siemens.de> wrote:
>> >> >| But I always though the correct answer was 42...
>> >> > Me too...what was the question?
>> >> "What do you get when you multiply six by nine?"
>> >54
>> Which is 42 base 13.
>Ooooooooooooooooh! NICE recovery, Dan! =)

Not really, it's Hitch Hikers Guide to the Galaxy Trivia, which is why
Donal "Arthur Dent" Fellows sighed.

Dan "Ford Prefect" Smart

Donal K. Fellows

unread,
Mar 13, 2001, 8:55:20 AM3/13/01
to
Dan Smart wrote:
> Not really, it's Hitch Hikers Guide to the Galaxy Trivia, which is why
> Donal "Arthur Dent" Fellows sighed.
>
> Dan "Ford Prefect" Smart

:^) Exactly. I can remember seeing this all blugeoned to death online
back in 1992, and if we are going to insist on retracing those steps
again, I should point out [format %c 42] now.

"IRONY. Made of iron. Suitable for beating people over the head with online."

"I wouldn't just call you wrong. I'd go further and call you an argumentative
net-kook idiot who can't do his own research before opening his mouth and
yammering bullshit." -- Theo de Raadt <der...@zeus.theos.com>

0 new messages