# Copyright (C) 2008 Toby Thain, toby@telegraphics.com.au
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# Print the solution to VIER NEUN puzzle.
# See: http://groups.google.com/group/comp.lang.tcl/msg/8846d9f7491ba0ba
procedure main()
sq := []
every put(sq, string( (32 to 99)^2 )) # build list of 4-digit squares
c := table(0)
res := []
every v := !sq & n := !sq do # generate all pairings (Cartesian product)
if v[3]=n[2] & n[1]=n[4] & *cset(v||n)=6 then { # test against pattern
every c[v|n] +:= 1 # count occurrences of left and right squares
put(res, [v,n]) # store this solution
}
every r := !res do
if 1 = c[r[1]] = c[r[2]] then # print only solutions where
write(r[1], " ", r[2]) # each half appears only once
end