Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #13090
| Newsgroups | comp.lang.forth |
|---|---|
| From | Albert van der Horst <albert@spenarnc.xs4all.nl> |
| Subject | Re: Euro's and Dollars. |
| Date | 2012-06-20 01:31 +0000 |
| Message-ID | <m5w6vt.2hd@spenarnc.xs4all.nl> (permalink) |
| Organization | Dutch Forth Workshop |
| References | <m5tu4r.9ba@spenarnc.xs4all.nl> <20120619092656.0d5cc45a@tiger.support.j.intershop.de> <m5vgd3.1kw@spenarnc.xs4all.nl> <4fe0bd9f$0$9525$9b4e6d93@newsspool1.arcor-online.net> |
In article <4fe0bd9f$0$9525$9b4e6d93@newsspool1.arcor-online.net>, A. K. <akk@nospam.org> wrote: >On 19.06.2012 17:58, Albert van der Horst wrote: >> In article <20120619092656.0d5cc45a@tiger.support.j.intershop.de>, >> Ecki <ecki@intershop.de> wrote: >>>> Someone said, CP is the most underestimated area in the software >>>> industry. >>> >>> For Prolog, it's IMHO somehow the missing part, as it allows one to >>> "semi-bind" a variable, in contrast to either have it bound or >>> full-free. That in turn heavily reduces the possible search tree for >>> many problems, making them solvable with much less effort or at all -- >>> think of how Sudoku is solved. >> >> The most natural way to solve a Sudoku is: >> for all unsolved squares find out how many possibilities it has. >> for all squares with 1 possibility fill it in >> repeat >> > >You are thinking algorithmically. But CP is data driven and requires a >fundamentally different mindset. > >F.ex. below is a _complete_ working plain vanilla straightforward >generic Sudoku solver in BProlog. Non-optimized. It contains _only_ >range and position information, and the rules of the game. Nothing else. > > >/* ########## >Sudoku solver >*/ > >:- initialization(main). > >main :- > >Vars = [ % the board >X11,X12,X13, X14,X15,X16, X17,X18,X19, >X21,X22,X23, X24,X25,X26, X27,X28,X29, >X31,X32,X33, X34,X35,X36, X37,X38,X39, > >X41,X42,X43, X44,X45,X46, X47,X48,X49, >X51,X52,X53, X54,X55,X56, X57,X58,X59, >X61,X62,X63, X64,X65,X66, X67,X68,X69, > >X71,X72,X73, X74,X75,X76, X77,X78,X79, >X81,X82,X83, X84,X85,X86, X87,X88,X89, >X91,X92,X93, X94,X95,X96, X97,X98,X99 ], >Vars :: 1..9, > >sudoku(Vars), % read in puzzle > >%row rules >alldifferent([X11,X12,X13, X14,X15,X16, X17,X18,X19]), >alldifferent([X21,X22,X23, X24,X25,X26, X27,X28,X29]), >alldifferent([X31,X32,X33, X34,X35,X36, X37,X38,X39]), >alldifferent([X41,X42,X43, X44,X45,X46, X47,X48,X49]), >alldifferent([X51,X52,X53, X54,X55,X56, X57,X58,X59]), >alldifferent([X61,X62,X63, X64,X65,X66, X67,X68,X69]), >alldifferent([X71,X72,X73, X74,X75,X76, X77,X78,X79]), >alldifferent([X81,X82,X83, X84,X85,X86, X87,X88,X89]), >alldifferent([X91,X92,X93, X94,X95,X96, X97,X98,X99]), > >%column rules >alldifferent([X11,X21,X31, X41,X51,X61, X71,X81,X91]), >alldifferent([X12,X22,X32, X42,X52,X62, X72,X82,X92]), >alldifferent([X13,X23,X33, X43,X53,X63, X73,X83,X93]), >alldifferent([X14,X24,X34, X44,X54,X64, X74,X84,X94]), >alldifferent([X15,X25,X35, X45,X55,X65, X75,X85,X95]), >alldifferent([X16,X26,X36, X46,X56,X66, X76,X86,X96]), >alldifferent([X17,X27,X37, X47,X57,X67, X77,X87,X97]), >alldifferent([X18,X28,X38, X48,X58,X68, X78,X88,X98]), >alldifferent([X19,X29,X39, X49,X59,X69, X79,X89,X99]), > >%block rules >alldifferent([X11,X12,X13, X21,X22,X23, X31,X32,X33]), >alldifferent([X14,X15,X16, X24,X25,X26, X34,X35,X36]), >alldifferent([X17,X18,X19, X27,X28,X29, X37,X38,X39]), >alldifferent([X41,X42,X43, X51,X52,X53, X61,X62,X63]), >alldifferent([X44,X45,X46, X54,X55,X56, X64,X65,X66]), >alldifferent([X47,X48,X49, X57,X58,X59, X67,X68,X69]), >alldifferent([X71,X72,X73, X81,X82,X83, X91,X92,X93]), >alldifferent([X74,X75,X76, X84,X85,X86, X94,X95,X96]), >alldifferent([X77,X78,X79, X87,X88,X89, X97,X98,X99]), > >labeling(Vars), % get solution >writeln(Vars). > >% ##################################################################### > >sudoku([ % Puzzle example >8,6,7, _,_,5, 9,1,_, >1,_,_, _,7,_, _,8,5, >_,3,_, _,_,_, _,_,_, > >_,_,_, 7,6,2, 1,_,_, >_,8,_, _,9,_, _,6,_, >_,_,2, 8,1,4, _,_,_, > >_,_,_, _,_,_, _,3,_, >9,1,_, _,3,_, _,_,6, >_,4,3, 1,_,_, 8,2,9 >]). > >% that's all folks > Of course, but Prolog was made for this kind of problems. From the procedural side I was impressed with Python. After I solved it for 3 by 3 by 3, I discovered that I could reuse the very same code for 4 by 4 by 4 with not much more then changing a few boundaries. Of course nobody expects your code as is is to be reusable for 4 by 4 by 4, but I even doubt you could come close to anything resembling reusable classes. Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Euro's and Dollars. Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-06-18 19:00 +0000
Re: Euro's and Dollars. "A. K." <akk@nospam.org> - 2012-06-18 23:18 +0200
Re: Euro's and Dollars. Mark Wills <markrobertwills@yahoo.co.uk> - 2012-06-19 00:20 -0700
Re: Euro's and Dollars. "Elizabeth D. Rather" <erather@forth.com> - 2012-06-18 21:51 -1000
Re: Euro's and Dollars. vandys@vsta.org - 2012-06-19 00:49 +0000
Re: Euro's and Dollars. Spam@ControlQ.com - 2012-06-18 21:43 -0400
Re: Euro's and Dollars. "A. K." <akk@nospam.org> - 2012-06-19 07:20 +0200
Re: Euro's and Dollars. Ecki <ecki@intershop.de> - 2012-06-19 09:26 +0200
Re: Euro's and Dollars. Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-06-19 15:58 +0000
Re: Euro's and Dollars. "A. K." <akk@nospam.org> - 2012-06-19 19:58 +0200
Re: Euro's and Dollars. Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-06-20 01:31 +0000
Re: Euro's and Dollars. "A. K." <akk@nospam.org> - 2012-06-20 07:15 +0200
Re: Euro's and Dollars. Ecki <ecki@intershop.de> - 2012-06-20 10:15 +0200
Re: Euro's and Dollars. anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-06-20 10:46 +0000
Re: Euro's and Dollars. Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-06-20 17:39 +0000
Re: Euro's and Dollars. anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-06-21 16:21 +0000
Re: Euro's and Dollars. Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-06-21 11:58 -0500
Re: Euro's and Dollars. anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-06-22 14:57 +0000
Re: Euro's and Dollars. Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-06-21 20:38 +0000
Re: Euro's and Dollars. vandys@vsta.org - 2012-06-19 15:49 +0000
Re: Euro's and Dollars. Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-06-19 15:43 +0000
Re: Euro's and Dollars. vandys@vsta.org - 2012-06-19 15:51 +0000
Re: Euro's and Dollars. Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-06-19 15:41 +0000
Re: Euro's and Dollars. Paul Rubin <no.email@nospam.invalid> - 2012-06-19 10:26 -0700
Re: Euro's and Dollars. Paul Rubin <no.email@nospam.invalid> - 2012-06-19 23:34 -0700
Re: Euro's and Dollars. Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-06-19 12:41 -0500
Re: Euro's and Dollars. Paul Rubin <no.email@nospam.invalid> - 2012-06-19 11:10 -0700
Re: Euro's and Dollars. Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-06-20 03:12 +0000
Re: Euro's and Dollars. Paul Rubin <no.email@nospam.invalid> - 2012-06-19 23:51 -0700
Re: Euro's and Dollars. Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-06-20 03:15 -0500
csiph-web