Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

Nature always sides with the hidden flaw.


devel / comp.lang.forth / Re: new version of magic hexagon program

SubjectAuthor
* new version of magic hexagon programAhmed MELAHI
+* Re: new version of magic hexagon programMarcel Hendrix
|+* Re: new version of magic hexagon programAhmed MELAHI
||`* Re: new version of magic hexagon programAhmed MELAHI
|| `- Re: new version of magic hexagon programAhmed MELAHI
|`* Re: new version of magic hexagon programnone
| `* Re: new version of magic hexagon programMarcel Hendrix
|  `* Re: new version of magic hexagon programminforth
|   `* Re: new version of magic hexagon programAhmed MELAHI
|    +* Re: new version of magic hexagon programMarcel Hendrix
|    |`- Re: new version of magic hexagon programAhmed MELAHI
|    `* Re: new version of magic hexagon programminforth
|     `* Re: new version of magic hexagon programMarcel Hendrix
|      +* Re: new version of magic hexagon programAhmed MELAHI
|      |+- Re: new version of magic hexagon programMarcel Hendrix
|      |`* Re: new version of magic hexagon programminforth
|      | +- Re: new version of magic hexagon programAhmed MELAHI
|      | `- Re: new version of magic hexagon programAhmed MELAHI
|      `- Re: new version of magic hexagon programAnton Ertl
+* Re: new version of magic hexagon programnone
|`- Re: new version of magic hexagon programAhmed MELAHI
`* Re: new version of magic hexagon programnone
 `- Re: new version of magic hexagon programAhmed MELAHI

1
new version of magic hexagon program

<3b96660a-56e6-4a84-ac82-2758fe6b9d06n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24620&group=comp.lang.forth#24620

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:620a:25c:b0:76d:bea6:7ec1 with SMTP id q28-20020a05620a025c00b0076dbea67ec1mr4948qkn.12.1695144916715;
Tue, 19 Sep 2023 10:35:16 -0700 (PDT)
X-Received: by 2002:a4a:2c56:0:b0:578:d87a:7d30 with SMTP id
o83-20020a4a2c56000000b00578d87a7d30mr97425ooo.0.1695144916464; Tue, 19 Sep
2023 10:35:16 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!border-2.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Tue, 19 Sep 2023 10:35:16 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=154.121.48.209; posting-account=KJSw4AoAAACRkUCek5r_78mFj6sHzH4C
NNTP-Posting-Host: 154.121.48.209
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <3b96660a-56e6-4a84-ac82-2758fe6b9d06n@googlegroups.com>
Subject: new version of magic hexagon program
From: ahmed.melahi@univ-bejaia.dz (Ahmed MELAHI)
Injection-Date: Tue, 19 Sep 2023 17:35:16 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 89
 by: Ahmed MELAHI - Tue, 19 Sep 2023 17:35 UTC

Hi,
I rewrote the program for the magic hexagon.
It appears elegant without any loss of performance. I think it is faster than the last versions I have already posted.

Here begin the program:

\ Place the integers 1..19 in the following Magic Hexagon of rank 3
\ __A_B_C__
\ _D_E_F_G_
\ H_I_J_K_L
\ _M_N_O_P_
\ __Q_R_S__
\ so that the sum of all numbers in a straight line (horizontal and diagonal)
\ is equal to 38.

: values 0 ?do 0 value loop ;
19 values vA vB vC vD vE vF vG vH vI vJ vK vL vM vN vO vP vQ vR vS

create marking_table 77 allot
marking_table 77 1 fill

marking_table 38 + value marked
marked 20 erase

: -- 2 .r 2 spaces ;
: .mag_hex
cr
cr
4 spaces vA -- vB -- vC -- cr
2 spaces vD -- vE -- vF -- vG -- cr
vH -- vI -- vJ -- vK -- vL -- cr
2 spaces vM -- vN -- vO -- vP -- cr
4 spaces vQ -- vR -- vS --
cr
;

0 value nloops_prec
0 value nloops
0 value constraint_num
20 value max_num_constraints
create loop_loc max_num_constraints allot
loop_loc max_num_constraints erase
: mark 1 swap marked + c! ;
: unmark 0 swap marked + c! ;
: marked? marked + c@ 0= ;

: .-- nloops 1+ to nloops postpone do postpone i ; immediate
: ?, postpone dup postpone marked? postpone if postpone mark ; immediate
: --> postpone to constraint_num 1+ to constraint_num nloops nloops_prec <> if 1 loop_loc constraint_num + c! nloops to nloops_prec then ; immediate
: constraints_begin( marked 20 erase ;
: finish: nloops 0 do postpone unloop loop postpone exit ; immediate
: --- ; immediate
: _begin_ marked 20 erase ;
: | postpone unmark postpone else postpone drop postpone then loop_loc constraint_num + c@ if postpone loop then constraint_num 1- to constraint_num ; immediate
: _end_ ; immediate

: solve
_begin_
20 1 .-- --> vA vA ?,
20 1 .-- --> vB vB ?,
38 vA vB + - --- --> vC vC ?,
20 1 .-- --> vG vG ?,
38 vC vG + - --- --> vL vL ?,
20 1 .-- --> vP vP ?,
38 vL vP + - --- --> vS vS ?,
20 1 .-- --> vR vR ?,
38 vS vR + - --- --> vQ vQ ?,
20 1 .-- --> vM vM ?,
38 vQ vM + - --- --> vH vH ?,
38 vA vH + - --- --> vD vD ?,
20 1 .-- --> vE vE ?,
38 vD vE + vG + - --- --> vF vF ?,
38 vB vF + vP + - --- --> vK vK ?,
38 vG vK + vR + - --- --> vO vO ?,
38 vP vO + vM + - --- --> vN vN ?,
38 vR vN + vD + - --- --> vI vI ?,
38 vH vI + vK + vL + - --- --> vJ vJ ?,

finish: vJ | vI | vN | vO | vK | vF | vE | vD | vH | vM | vQ | vR | vS | vP | vL | vG | vC | vB | vA |
_end_
;

Tested with: gforth, vfxforth anf iforth v4 (evaluation) on my PC:
gforth: 4.5 ms
vfxforth: 0.734 ms
iforth: 0.976 ms

Enjoy

Re: new version of magic hexagon program

<ed0dfb07-3b15-431d-a9d1-b3ed28f6d096n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24621&group=comp.lang.forth#24621

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:ac8:7e86:0:b0:417:b545:175b with SMTP id w6-20020ac87e86000000b00417b545175bmr6710qtj.3.1695150069579;
Tue, 19 Sep 2023 12:01:09 -0700 (PDT)
X-Received: by 2002:a05:6830:1292:b0:6bd:749:f5cf with SMTP id
z18-20020a056830129200b006bd0749f5cfmr144511otp.5.1695150069324; Tue, 19 Sep
2023 12:01:09 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!border-2.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Tue, 19 Sep 2023 12:01:08 -0700 (PDT)
In-Reply-To: <3b96660a-56e6-4a84-ac82-2758fe6b9d06n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2001:1c05:2f18:6d00:d00f:a4fe:2d77:3bb2;
posting-account=-JQ2RQoAAAB6B5tcBTSdvOqrD1HpT_Rk
NNTP-Posting-Host: 2001:1c05:2f18:6d00:d00f:a4fe:2d77:3bb2
References: <3b96660a-56e6-4a84-ac82-2758fe6b9d06n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <ed0dfb07-3b15-431d-a9d1-b3ed28f6d096n@googlegroups.com>
Subject: Re: new version of magic hexagon program
From: mhx@iae.nl (Marcel Hendrix)
Injection-Date: Tue, 19 Sep 2023 19:01:09 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 40
 by: Marcel Hendrix - Tue, 19 Sep 2023 19:01 UTC

On Tuesday, September 19, 2023 at 7:35:18 PM UTC+2, Ahmed MELAHI wrote:
> Hi,
> I rewrote the program for the magic hexagon.
> It appears elegant without any loss of performance. I think it is faster than the last versions I have already posted.
[..]
> Tested with: gforth, vfxforth anf iforth v4 (evaluation) on my PC:
> gforth: 4.5 ms
> vfxforth: 0.734 ms
> iforth: 0.976 ms

No idea how you timed that. I get 224 us with this:

: INIT marking_table #77 1 fill
marked #20 ERASE
loop_loc max_num_constraints ERASE ;

: TEST INIT
.mag_hex
CR DTICKS-RESET [TICKS solve TICKS] D-US? .USECS ." elapsed."
.mag_hex ;

FORTH> TEST

0 0 0
0 0 0 0
0 0 0 0 0
0 0 0 0
0 0 0

240 us elapsed.

3 17 18
19 7 1 11
16 2 5 6 9
12 4 8 14
10 13 15
ok

-marcel

Re: new version of magic hexagon program

<11a0b66c-d991-4207-aca8-a321f2825f99n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24622&group=comp.lang.forth#24622

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:620a:3846:b0:76d:b19e:aa21 with SMTP id po6-20020a05620a384600b0076db19eaa21mr8674qkn.13.1695154475499;
Tue, 19 Sep 2023 13:14:35 -0700 (PDT)
X-Received: by 2002:a05:6830:4c8:b0:6ab:8d3:5209 with SMTP id
s8-20020a05683004c800b006ab08d35209mr195861otd.5.1695154475141; Tue, 19 Sep
2023 13:14:35 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!3.us.feeder.erje.net!feeder.erje.net!border-1.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Tue, 19 Sep 2023 13:14:34 -0700 (PDT)
In-Reply-To: <ed0dfb07-3b15-431d-a9d1-b3ed28f6d096n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=154.121.48.209; posting-account=KJSw4AoAAACRkUCek5r_78mFj6sHzH4C
NNTP-Posting-Host: 154.121.48.209
References: <3b96660a-56e6-4a84-ac82-2758fe6b9d06n@googlegroups.com> <ed0dfb07-3b15-431d-a9d1-b3ed28f6d096n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <11a0b66c-d991-4207-aca8-a321f2825f99n@googlegroups.com>
Subject: Re: new version of magic hexagon program
From: ahmed.melahi@univ-bejaia.dz (Ahmed MELAHI)
Injection-Date: Tue, 19 Sep 2023 20:14:35 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 156
 by: Ahmed MELAHI - Tue, 19 Sep 2023 20:14 UTC

Le mardi 19 septembre 2023 à 19:01:11 UTC, Marcel Hendrix a écrit :
> On Tuesday, September 19, 2023 at 7:35:18 PM UTC+2, Ahmed MELAHI wrote:
> > Hi,
> > I rewrote the program for the magic hexagon.
> > It appears elegant without any loss of performance. I think it is faster than the last versions I have already posted.
> [..]
> > Tested with: gforth, vfxforth anf iforth v4 (evaluation) on my PC:
> > gforth: 4.5 ms
> > vfxforth: 0.734 ms
> > iforth: 0.976 ms
> No idea how you timed that. I get 224 us with this:
>
> : INIT marking_table #77 1 fill
> marked #20 ERASE
> loop_loc max_num_constraints ERASE ;
>
> : TEST INIT
> .mag_hex
> CR DTICKS-RESET [TICKS solve TICKS] D-US? .USECS ." elapsed."
> .mag_hex ;
>
> FORTH> TEST
>
> 0 0 0
> 0 0 0 0
> 0 0 0 0 0
> 0 0 0 0
> 0 0 0
>
> 240 us elapsed.
>
> 3 17 18
> 19 7 1 11
> 16 2 5 6 9
> 12 4 8 14
> 10 13 15
> ok
>
> -marcel

for the timing I used
: timing_1000 timer-reset 1000 0 do solve loop .elapsed ;
I don't know if it is good or no.
Perhaps my PC is slow (PC portable lenovo ideapad330, Intel(R) Celeron(R) CPU 3867U @ 1.80GHz 1.80 GHz, RAM 12 GB).

My objective was to keep the performance of the previous program and simplify the presentation of the problem of the puzzle (in the word solve) and reduce the size of the program (to about 70 loc).
Here we can separate the puzzle itself from the tools (clp???) at the begining of the program.

Here, I did that ( I rewrote the program) and got:

\ tools: clp??? ---------------part----------
100 value marking_table_size_max
create marking_table marking_table_size_max allot
marking_table marking_table_size_max 1 fill

0 value vals_num
20 value vals_num_max
marking_table marking_table_size_max 2 / + value marked
marked vals_num_max erase

0 value nloops_prec
0 value nloops
0 value constraint_num
20 value max_num_constraints
create loop_loc max_num_constraints allot
loop_loc max_num_constraints erase
: mark 1 swap marked + c! ;
: unmark 0 swap marked + c! ;
: marked? marked + c@ 0= ;

: .-- nloops 1+ to nloops postpone do postpone i ; immediate
: ?, postpone dup postpone marked? postpone if postpone mark ; immediate
: --> postpone to constraint_num 1+ to constraint_num nloops nloops_prec <> if 1 loop_loc constraint_num + c! nloops to nloops_prec then ; immediate
: finish| nloops 0 do postpone unloop loop postpone exit ; immediate
: --- ; immediate
: _begin_ marked vals_num erase ;
: | postpone unmark postpone else postpone drop postpone then loop_loc constraint_num + c@ if postpone loop then constraint_num 1- to constraint_num ; immediate
: _end_ ; immediate

: values dup 1+ to vals_num 0 ?do 0 value loop ;

\ puzzle: magic hexagon puzzle ----part------
19 values vA vB vC vD vE vF vG vH vI vJ vK vL vM vN vO vP vQ vR vS

: -- 2 .r 2 spaces ;
: .mag_hex
cr
cr
4 spaces vA -- vB -- vC -- cr
2 spaces vD -- vE -- vF -- vG -- cr
vH -- vI -- vJ -- vK -- vL -- cr
2 spaces vM -- vN -- vO -- vP -- cr
4 spaces vQ -- vR -- vS --
cr
;

: solve
_begin_
20 1 .-- --> vA vA ?,
20 1 .-- --> vB vB ?,
38 vA vB + - --- --> vC vC ?,
20 1 .-- --> vG vG ?,
38 vC vG + - --- --> vL vL ?,
20 1 .-- --> vP vP ?,
38 vL vP + - --- --> vS vS ?,
20 1 .-- --> vR vR ?,
38 vS vR + - --- --> vQ vQ ?,
20 1 .-- --> vM vM ?,
38 vQ vM + - --- --> vH vH ?,
38 vA vH + - --- --> vD vD ?,
20 1 .-- --> vE vE ?,
38 vD vE + vG + - --- --> vF vF ?,
38 vB vF + vP + - --- --> vK vK ?,
38 vG vK + vR + - --- --> vO vO ?,
38 vP vO + vM + - --- --> vN vN ?,
38 vR vN + vD + - --- --> vI vI ?,
38 vH vI + vK + vL + - --- --> vJ vJ ?,

finish| vJ | vI | vN | vO | vK | vF | vE | vD | vH | vM | vQ | vR | vS | vP | vL | vG | vC | vB | vA |
_end_
;

For example:
20 1 .-- --- ---> vA vA ?, is read like this: let vA between 1 and 19, is it acceptable? if yes continue with the others else change vA (backtrack???).
38 vA vB + - --- ---> vC vC ?, is read like this: calculate vC using the formula just before (the constraint), is it acceptable? if yes continue with the others else (backtrack???) (in fact I am not sure if this is backtracking).
When all vA, ..., vJ are accepted (solution found), the word finish| terminates the execution of the word solve.

for the timing, I use:
: timing_1000 timer-reset 1000 0 do solve loop .elapsed ;

for the moment I don't know if I can use the tools (at the begining) to solve other problems (puzzles) like: magic squares, sendmoremoney etc...
If so, one can save the first part (tools clp???) in a program named clp.fs for example.
This program will be included in the program where the problem (puzzle) iself will be programmed.
I did it, it works.
Bye

Re: new version of magic hexagon program

<nnd$08d3555d$3b44d837@d33df914ac13dc27>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24623&group=comp.lang.forth#24623

  copy link   Newsgroups: comp.lang.forth
Newsgroups: comp.lang.forth
Subject: Re: new version of magic hexagon program
References: <3b96660a-56e6-4a84-ac82-2758fe6b9d06n@googlegroups.com> <ed0dfb07-3b15-431d-a9d1-b3ed28f6d096n@googlegroups.com>
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
From: albert@cherry (none)
Originator: albert@cherry.(none) (albert)
Message-ID: <nnd$08d3555d$3b44d837@d33df914ac13dc27>
Organization: KPN B.V.
Date: Tue, 19 Sep 2023 22:17:01 +0200
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feed.abavia.com!abe006.abavia.com!abp001.abavia.com!news.kpn.nl!not-for-mail
Lines: 53
Injection-Date: Tue, 19 Sep 2023 22:17:01 +0200
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
X-Received-Bytes: 2278
 by: none - Tue, 19 Sep 2023 20:17 UTC

In article <ed0dfb07-3b15-431d-a9d1-b3ed28f6d096n@googlegroups.com>,
Marcel Hendrix <mhx@iae.nl> wrote:
>On Tuesday, September 19, 2023 at 7:35:18 PM UTC+2, Ahmed MELAHI wrote:
>> Hi,
>> I rewrote the program for the magic hexagon.
>> It appears elegant without any loss of performance. I think it is
>faster than the last versions I have already posted.
>[..]
>> Tested with: gforth, vfxforth anf iforth v4 (evaluation) on my PC:
>> gforth: 4.5 ms
>> vfxforth: 0.734 ms
>> iforth: 0.976 ms
>
>No idea how you timed that. I get 224 us with this:
>
>: INIT marking_table #77 1 fill
> marked #20 ERASE
> loop_loc max_num_constraints ERASE ;
>
>: TEST INIT
> .mag_hex
> CR DTICKS-RESET [TICKS solve TICKS] D-US? .USECS ." elapsed."
> .mag_hex ;
>
>FORTH> TEST
>
> 0 0 0
> 0 0 0 0
> 0 0 0 0 0
> 0 0 0 0
> 0 0 0
>
>240 us elapsed.
>
> 3 17 18
> 19 7 1 11
>16 2 5 6 9
> 12 4 8 14
> 10 13 15
> ok
>
>-marcel

This comment makes no sense. It just proves that your machine
is four times as fast as Ahmed's.

Groetjes Albert
--
Don't praise the day before the evening. One swallow doesn't make spring.
You must not say "hey" before you have crossed the bridge. Don't sell the
hide of the bear until you shot it. Better one bird in the hand than ten in
the air. First gain is a cat spinning. - the Wise from Antrim -

Re: new version of magic hexagon program

<7ddbefe3-078f-487f-b526-377c18f51ebcn@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24624&group=comp.lang.forth#24624

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:620a:2852:b0:770:ef1f:43e9 with SMTP id h18-20020a05620a285200b00770ef1f43e9mr9851qkp.11.1695159844124;
Tue, 19 Sep 2023 14:44:04 -0700 (PDT)
X-Received: by 2002:a05:6830:4c8:b0:6ab:8d3:5209 with SMTP id
s8-20020a05683004c800b006ab08d35209mr258112otd.5.1695159843765; Tue, 19 Sep
2023 14:44:03 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Tue, 19 Sep 2023 14:44:03 -0700 (PDT)
In-Reply-To: <11a0b66c-d991-4207-aca8-a321f2825f99n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=154.121.48.209; posting-account=KJSw4AoAAACRkUCek5r_78mFj6sHzH4C
NNTP-Posting-Host: 154.121.48.209
References: <3b96660a-56e6-4a84-ac82-2758fe6b9d06n@googlegroups.com>
<ed0dfb07-3b15-431d-a9d1-b3ed28f6d096n@googlegroups.com> <11a0b66c-d991-4207-aca8-a321f2825f99n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <7ddbefe3-078f-487f-b526-377c18f51ebcn@googlegroups.com>
Subject: Re: new version of magic hexagon program
From: ahmed.melahi@univ-bejaia.dz (Ahmed MELAHI)
Injection-Date: Tue, 19 Sep 2023 21:44:04 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 11407
 by: Ahmed MELAHI - Tue, 19 Sep 2023 21:44 UTC

Le mardi 19 septembre 2023 à 20:14:37 UTC, Ahmed MELAHI a écrit :
> Le mardi 19 septembre 2023 à 19:01:11 UTC, Marcel Hendrix a écrit :
> > On Tuesday, September 19, 2023 at 7:35:18 PM UTC+2, Ahmed MELAHI wrote:
> > > Hi,
> > > I rewrote the program for the magic hexagon.
> > > It appears elegant without any loss of performance. I think it is faster than the last versions I have already posted.
> > [..]
> > > Tested with: gforth, vfxforth anf iforth v4 (evaluation) on my PC:
> > > gforth: 4.5 ms
> > > vfxforth: 0.734 ms
> > > iforth: 0.976 ms
> > No idea how you timed that. I get 224 us with this:
> >
> > : INIT marking_table #77 1 fill
> > marked #20 ERASE
> > loop_loc max_num_constraints ERASE ;
> >
> > : TEST INIT
> > .mag_hex
> > CR DTICKS-RESET [TICKS solve TICKS] D-US? .USECS ." elapsed."
> > .mag_hex ;
> >
> > FORTH> TEST
> >
> > 0 0 0
> > 0 0 0 0
> > 0 0 0 0 0
> > 0 0 0 0
> > 0 0 0
> >
> > 240 us elapsed.
> >
> > 3 17 18
> > 19 7 1 11
> > 16 2 5 6 9
> > 12 4 8 14
> > 10 13 15
> > ok
> >
> > -marcel
> for the timing I used
> : timing_1000 timer-reset 1000 0 do solve loop .elapsed ;
> I don't know if it is good or no.
> Perhaps my PC is slow (PC portable lenovo ideapad330, Intel(R) Celeron(R) CPU 3867U @ 1.80GHz 1.80 GHz, RAM 12 GB).
>
> My objective was to keep the performance of the previous program and simplify the presentation of the problem of the puzzle (in the word solve) and reduce the size of the program (to about 70 loc).
> Here we can separate the puzzle itself from the tools (clp???) at the begining of the program.
>
> Here, I did that ( I rewrote the program) and got:
>
> \ tools: clp??? ---------------part----------
> 100 value marking_table_size_max
> create marking_table marking_table_size_max allot
> marking_table marking_table_size_max 1 fill
>
> 0 value vals_num
> 20 value vals_num_max
> marking_table marking_table_size_max 2 / + value marked
> marked vals_num_max erase
> 0 value nloops_prec
> 0 value nloops
> 0 value constraint_num
> 20 value max_num_constraints
> create loop_loc max_num_constraints allot
> loop_loc max_num_constraints erase
> : mark 1 swap marked + c! ;
> : unmark 0 swap marked + c! ;
> : marked? marked + c@ 0= ;
>
> : .-- nloops 1+ to nloops postpone do postpone i ; immediate
> : ?, postpone dup postpone marked? postpone if postpone mark ; immediate
> : --> postpone to constraint_num 1+ to constraint_num nloops nloops_prec <> if 1 loop_loc constraint_num + c! nloops to nloops_prec then ; immediate
> : finish| nloops 0 do postpone unloop loop postpone exit ; immediate
> : --- ; immediate
> : _begin_ marked vals_num erase ;
> : | postpone unmark postpone else postpone drop postpone then loop_loc constraint_num + c@ if postpone loop then constraint_num 1- to constraint_num ; immediate
> : _end_ ; immediate
> : values dup 1+ to vals_num 0 ?do 0 value loop ;
>
> \ puzzle: magic hexagon puzzle ----part------
> 19 values vA vB vC vD vE vF vG vH vI vJ vK vL vM vN vO vP vQ vR vS
> : -- 2 .r 2 spaces ;
> : .mag_hex
> cr
> cr
> 4 spaces vA -- vB -- vC -- cr
> 2 spaces vD -- vE -- vF -- vG -- cr
> vH -- vI -- vJ -- vK -- vL -- cr
> 2 spaces vM -- vN -- vO -- vP -- cr
> 4 spaces vQ -- vR -- vS --
> cr
> ;
> : solve
> _begin_
> 20 1 .-- --> vA vA ?,
> 20 1 .-- --> vB vB ?,
> 38 vA vB + - --- --> vC vC ?,
> 20 1 .-- --> vG vG ?,
> 38 vC vG + - --- --> vL vL ?,
> 20 1 .-- --> vP vP ?,
> 38 vL vP + - --- --> vS vS ?,
> 20 1 .-- --> vR vR ?,
> 38 vS vR + - --- --> vQ vQ ?,
> 20 1 .-- --> vM vM ?,
> 38 vQ vM + - --- --> vH vH ?,
> 38 vA vH + - --- --> vD vD ?,
> 20 1 .-- --> vE vE ?,
> 38 vD vE + vG + - --- --> vF vF ?,
> 38 vB vF + vP + - --- --> vK vK ?,
> 38 vG vK + vR + - --- --> vO vO ?,
> 38 vP vO + vM + - --- --> vN vN ?,
> 38 vR vN + vD + - --- --> vI vI ?,
> 38 vH vI + vK + vL + - --- --> vJ vJ ?,
>
> finish| vJ | vI | vN | vO | vK | vF | vE | vD | vH | vM | vQ | vR | vS | vP | vL | vG | vC | vB | vA |
> _end_
> ;
> For example:
> 20 1 .-- --- ---> vA vA ?, is read like this: let vA between 1 and 19, is it acceptable? if yes continue with the others else change vA (backtrack???).
> 38 vA vB + - --- ---> vC vC ?, is read like this: calculate vC using the formula just before (the constraint), is it acceptable? if yes continue with the others else (backtrack???) (in fact I am not sure if this is backtracking).
> When all vA, ..., vJ are accepted (solution found), the word finish| terminates the execution of the word solve.
>
> for the timing, I use:
> : timing_1000 timer-reset 1000 0 do solve loop .elapsed ;
>
> for the moment I don't know if I can use the tools (at the begining) to solve other problems (puzzles) like: magic squares, sendmoremoney etc...
> If so, one can save the first part (tools clp???) in a program named clp.fs for example.
> This program will be included in the program where the problem (puzzle) iself will be programmed.
> I did it, it works.
> Bye

Hi,
I separated the tools from the puzzle.

The tools: saved as clp.fs to be included in the programs where the puzzles (problems) will be defined. Here it is: (I added few words)

\ clp
100 value marking_table_size_max
create marking_table marking_table_size_max allot
marking_table marking_table_size_max 1 fill

0 value vals_num
20 value vals_num_max
marking_table marking_table_size_max 2 / + value marked
marked vals_num_max erase

0 value nloops_prec
0 value nloops
0 value constraint_num
20 value max_num_constraints
create loop_loc max_num_constraints allot
loop_loc max_num_constraints erase
: mark 1 swap marked + c! ;
: unmark 0 swap marked + c! ;
: marked? marked + c@ 0= ;

0 value min_val
0 value max_val

: .-- nloops 1+ to nloops postpone do postpone i ; immediate
: ?, postpone dup postpone dup postpone min_val postpone max_val postpone 1+ postpone within postpone swap postpone marked? postpone and postpone if postpone mark ; immediate
: --> postpone to constraint_num 1+ to constraint_num nloops nloops_prec <> if 1 loop_loc constraint_num + c! nloops to nloops_prec then ; immediate
: finish| nloops 0 do postpone unloop loop postpone exit ; immediate
: --- ; immediate
: _begin_ marked vals_num erase ;
: | postpone unmark postpone else postpone drop postpone then loop_loc constraint_num + c@ if postpone loop then constraint_num 1- to constraint_num ; immediate
: _end_ ; immediate
: =, postpone = postpone if ; immediate
: =| postpone then ; immediate

: values dup 1+ to vals_num 0 ?do 0 value loop ;

\ ------------------------------- here finishes the tools

The magic hexagon puzzle:

include clp.fs

\ magic hexagon puzzle
19 values vA vB vC vD vE vF vG vH vI vJ vK vL vM vN vO vP vQ vR vS
1 to min_val
19 to max_val

: -- 2 .r 2 spaces ;
: .mag_hex
cr
cr
4 spaces vA -- vB -- vC -- cr
2 spaces vD -- vE -- vF -- vG -- cr
vH -- vI -- vJ -- vK -- vL -- cr
2 spaces vM -- vN -- vO -- vP -- cr
4 spaces vQ -- vR -- vS --
cr
;

: solve
_begin_
20 1 .-- --> vA vA ?,
20 1 .-- --> vB vB ?,
38 vA vB + - --- --> vC vC ?,
20 1 .-- --> vG vG ?,
38 vC vG + - --- --> vL vL ?,
20 1 .-- --> vP vP ?,
38 vL vP + - --- --> vS vS ?,
20 1 .-- --> vR vR ?,
38 vS vR + - --- --> vQ vQ ?,
20 1 .-- --> vM vM ?,
38 vQ vM + - --- --> vH vH ?,
38 vA vH + - --- --> vD vD ?,
20 1 .-- --> vE vE ?,
38 vD vE + vG + - --- --> vF vF ?,
38 vB vF + vP + - --- --> vK vK ?,
38 vG vK + vR + - --- --> vO vO ?,
38 vP vO + vM + - --- --> vN vN ?,
38 vR vN + vD + - --- --> vI vI ?,
38 vH vI + vK + vL + - --- --> vJ vJ ?,

finish| vJ | vI | vN | vO | vK | vF | vE | vD | vH | vM | vQ | vR | vS | vP | vL | vG | vC | vB | vA |
_end_
;

\ here finishes the magic hexagon puzzle

Example 2: the magic square (3*3):
include clp.fs

\ magic hexagon puzzle
9 values vA vB vC vD vE vF vG vH vI
1 to min_val
9 to max_val


Click here to read the complete article
Re: new version of magic hexagon program

<cc5591bf-12b0-4b67-b3b2-c63004224d81n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24626&group=comp.lang.forth#24626

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a37:5887:0:b0:76e:e71e:3196 with SMTP id m129-20020a375887000000b0076ee71e3196mr16392qkb.4.1695185102130;
Tue, 19 Sep 2023 21:45:02 -0700 (PDT)
X-Received: by 2002:a05:6870:7690:b0:1d6:5e45:3bc7 with SMTP id
dx16-20020a056870769000b001d65e453bc7mr572277oab.5.1695185101918; Tue, 19 Sep
2023 21:45:01 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Tue, 19 Sep 2023 21:45:01 -0700 (PDT)
In-Reply-To: <nnd$08d3555d$3b44d837@d33df914ac13dc27>
Injection-Info: google-groups.googlegroups.com; posting-host=2001:1c05:2f18:6d00:d00f:a4fe:2d77:3bb2;
posting-account=-JQ2RQoAAAB6B5tcBTSdvOqrD1HpT_Rk
NNTP-Posting-Host: 2001:1c05:2f18:6d00:d00f:a4fe:2d77:3bb2
References: <3b96660a-56e6-4a84-ac82-2758fe6b9d06n@googlegroups.com>
<ed0dfb07-3b15-431d-a9d1-b3ed28f6d096n@googlegroups.com> <nnd$08d3555d$3b44d837@d33df914ac13dc27>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <cc5591bf-12b0-4b67-b3b2-c63004224d81n@googlegroups.com>
Subject: Re: new version of magic hexagon program
From: mhx@iae.nl (Marcel Hendrix)
Injection-Date: Wed, 20 Sep 2023 04:45:02 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: Marcel Hendrix - Wed, 20 Sep 2023 04:45 UTC

On Tuesday, September 19, 2023 at 10:17:04 PM UTC+2, none albert wrote:
> In article <ed0dfb07-3b15-431d...@googlegroups.com>,
> Marcel Hendrix <m...@iae.nl> wrote:
[..]
>>>Tested with: gforth, vfxforth anf iforth v4 (evaluation) on my PC:
[..]
> This comment makes no sense. It just proves that your machine
> is four times as fast as Ahmed's.

No, it just points out that 1. the current version of iForth is "version 6.9.109,
generated 18:39:31, September 27, 2021", and 2. it was not clear how
to run a microsecond timer over the code on the mentioned Forths.

-marcel

Re: new version of magic hexagon program

<8bbd9e41-e13b-4af6-9d7f-7b53718523e2n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24627&group=comp.lang.forth#24627

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:620a:6548:b0:76f:6e2:8bea with SMTP id qc8-20020a05620a654800b0076f06e28beamr15669qkn.12.1695187038501;
Tue, 19 Sep 2023 22:17:18 -0700 (PDT)
X-Received: by 2002:a05:6870:1844:b0:1d6:3c76:e1c9 with SMTP id
u4-20020a056870184400b001d63c76e1c9mr630651oaf.6.1695187037338; Tue, 19 Sep
2023 22:17:17 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Tue, 19 Sep 2023 22:17:16 -0700 (PDT)
In-Reply-To: <cc5591bf-12b0-4b67-b3b2-c63004224d81n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2003:f7:1f04:cca8:3166:4798:b776:324f;
posting-account=AqNUYgoAAADmkK2pN-RKms8sww57W0Iw
NNTP-Posting-Host: 2003:f7:1f04:cca8:3166:4798:b776:324f
References: <3b96660a-56e6-4a84-ac82-2758fe6b9d06n@googlegroups.com>
<ed0dfb07-3b15-431d-a9d1-b3ed28f6d096n@googlegroups.com> <nnd$08d3555d$3b44d837@d33df914ac13dc27>
<cc5591bf-12b0-4b67-b3b2-c63004224d81n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <8bbd9e41-e13b-4af6-9d7f-7b53718523e2n@googlegroups.com>
Subject: Re: new version of magic hexagon program
From: minforth@arcor.de (minforth)
Injection-Date: Wed, 20 Sep 2023 05:17:18 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2412
 by: minforth - Wed, 20 Sep 2023 05:17 UTC

Marcel Hendrix schrieb am Mittwoch, 20. September 2023 um 06:45:03 UTC+2:
> On Tuesday, September 19, 2023 at 10:17:04 PM UTC+2, none albert wrote:
> > In article <ed0dfb07-3b15-431d...@googlegroups.com>,
> > Marcel Hendrix <m...@iae.nl> wrote:
> [..]
> >>>Tested with: gforth, vfxforth anf iforth v4 (evaluation) on my PC:
> [..]
> > This comment makes no sense. It just proves that your machine
> > is four times as fast as Ahmed's.
> No, it just points out that 1. the current version of iForth is "version 6.9.109,
> generated 18:39:31, September 27, 2021", and 2. it was not clear how
> to run a microsecond timer over the code on the mentioned Forths.
>

Since we have timing problems now, it seems high time to burn more microseconds
by solving the Magic Hexagon of rank 8:

Cells start with −84 and end with +84, and all its horizontal and diagonal sums are 0.

Solution:
https://commons.wikimedia.org/wiki/File:MagicHexagon-Order8.svg

Enjoy ;-)

Re: new version of magic hexagon program

<9a6ba3d0-1a02-4418-85a5-66511593c398n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24628&group=comp.lang.forth#24628

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:622a:1315:b0:412:2d47:701e with SMTP id v21-20020a05622a131500b004122d47701emr18531qtk.12.1695189107431;
Tue, 19 Sep 2023 22:51:47 -0700 (PDT)
X-Received: by 2002:a9d:6282:0:b0:6c0:e336:7b81 with SMTP id
x2-20020a9d6282000000b006c0e3367b81mr591516otk.4.1695189107017; Tue, 19 Sep
2023 22:51:47 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!border-2.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Tue, 19 Sep 2023 22:51:46 -0700 (PDT)
In-Reply-To: <7ddbefe3-078f-487f-b526-377c18f51ebcn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=154.121.48.209; posting-account=KJSw4AoAAACRkUCek5r_78mFj6sHzH4C
NNTP-Posting-Host: 154.121.48.209
References: <3b96660a-56e6-4a84-ac82-2758fe6b9d06n@googlegroups.com>
<ed0dfb07-3b15-431d-a9d1-b3ed28f6d096n@googlegroups.com> <11a0b66c-d991-4207-aca8-a321f2825f99n@googlegroups.com>
<7ddbefe3-078f-487f-b526-377c18f51ebcn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <9a6ba3d0-1a02-4418-85a5-66511593c398n@googlegroups.com>
Subject: Re: new version of magic hexagon program
From: ahmed.melahi@univ-bejaia.dz (Ahmed MELAHI)
Injection-Date: Wed, 20 Sep 2023 05:51:47 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 408
 by: Ahmed MELAHI - Wed, 20 Sep 2023 05:51 UTC

Le mardi 19 septembre 2023 à 21:44:05 UTC, Ahmed MELAHI a écrit :
> Le mardi 19 septembre 2023 à 20:14:37 UTC, Ahmed MELAHI a écrit :
> > Le mardi 19 septembre 2023 à 19:01:11 UTC, Marcel Hendrix a écrit :
> > > On Tuesday, September 19, 2023 at 7:35:18 PM UTC+2, Ahmed MELAHI wrote:
> > > > Hi,
> > > > I rewrote the program for the magic hexagon.
> > > > It appears elegant without any loss of performance. I think it is faster than the last versions I have already posted.
> > > [..]
> > > > Tested with: gforth, vfxforth anf iforth v4 (evaluation) on my PC:
> > > > gforth: 4.5 ms
> > > > vfxforth: 0.734 ms
> > > > iforth: 0.976 ms
> > > No idea how you timed that. I get 224 us with this:
> > >
> > > : INIT marking_table #77 1 fill
> > > marked #20 ERASE
> > > loop_loc max_num_constraints ERASE ;
> > >
> > > : TEST INIT
> > > .mag_hex
> > > CR DTICKS-RESET [TICKS solve TICKS] D-US? .USECS ." elapsed."
> > > .mag_hex ;
> > >
> > > FORTH> TEST
> > >
> > > 0 0 0
> > > 0 0 0 0
> > > 0 0 0 0 0
> > > 0 0 0 0
> > > 0 0 0
> > >
> > > 240 us elapsed.
> > >
> > > 3 17 18
> > > 19 7 1 11
> > > 16 2 5 6 9
> > > 12 4 8 14
> > > 10 13 15
> > > ok
> > >
> > > -marcel
> > for the timing I used
> > : timing_1000 timer-reset 1000 0 do solve loop .elapsed ;
> > I don't know if it is good or no.
> > Perhaps my PC is slow (PC portable lenovo ideapad330, Intel(R) Celeron(R) CPU 3867U @ 1.80GHz 1.80 GHz, RAM 12 GB).
> >
> > My objective was to keep the performance of the previous program and simplify the presentation of the problem of the puzzle (in the word solve) and reduce the size of the program (to about 70 loc).
> > Here we can separate the puzzle itself from the tools (clp???) at the begining of the program.
> >
> > Here, I did that ( I rewrote the program) and got:
> >
> > \ tools: clp??? ---------------part----------
> > 100 value marking_table_size_max
> > create marking_table marking_table_size_max allot
> > marking_table marking_table_size_max 1 fill
> >
> > 0 value vals_num
> > 20 value vals_num_max
> > marking_table marking_table_size_max 2 / + value marked
> > marked vals_num_max erase
> > 0 value nloops_prec
> > 0 value nloops
> > 0 value constraint_num
> > 20 value max_num_constraints
> > create loop_loc max_num_constraints allot
> > loop_loc max_num_constraints erase
> > : mark 1 swap marked + c! ;
> > : unmark 0 swap marked + c! ;
> > : marked? marked + c@ 0= ;
> >
> > : .-- nloops 1+ to nloops postpone do postpone i ; immediate
> > : ?, postpone dup postpone marked? postpone if postpone mark ; immediate
> > : --> postpone to constraint_num 1+ to constraint_num nloops nloops_prec <> if 1 loop_loc constraint_num + c! nloops to nloops_prec then ; immediate
> > : finish| nloops 0 do postpone unloop loop postpone exit ; immediate
> > : --- ; immediate
> > : _begin_ marked vals_num erase ;
> > : | postpone unmark postpone else postpone drop postpone then loop_loc constraint_num + c@ if postpone loop then constraint_num 1- to constraint_num ; immediate
> > : _end_ ; immediate
> > : values dup 1+ to vals_num 0 ?do 0 value loop ;
> >
> > \ puzzle: magic hexagon puzzle ----part------
> > 19 values vA vB vC vD vE vF vG vH vI vJ vK vL vM vN vO vP vQ vR vS
> > : -- 2 .r 2 spaces ;
> > : .mag_hex
> > cr
> > cr
> > 4 spaces vA -- vB -- vC -- cr
> > 2 spaces vD -- vE -- vF -- vG -- cr
> > vH -- vI -- vJ -- vK -- vL -- cr
> > 2 spaces vM -- vN -- vO -- vP -- cr
> > 4 spaces vQ -- vR -- vS --
> > cr
> > ;
> > : solve
> > _begin_
> > 20 1 .-- --> vA vA ?,
> > 20 1 .-- --> vB vB ?,
> > 38 vA vB + - --- --> vC vC ?,
> > 20 1 .-- --> vG vG ?,
> > 38 vC vG + - --- --> vL vL ?,
> > 20 1 .-- --> vP vP ?,
> > 38 vL vP + - --- --> vS vS ?,
> > 20 1 .-- --> vR vR ?,
> > 38 vS vR + - --- --> vQ vQ ?,
> > 20 1 .-- --> vM vM ?,
> > 38 vQ vM + - --- --> vH vH ?,
> > 38 vA vH + - --- --> vD vD ?,
> > 20 1 .-- --> vE vE ?,
> > 38 vD vE + vG + - --- --> vF vF ?,
> > 38 vB vF + vP + - --- --> vK vK ?,
> > 38 vG vK + vR + - --- --> vO vO ?,
> > 38 vP vO + vM + - --- --> vN vN ?,
> > 38 vR vN + vD + - --- --> vI vI ?,
> > 38 vH vI + vK + vL + - --- --> vJ vJ ?,
> >
> > finish| vJ | vI | vN | vO | vK | vF | vE | vD | vH | vM | vQ | vR | vS | vP | vL | vG | vC | vB | vA |
> > _end_
> > ;
> > For example:
> > 20 1 .-- --- ---> vA vA ?, is read like this: let vA between 1 and 19, is it acceptable? if yes continue with the others else change vA (backtrack???).
> > 38 vA vB + - --- ---> vC vC ?, is read like this: calculate vC using the formula just before (the constraint), is it acceptable? if yes continue with the others else (backtrack???) (in fact I am not sure if this is backtracking).
> > When all vA, ..., vJ are accepted (solution found), the word finish| terminates the execution of the word solve.
> >
> > for the timing, I use:
> > : timing_1000 timer-reset 1000 0 do solve loop .elapsed ;
> >
> > for the moment I don't know if I can use the tools (at the begining) to solve other problems (puzzles) like: magic squares, sendmoremoney etc...
> > If so, one can save the first part (tools clp???) in a program named clp.fs for example.
> > This program will be included in the program where the problem (puzzle) iself will be programmed.
> > I did it, it works.
> > Bye
> Hi,
> I separated the tools from the puzzle.
>
> The tools: saved as clp.fs to be included in the programs where the puzzles (problems) will be defined. Here it is: (I added few words)
>
>
> \ clp
> 100 value marking_table_size_max
> create marking_table marking_table_size_max allot
> marking_table marking_table_size_max 1 fill
>
> 0 value vals_num
> 20 value vals_num_max
> marking_table marking_table_size_max 2 / + value marked
> marked vals_num_max erase
>
> 0 value nloops_prec
> 0 value nloops
> 0 value constraint_num
> 20 value max_num_constraints
> create loop_loc max_num_constraints allot
> loop_loc max_num_constraints erase
> : mark 1 swap marked + c! ;
> : unmark 0 swap marked + c! ;
> : marked? marked + c@ 0= ;
> 0 value min_val
> 0 value max_val
> : .-- nloops 1+ to nloops postpone do postpone i ; immediate
> : ?, postpone dup postpone dup postpone min_val postpone max_val postpone 1+ postpone within postpone swap postpone marked? postpone and postpone if postpone mark ; immediate
> : --> postpone to constraint_num 1+ to constraint_num nloops nloops_prec <> if 1 loop_loc constraint_num + c! nloops to nloops_prec then ; immediate
> : finish| nloops 0 do postpone unloop loop postpone exit ; immediate
> : --- ; immediate
> : _begin_ marked vals_num erase ;
> : | postpone unmark postpone else postpone drop postpone then loop_loc constraint_num + c@ if postpone loop then constraint_num 1- to constraint_num ; immediate
> : _end_ ; immediate
> : =, postpone = postpone if ; immediate
> : =| postpone then ; immediate
> : values dup 1+ to vals_num 0 ?do 0 value loop ;
> \ ------------------------------- here finishes the tools
>
> The magic hexagon puzzle:
>
> include clp.fs
>
> \ magic hexagon puzzle
> 19 values vA vB vC vD vE vF vG vH vI vJ vK vL vM vN vO vP vQ vR vS
> 1 to min_val
> 19 to max_val
> : -- 2 .r 2 spaces ;
> : .mag_hex
> cr
> cr
> 4 spaces vA -- vB -- vC -- cr
> 2 spaces vD -- vE -- vF -- vG -- cr
> vH -- vI -- vJ -- vK -- vL -- cr
> 2 spaces vM -- vN -- vO -- vP -- cr
> 4 spaces vQ -- vR -- vS --
> cr
> ;
>
> : solve
> _begin_
> 20 1 .-- --> vA vA ?,
> 20 1 .-- --> vB vB ?,
> 38 vA vB + - --- --> vC vC ?,
> 20 1 .-- --> vG vG ?,
> 38 vC vG + - --- --> vL vL ?,
> 20 1 .-- --> vP vP ?,
> 38 vL vP + - --- --> vS vS ?,
> 20 1 .-- --> vR vR ?,
> 38 vS vR + - --- --> vQ vQ ?,
> 20 1 .-- --> vM vM ?,
> 38 vQ vM + - --- --> vH vH ?,
> 38 vA vH + - --- --> vD vD ?,
> 20 1 .-- --> vE vE ?,
> 38 vD vE + vG + - --- --> vF vF ?,
> 38 vB vF + vP + - --- --> vK vK ?,
> 38 vG vK + vR + - --- --> vO vO ?,
> 38 vP vO + vM + - --- --> vN vN ?,
> 38 vR vN + vD + - --- --> vI vI ?,
> 38 vH vI + vK + vL + - --- --> vJ vJ ?,
>
> finish| vJ | vI | vN | vO | vK | vF | vE | vD | vH | vM | vQ | vR | vS | vP | vL | vG | vC | vB | vA |
> _end_
> ;
> \ here finishes the magic hexagon puzzle
>
> Example 2: the magic square (3*3):
> include clp.fs
>
> \ magic hexagon puzzle
> 9 values vA vB vC vD vE vF vG vH vI
> 1 to min_val
> 9 to max_val
> : -- 2 .r 2 spaces ;
> : .mag_sq
> cr
> cr
> 4 spaces vA -- vB -- vC -- cr
> 4 spaces vD -- vE -- vF -- cr
> 4 spaces vG -- vH -- vI --
> cr
> ;
>
> : solve
> _begin_
> 10 1 .-- --> vA vA ?,
> 10 1 .-- --> vB vB ?,
> 15 vA vB + - --- --> vC vC ?,
> 10 1 .-- --> vF vF ?,
> 15 vC vF + - --- --> vI vI ?,
> 10 1 .-- --> vH vH ?,
> 15 vI vH + - --- --> vG vG ?,
> 15 vG vA + - --- --> vD vD ?,
> 15 vD vF + - --- --> vE vE ?,
> 15 vA vE vI + + =,
> 15 vG vE vC + + =,
> 15 vG vE vC + + =,
>
> finish| =| =| =| vE | vD | vG | vH | vI | vF | vC | vB | vA | ." no solution found!"
> _end_
> ;
> \ here ends the magic square program
> for the timing, I use:
> : timing_1000 timer-reset 1000 0 do solve loop .elapsed ;
> for the magic square:
> gforth 42 us
> iforth 3.3 us
> vfxforth 1.6us
>
>
> any ideas, propositions ...
> Bye


Click here to read the complete article
Re: new version of magic hexagon program

<968c2cc6-abc6-4e67-a275-7af21b99471an@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24629&group=comp.lang.forth#24629

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:620a:b0d:b0:76d:bea6:7ec2 with SMTP id t13-20020a05620a0b0d00b0076dbea67ec2mr19453qkg.3.1695189853290;
Tue, 19 Sep 2023 23:04:13 -0700 (PDT)
X-Received: by 2002:a05:6871:6a97:b0:1d6:cf21:44c1 with SMTP id
zf23-20020a0568716a9700b001d6cf2144c1mr599251oab.9.1695189852987; Tue, 19 Sep
2023 23:04:12 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Tue, 19 Sep 2023 23:04:12 -0700 (PDT)
In-Reply-To: <8bbd9e41-e13b-4af6-9d7f-7b53718523e2n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=154.121.48.209; posting-account=KJSw4AoAAACRkUCek5r_78mFj6sHzH4C
NNTP-Posting-Host: 154.121.48.209
References: <3b96660a-56e6-4a84-ac82-2758fe6b9d06n@googlegroups.com>
<ed0dfb07-3b15-431d-a9d1-b3ed28f6d096n@googlegroups.com> <nnd$08d3555d$3b44d837@d33df914ac13dc27>
<cc5591bf-12b0-4b67-b3b2-c63004224d81n@googlegroups.com> <8bbd9e41-e13b-4af6-9d7f-7b53718523e2n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <968c2cc6-abc6-4e67-a275-7af21b99471an@googlegroups.com>
Subject: Re: new version of magic hexagon program
From: ahmed.melahi@univ-bejaia.dz (Ahmed MELAHI)
Injection-Date: Wed, 20 Sep 2023 06:04:13 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2992
 by: Ahmed MELAHI - Wed, 20 Sep 2023 06:04 UTC

Le mercredi 20 septembre 2023 à 05:17:19 UTC, minforth a écrit :
> Marcel Hendrix schrieb am Mittwoch, 20. September 2023 um 06:45:03 UTC+2:
> > On Tuesday, September 19, 2023 at 10:17:04 PM UTC+2, none albert wrote:
> > > In article <ed0dfb07-3b15-431d...@googlegroups.com>,
> > > Marcel Hendrix <m...@iae.nl> wrote:
> > [..]
> > >>>Tested with: gforth, vfxforth anf iforth v4 (evaluation) on my PC:
> > [..]
> > > This comment makes no sense. It just proves that your machine
> > > is four times as fast as Ahmed's.
> > No, it just points out that 1. the current version of iForth is "version 6.9.109,
> > generated 18:39:31, September 27, 2021", and 2. it was not clear how
> > to run a microsecond timer over the code on the mentioned Forths.
> >
> Since we have timing problems now, it seems high time to burn more microseconds
> by solving the Magic Hexagon of rank 8:
>
> Cells start with −84 and end with +84, and all its horizontal and diagonal sums are 0.
>
> Solution:
> https://commons.wikimedia.org/wiki/File:MagicHexagon-Order8.svg
>
> Enjoy ;-)

HI,
A problem with:
169 unkowns,
45 constraints,
169 possible values
write a program to solve this problem for just fun!!! I don't dare write it..
What about sudoku?
sudoku has: 81 unkowns, 27 constraints and 10 possible values.

In fact, I took the magic hexagon, the magic square and sendmoremoney problems just to test the possibility to write a simple clp solver.
bye

Re: new version of magic hexagon program

<874c321b-7c66-4b5e-b277-83a2c2aff392n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24630&group=comp.lang.forth#24630

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:6214:1932:b0:656:1fc7:d6c4 with SMTP id es18-20020a056214193200b006561fc7d6c4mr15573qvb.10.1695193425149;
Wed, 20 Sep 2023 00:03:45 -0700 (PDT)
X-Received: by 2002:a05:6808:318e:b0:3ad:caa7:837a with SMTP id
cd14-20020a056808318e00b003adcaa7837amr2030771oib.2.1695193424857; Wed, 20
Sep 2023 00:03:44 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Wed, 20 Sep 2023 00:03:44 -0700 (PDT)
In-Reply-To: <968c2cc6-abc6-4e67-a275-7af21b99471an@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=131.155.126.1; posting-account=-JQ2RQoAAAB6B5tcBTSdvOqrD1HpT_Rk
NNTP-Posting-Host: 131.155.126.1
References: <3b96660a-56e6-4a84-ac82-2758fe6b9d06n@googlegroups.com>
<ed0dfb07-3b15-431d-a9d1-b3ed28f6d096n@googlegroups.com> <nnd$08d3555d$3b44d837@d33df914ac13dc27>
<cc5591bf-12b0-4b67-b3b2-c63004224d81n@googlegroups.com> <8bbd9e41-e13b-4af6-9d7f-7b53718523e2n@googlegroups.com>
<968c2cc6-abc6-4e67-a275-7af21b99471an@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <874c321b-7c66-4b5e-b277-83a2c2aff392n@googlegroups.com>
Subject: Re: new version of magic hexagon program
From: mhx@iae.nl (Marcel Hendrix)
Injection-Date: Wed, 20 Sep 2023 07:03:45 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2358
 by: Marcel Hendrix - Wed, 20 Sep 2023 07:03 UTC

On Wednesday, September 20, 2023 at 8:04:14 AM UTC+2, Ahmed MELAHI wrote:
[..]
> A problem with:
> 169 unkowns,
> 45 constraints,
> 169 possible values
> write a program to solve this problem for just fun!!! I don't dare write it.
> What about sudoku?
> sudoku has: 81 unkowns, 27 constraints and 10 possible values.
>
> In fact, I took the magic hexagon, the magic square and sendmoremoney
> problems just to test the possibility to write a simple clp solver.

This starts to get interesting. Is it possible for you to write down the solution
method refering to the way(s) in which it is conventionally approached?
A reference to a classic paper might suffice.

I'd like to understand which corners are cut (if any) and what the advantage is over
existing programs. I use the minion program when necessay, unfortunately I saw that it
is out of maintenance.

-marcel

Re: new version of magic hexagon program

<a6d0e64f-dd73-42b7-89d7-66614ed8cf6dn@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24632&group=comp.lang.forth#24632

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:622a:1a06:b0:412:3f1:aafa with SMTP id f6-20020a05622a1a0600b0041203f1aafamr23661qtb.5.1695209968088;
Wed, 20 Sep 2023 04:39:28 -0700 (PDT)
X-Received: by 2002:a05:6870:c7b3:b0:1bb:5fac:524e with SMTP id
dy51-20020a056870c7b300b001bb5fac524emr973900oab.5.1695209967665; Wed, 20 Sep
2023 04:39:27 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Wed, 20 Sep 2023 04:39:27 -0700 (PDT)
In-Reply-To: <874c321b-7c66-4b5e-b277-83a2c2aff392n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=154.121.48.209; posting-account=KJSw4AoAAACRkUCek5r_78mFj6sHzH4C
NNTP-Posting-Host: 154.121.48.209
References: <3b96660a-56e6-4a84-ac82-2758fe6b9d06n@googlegroups.com>
<ed0dfb07-3b15-431d-a9d1-b3ed28f6d096n@googlegroups.com> <nnd$08d3555d$3b44d837@d33df914ac13dc27>
<cc5591bf-12b0-4b67-b3b2-c63004224d81n@googlegroups.com> <8bbd9e41-e13b-4af6-9d7f-7b53718523e2n@googlegroups.com>
<968c2cc6-abc6-4e67-a275-7af21b99471an@googlegroups.com> <874c321b-7c66-4b5e-b277-83a2c2aff392n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a6d0e64f-dd73-42b7-89d7-66614ed8cf6dn@googlegroups.com>
Subject: Re: new version of magic hexagon program
From: ahmed.melahi@univ-bejaia.dz (Ahmed MELAHI)
Injection-Date: Wed, 20 Sep 2023 11:39:28 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 5203
 by: Ahmed MELAHI - Wed, 20 Sep 2023 11:39 UTC

Le mercredi 20 septembre 2023 à 07:03:46 UTC, Marcel Hendrix a écrit :
> On Wednesday, September 20, 2023 at 8:04:14 AM UTC+2, Ahmed MELAHI wrote:
> [..]
> > A problem with:
> > 169 unkowns,
> > 45 constraints,
> > 169 possible values
> > write a program to solve this problem for just fun!!! I don't dare write it.
> > What about sudoku?
> > sudoku has: 81 unkowns, 27 constraints and 10 possible values.
> >
> > In fact, I took the magic hexagon, the magic square and sendmoremoney
> > problems just to test the possibility to write a simple clp solver.
> This starts to get interesting. Is it possible for you to write down the solution
> method refering to the way(s) in which it is conventionally approached?
> A reference to a classic paper might suffice.
>
> I'd like to understand which corners are cut (if any) and what the advantage is over
> existing programs. I use the minion program when necessay, unfortunately I saw that it
> is out of maintenance.
>
> -marcel
Hi,
I forgot to post the latest update of clp.fs
Here it is:

\ clp
100 value marking_table_size_max
create marking_table marking_table_size_max allot
marking_table marking_table_size_max 1 fill

0 value vals_num
20 value vals_num_max
marking_table marking_table_size_max 2 / + value marked
marked vals_num_max erase

0 value nloops_prec
0 value nloops
0 value constraint_num
20 value max_num_constraints
create loop_loc max_num_constraints allot
loop_loc max_num_constraints erase
: mark 1 swap marked + c! ;
: unmark 0 swap marked + c! ;
: marked? marked + c@ 0= ;

0 value min_val
0 value max_val

: .-- nloops 1+ to nloops postpone do postpone i ; immediate
: ?, postpone dup postpone dup postpone min_val postpone max_val postpone 1+ postpone within postpone swap postpone marked? postpone and postpone if postpone mark ; immediate
: --> postpone to constraint_num 1+ to constraint_num nloops nloops_prec <> if 1 loop_loc constraint_num + c! nloops to nloops_prec then ; immediate
: finish| nloops 0 do postpone unloop loop postpone exit ; immediate
: --- ; immediate
: _begin_ marked vals_num_max erase ;
: | postpone unmark postpone else postpone drop postpone then loop_loc constraint_num + c@ if postpone loop then constraint_num 1- to constraint_num ; immediate
: _end_ ; immediate
: =, postpone = postpone if ; immediate
: =| postpone then ; immediate

: values dup 1+ to vals_num 0 ?do 0 value loop ;

\----------------------------
For the documentation, I saw the website:
https://www.metalevel.at/
and in this page, the book (thesis) :
Correctness Considerations in CLP(FD) Systems (pdf, bib)
Doctoral thesis, under the supervision of Priv.-Doz. Dr. Nysret Musliu
Accepted in January 2014, Technische Universität Wien

I read just the first two chapters rapidly.
And some other books about constraint logic programming (summarily).
The advices I found (as I understood it ) and used:
- order the unkowns,
- order the constraints,
- calculate when possible

I applied these advices and wrote the first lenghty program.

Then with postpone and other ideas etc .. I tried to construct the same word "solve" in compile time.
I tried to simplify the presentation (the look) of the word solve in order to read the problem ( the constraints) easily.
With iterative refinements, I realized that I can separate the tools from the problems to solve.

The challange, now, is how to generalize the tools to deal with different types of problems.
Bye

Re: new version of magic hexagon program

<d579bb45-e21e-4ea8-a98e-599d7073846en@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24633&group=comp.lang.forth#24633

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:ac8:5a49:0:b0:412:2107:7f1d with SMTP id o9-20020ac85a49000000b0041221077f1dmr40504qta.7.1695228022130;
Wed, 20 Sep 2023 09:40:22 -0700 (PDT)
X-Received: by 2002:a05:6870:1a88:b0:1d5:8e96:7d85 with SMTP id
ef8-20020a0568701a8800b001d58e967d85mr1076212oab.1.1695228021826; Wed, 20 Sep
2023 09:40:21 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!1.us.feeder.erje.net!3.us.feeder.erje.net!feeder.erje.net!border-1.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Wed, 20 Sep 2023 09:40:21 -0700 (PDT)
In-Reply-To: <968c2cc6-abc6-4e67-a275-7af21b99471an@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2003:f7:1f04:cc1f:754b:4f2c:e93:2358;
posting-account=AqNUYgoAAADmkK2pN-RKms8sww57W0Iw
NNTP-Posting-Host: 2003:f7:1f04:cc1f:754b:4f2c:e93:2358
References: <3b96660a-56e6-4a84-ac82-2758fe6b9d06n@googlegroups.com>
<ed0dfb07-3b15-431d-a9d1-b3ed28f6d096n@googlegroups.com> <nnd$08d3555d$3b44d837@d33df914ac13dc27>
<cc5591bf-12b0-4b67-b3b2-c63004224d81n@googlegroups.com> <8bbd9e41-e13b-4af6-9d7f-7b53718523e2n@googlegroups.com>
<968c2cc6-abc6-4e67-a275-7af21b99471an@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d579bb45-e21e-4ea8-a98e-599d7073846en@googlegroups.com>
Subject: Re: new version of magic hexagon program
From: minforth@arcor.de (minforth)
Injection-Date: Wed, 20 Sep 2023 16:40:22 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 106
 by: minforth - Wed, 20 Sep 2023 16:40 UTC

Ahmed MELAHI schrieb am Mittwoch, 20. September 2023 um 08:04:14 UTC+2:
> Le mercredi 20 septembre 2023 à 05:17:19 UTC, minforth a écrit :
> > Marcel Hendrix schrieb am Mittwoch, 20. September 2023 um 06:45:03 UTC+2:
> > > On Tuesday, September 19, 2023 at 10:17:04 PM UTC+2, none albert wrote:
> > > > In article <ed0dfb07-3b15-431d...@googlegroups.com>,
> > > > Marcel Hendrix <m...@iae.nl> wrote:
> > > [..]
> > > >>>Tested with: gforth, vfxforth anf iforth v4 (evaluation) on my PC:
> > > [..]
> > > > This comment makes no sense. It just proves that your machine
> > > > is four times as fast as Ahmed's.
> > > No, it just points out that 1. the current version of iForth is "version 6.9.109,
> > > generated 18:39:31, September 27, 2021", and 2. it was not clear how
> > > to run a microsecond timer over the code on the mentioned Forths.
> > >
> > Since we have timing problems now, it seems high time to burn more microseconds
> > by solving the Magic Hexagon of rank 8:
> >
> > Cells start with −84 and end with +84, and all its horizontal and diagonal sums are 0.
> >
> > Solution:
> > https://commons.wikimedia.org/wiki/File:MagicHexagon-Order8.svg
> >
> > Enjoy ;-)
> HI,
> A problem with:
> 169 unkowns,
> 45 constraints,
> 169 possible values
> write a program to solve this problem for just fun!!! I don't dare write it.
> What about sudoku?
> sudoku has: 81 unkowns, 27 constraints and 10 possible values.
>
> In fact, I took the magic hexagon, the magic square and sendmoremoney problems just to test the possibility to write a simple clp solver.
> bye

Congrats for your work!

Just for comparison (an example for declarative programming without one single line of imperative algorithms):

/*
Sudoku solver (BProlog)
*/

:- initialization(main).

main :-

Vars = [ % declare sudoku 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 puzzle

%row restrictions
alldifferent([X11,X12,X13, X14,X15,X16, X17,X18,X19]),
<snip: other 8 rows>

%column restr.
alldifferent([X11,X21,X31, X41,X51,X61, X71,X81,X91]),
<snip: other 8 cols>

%block restr.
alldifferent([X11,X12,X13, X21,X22,X23, X31,X32,X33]),
<snip: other 8 blocks>

labeling(Vars), %solver
writeln(Vars).

% Example:

sudoku([ % initialize board and solve puzzle
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
]).

Underscore characters _ are so-called unbound variables.

Re: new version of magic hexagon program

<b5d24a6c-1736-4c63-9c15-7b1780b9d5e4n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24634&group=comp.lang.forth#24634

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:620a:1a0e:b0:76f:e36:28d0 with SMTP id bk14-20020a05620a1a0e00b0076f0e3628d0mr47629qkb.0.1695231146060;
Wed, 20 Sep 2023 10:32:26 -0700 (PDT)
X-Received: by 2002:a05:6870:b7ad:b0:1d1:4a4b:62b8 with SMTP id
ed45-20020a056870b7ad00b001d14a4b62b8mr1083327oab.8.1695231145702; Wed, 20
Sep 2023 10:32:25 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Wed, 20 Sep 2023 10:32:25 -0700 (PDT)
In-Reply-To: <d579bb45-e21e-4ea8-a98e-599d7073846en@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2001:1c05:2f18:6d00:d00f:a4fe:2d77:3bb2;
posting-account=-JQ2RQoAAAB6B5tcBTSdvOqrD1HpT_Rk
NNTP-Posting-Host: 2001:1c05:2f18:6d00:d00f:a4fe:2d77:3bb2
References: <3b96660a-56e6-4a84-ac82-2758fe6b9d06n@googlegroups.com>
<ed0dfb07-3b15-431d-a9d1-b3ed28f6d096n@googlegroups.com> <nnd$08d3555d$3b44d837@d33df914ac13dc27>
<cc5591bf-12b0-4b67-b3b2-c63004224d81n@googlegroups.com> <8bbd9e41-e13b-4af6-9d7f-7b53718523e2n@googlegroups.com>
<968c2cc6-abc6-4e67-a275-7af21b99471an@googlegroups.com> <d579bb45-e21e-4ea8-a98e-599d7073846en@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b5d24a6c-1736-4c63-9c15-7b1780b9d5e4n@googlegroups.com>
Subject: Re: new version of magic hexagon program
From: mhx@iae.nl (Marcel Hendrix)
Injection-Date: Wed, 20 Sep 2023 17:32:26 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2163
 by: Marcel Hendrix - Wed, 20 Sep 2023 17:32 UTC

On Wednesday, September 20, 2023 at 6:40:23 PM UTC+2, minforth wrote:
> Ahmed MELAHI schrieb am Mittwoch, 20. September 2023 um 08:04:14 UTC+2:
> > Le mercredi 20 septembre 2023 à 05:17:19 UTC, minforth a écrit :
[..]
> %row restrictions
> alldifferent([X11,X12,X13, X14,X15,X16, X17,X18,X19]),
> Underscore characters _ are so-called unbound variables.

That is the same syntax minion-0.12 is using ( alldifferent )!
It would be great to have a small Forth version of primitives like
abs, alldiff, difference, diseq, hamming ineq, occurence, ...

-marcel

Re: new version of magic hexagon program

<3620042f-e5bc-417a-86a5-c5ade886607cn@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24635&group=comp.lang.forth#24635

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:622a:1a26:b0:412:1974:9730 with SMTP id f38-20020a05622a1a2600b0041219749730mr38574qtb.5.1695236417182;
Wed, 20 Sep 2023 12:00:17 -0700 (PDT)
X-Received: by 2002:a05:6830:1d70:b0:6bb:2474:3d40 with SMTP id
l16-20020a0568301d7000b006bb24743d40mr1090384oti.0.1695236415367; Wed, 20 Sep
2023 12:00:15 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!border-2.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Wed, 20 Sep 2023 12:00:14 -0700 (PDT)
In-Reply-To: <b5d24a6c-1736-4c63-9c15-7b1780b9d5e4n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=154.121.92.114; posting-account=KJSw4AoAAACRkUCek5r_78mFj6sHzH4C
NNTP-Posting-Host: 154.121.92.114
References: <3b96660a-56e6-4a84-ac82-2758fe6b9d06n@googlegroups.com>
<ed0dfb07-3b15-431d-a9d1-b3ed28f6d096n@googlegroups.com> <nnd$08d3555d$3b44d837@d33df914ac13dc27>
<cc5591bf-12b0-4b67-b3b2-c63004224d81n@googlegroups.com> <8bbd9e41-e13b-4af6-9d7f-7b53718523e2n@googlegroups.com>
<968c2cc6-abc6-4e67-a275-7af21b99471an@googlegroups.com> <d579bb45-e21e-4ea8-a98e-599d7073846en@googlegroups.com>
<b5d24a6c-1736-4c63-9c15-7b1780b9d5e4n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <3620042f-e5bc-417a-86a5-c5ade886607cn@googlegroups.com>
Subject: Re: new version of magic hexagon program
From: ahmed.melahi@univ-bejaia.dz (Ahmed MELAHI)
Injection-Date: Wed, 20 Sep 2023 19:00:17 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 29
 by: Ahmed MELAHI - Wed, 20 Sep 2023 19:00 UTC

Le mercredi 20 septembre 2023 à 17:32:27 UTC, Marcel Hendrix a écrit :
> On Wednesday, September 20, 2023 at 6:40:23 PM UTC+2, minforth wrote:
> > Ahmed MELAHI schrieb am Mittwoch, 20. September 2023 um 08:04:14 UTC+2:
> > > Le mercredi 20 septembre 2023 à 05:17:19 UTC, minforth a écrit :
> [..]
> > %row restrictions
> > alldifferent([X11,X12,X13, X14,X15,X16, X17,X18,X19]),
> > Underscore characters _ are so-called unbound variables.
> That is the same syntax minion-0.12 is using ( alldifferent )!
> It would be great to have a small Forth version of primitives like
> abs, alldiff, difference, diseq, hamming ineq, occurence, ...
>
> -marcel
Hi,
There is also PICAT and MiniZinc for constraint logic programming, they all share approximately the same syntaxe as prolog.
Prolog is "programmation logique" (logic programming), but not for constraint logic programming. Prolog use the module clp(fd) for finite domain constraint logic programming (module in the library to be consulted with use).
But Picat and MiniZinc are oriented for contraint logic programming.
look at :
http://picat-lang.org
https://www.minizinc.org
have good investigations
Bye

Re: new version of magic hexagon program

<28a2c922-437d-4eb8-b906-fcd905916f4fn@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24636&group=comp.lang.forth#24636

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:620a:2295:b0:76e:f494:ff9 with SMTP id o21-20020a05620a229500b0076ef4940ff9mr43104qkh.4.1695239114194;
Wed, 20 Sep 2023 12:45:14 -0700 (PDT)
X-Received: by 2002:a05:6808:140d:b0:3a7:86b2:1950 with SMTP id
w13-20020a056808140d00b003a786b21950mr1651321oiv.0.1695239113892; Wed, 20 Sep
2023 12:45:13 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Wed, 20 Sep 2023 12:45:13 -0700 (PDT)
In-Reply-To: <3620042f-e5bc-417a-86a5-c5ade886607cn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2001:1c05:2f18:6d00:71fb:d29d:3923:b581;
posting-account=-JQ2RQoAAAB6B5tcBTSdvOqrD1HpT_Rk
NNTP-Posting-Host: 2001:1c05:2f18:6d00:71fb:d29d:3923:b581
References: <3b96660a-56e6-4a84-ac82-2758fe6b9d06n@googlegroups.com>
<ed0dfb07-3b15-431d-a9d1-b3ed28f6d096n@googlegroups.com> <nnd$08d3555d$3b44d837@d33df914ac13dc27>
<cc5591bf-12b0-4b67-b3b2-c63004224d81n@googlegroups.com> <8bbd9e41-e13b-4af6-9d7f-7b53718523e2n@googlegroups.com>
<968c2cc6-abc6-4e67-a275-7af21b99471an@googlegroups.com> <d579bb45-e21e-4ea8-a98e-599d7073846en@googlegroups.com>
<b5d24a6c-1736-4c63-9c15-7b1780b9d5e4n@googlegroups.com> <3620042f-e5bc-417a-86a5-c5ade886607cn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <28a2c922-437d-4eb8-b906-fcd905916f4fn@googlegroups.com>
Subject: Re: new version of magic hexagon program
From: mhx@iae.nl (Marcel Hendrix)
Injection-Date: Wed, 20 Sep 2023 19:45:14 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: Marcel Hendrix - Wed, 20 Sep 2023 19:45 UTC

On Wednesday, September 20, 2023 at 9:00:18 PM UTC+2, Ahmed MELAHI wrote:
> ( picat and minizinc )

[..]

I instantly liked the CLP page in Wikipedia. I can see how to write a primitive
CLP interpreter by just following the text, using the Forth dictionary and
redefining words for a first start.

Simplifying the constraint store is also described but it remains to be seen
if the explanation is lucid enough for my foggy brain.

-marcel

Re: new version of magic hexagon program

<2023Sep21.092957@mips.complang.tuwien.ac.at>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24641&group=comp.lang.forth#24641

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.lang.forth
Subject: Re: new version of magic hexagon program
Date: Thu, 21 Sep 2023 07:29:57 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 24
Message-ID: <2023Sep21.092957@mips.complang.tuwien.ac.at>
References: <3b96660a-56e6-4a84-ac82-2758fe6b9d06n@googlegroups.com> <ed0dfb07-3b15-431d-a9d1-b3ed28f6d096n@googlegroups.com> <nnd$08d3555d$3b44d837@d33df914ac13dc27> <cc5591bf-12b0-4b67-b3b2-c63004224d81n@googlegroups.com> <8bbd9e41-e13b-4af6-9d7f-7b53718523e2n@googlegroups.com> <968c2cc6-abc6-4e67-a275-7af21b99471an@googlegroups.com> <d579bb45-e21e-4ea8-a98e-599d7073846en@googlegroups.com> <b5d24a6c-1736-4c63-9c15-7b1780b9d5e4n@googlegroups.com>
Injection-Info: dont-email.me; posting-host="5488005b62ec1cfd25855706d7a5ff27";
logging-data="3589568"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/GxWwDx8+MuSKN81Kbog3w"
Cancel-Lock: sha1:cC5EvCpj/P/YY4IqQWMbK1+Wxbo=
X-newsreader: xrn 10.11
 by: Anton Ertl - Thu, 21 Sep 2023 07:29 UTC

Marcel Hendrix <mhx@iae.nl> writes:
>On Wednesday, September 20, 2023 at 6:40:23=E2=80=AFPM UTC+2, minforth wrot=
>e:
>> %row restrictions=20
>> alldifferent([X11,X12,X13, X14,X15,X16, X17,X18,X19]),=20
>> Underscore characters _ are so-called unbound variables.
>
>That is the same syntax minion-0.12 is using ( alldifferent )!
>It would be great to have a small Forth version of primitives like
>abs, alldiff, difference, diseq, hamming ineq, occurence, ...

You find alldifferent in Forth in
<https://github.com/AntonErtl/magic-hexagon/blob/main/magichex.4th>.
This is good enough for, e.g., Sudoku. You can find an implementation
that also uses bounds information to implement more proactive variants
of arraysum (Var1+...+Varn=const) and #< in
<https://github.com/AntonErtl/magic-hexagon/blob/main/magichex-bounds.4th>.

- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: https://forth-standard.org/
EuroForth 2023: https://euro.theforth.net/2023

Re: new version of magic hexagon program

<8d0096c8-28b0-4110-b848-33da4271c6cen@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24645&group=comp.lang.forth#24645

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:6214:4001:b0:658:9f16:6056 with SMTP id kd1-20020a056214400100b006589f166056mr65799qvb.3.1695369286764;
Fri, 22 Sep 2023 00:54:46 -0700 (PDT)
X-Received: by 2002:a05:6808:2005:b0:3a7:8c2c:8c8e with SMTP id
q5-20020a056808200500b003a78c2c8c8emr3860434oiw.11.1695369286512; Fri, 22 Sep
2023 00:54:46 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Fri, 22 Sep 2023 00:54:46 -0700 (PDT)
In-Reply-To: <3620042f-e5bc-417a-86a5-c5ade886607cn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=79.224.99.246; posting-account=AqNUYgoAAADmkK2pN-RKms8sww57W0Iw
NNTP-Posting-Host: 79.224.99.246
References: <3b96660a-56e6-4a84-ac82-2758fe6b9d06n@googlegroups.com>
<ed0dfb07-3b15-431d-a9d1-b3ed28f6d096n@googlegroups.com> <nnd$08d3555d$3b44d837@d33df914ac13dc27>
<cc5591bf-12b0-4b67-b3b2-c63004224d81n@googlegroups.com> <8bbd9e41-e13b-4af6-9d7f-7b53718523e2n@googlegroups.com>
<968c2cc6-abc6-4e67-a275-7af21b99471an@googlegroups.com> <d579bb45-e21e-4ea8-a98e-599d7073846en@googlegroups.com>
<b5d24a6c-1736-4c63-9c15-7b1780b9d5e4n@googlegroups.com> <3620042f-e5bc-417a-86a5-c5ade886607cn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <8d0096c8-28b0-4110-b848-33da4271c6cen@googlegroups.com>
Subject: Re: new version of magic hexagon program
From: minforth@arcor.de (minforth)
Injection-Date: Fri, 22 Sep 2023 07:54:46 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3270
 by: minforth - Fri, 22 Sep 2023 07:54 UTC

Ahmed MELAHI schrieb am Mittwoch, 20. September 2023 um 21:00:18 UTC+2:
> Le mercredi 20 septembre 2023 à 17:32:27 UTC, Marcel Hendrix a écrit :
> > On Wednesday, September 20, 2023 at 6:40:23 PM UTC+2, minforth wrote:
> > > Ahmed MELAHI schrieb am Mittwoch, 20. September 2023 um 08:04:14 UTC+2:
> > > > Le mercredi 20 septembre 2023 à 05:17:19 UTC, minforth a écrit :
> > [..]
> > > %row restrictions
> > > alldifferent([X11,X12,X13, X14,X15,X16, X17,X18,X19]),
> > > Underscore characters _ are so-called unbound variables.
> > That is the same syntax minion-0.12 is using ( alldifferent )!
> > It would be great to have a small Forth version of primitives like
> > abs, alldiff, difference, diseq, hamming ineq, occurence, ...
> >
> > -marcel
> Hi,
> There is also PICAT and MiniZinc for constraint logic programming, they all share approximately the same syntaxe as prolog.
> Prolog is "programmation logique" (logic programming), but not for constraint logic programming. Prolog use the module clp(fd) for finite domain constraint logic programming (module in the library to be consulted with use).
> But Picat and MiniZinc are oriented for contraint logic programming.
> look at :
> http://picat-lang.org
> https://www.minizinc.org
> have good investigations

PICAT is the worthy successor of BProlog. But back to Forth:

Apart from the intellectually stimulating exercise, are there any
real-world applications to use Prolog-like inference engines
or even CLP within a Forth control or software solution?

Re: new version of magic hexagon program

<900c038d-9a15-40e9-bfa4-75dda35cb08bn@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24646&group=comp.lang.forth#24646

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:ad4:4e21:0:b0:656:262c:6928 with SMTP id dm1-20020ad44e21000000b00656262c6928mr96178qvb.2.1695377694760;
Fri, 22 Sep 2023 03:14:54 -0700 (PDT)
X-Received: by 2002:a05:6808:1b20:b0:3ad:ba05:a3be with SMTP id
bx32-20020a0568081b2000b003adba05a3bemr1145439oib.4.1695377694417; Fri, 22
Sep 2023 03:14:54 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Fri, 22 Sep 2023 03:14:53 -0700 (PDT)
In-Reply-To: <8d0096c8-28b0-4110-b848-33da4271c6cen@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=154.121.98.5; posting-account=KJSw4AoAAACRkUCek5r_78mFj6sHzH4C
NNTP-Posting-Host: 154.121.98.5
References: <3b96660a-56e6-4a84-ac82-2758fe6b9d06n@googlegroups.com>
<ed0dfb07-3b15-431d-a9d1-b3ed28f6d096n@googlegroups.com> <nnd$08d3555d$3b44d837@d33df914ac13dc27>
<cc5591bf-12b0-4b67-b3b2-c63004224d81n@googlegroups.com> <8bbd9e41-e13b-4af6-9d7f-7b53718523e2n@googlegroups.com>
<968c2cc6-abc6-4e67-a275-7af21b99471an@googlegroups.com> <d579bb45-e21e-4ea8-a98e-599d7073846en@googlegroups.com>
<b5d24a6c-1736-4c63-9c15-7b1780b9d5e4n@googlegroups.com> <3620042f-e5bc-417a-86a5-c5ade886607cn@googlegroups.com>
<8d0096c8-28b0-4110-b848-33da4271c6cen@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <900c038d-9a15-40e9-bfa4-75dda35cb08bn@googlegroups.com>
Subject: Re: new version of magic hexagon program
From: ahmed.melahi@univ-bejaia.dz (Ahmed MELAHI)
Injection-Date: Fri, 22 Sep 2023 10:14:54 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 4108
 by: Ahmed MELAHI - Fri, 22 Sep 2023 10:14 UTC

Le vendredi 22 septembre 2023 à 07:54:48 UTC, minforth a écrit :
> Ahmed MELAHI schrieb am Mittwoch, 20. September 2023 um 21:00:18 UTC+2:
> > Le mercredi 20 septembre 2023 à 17:32:27 UTC, Marcel Hendrix a écrit :
> > > On Wednesday, September 20, 2023 at 6:40:23 PM UTC+2, minforth wrote:
> > > > Ahmed MELAHI schrieb am Mittwoch, 20. September 2023 um 08:04:14 UTC+2:
> > > > > Le mercredi 20 septembre 2023 à 05:17:19 UTC, minforth a écrit :
> > > [..]
> > > > %row restrictions
> > > > alldifferent([X11,X12,X13, X14,X15,X16, X17,X18,X19]),
> > > > Underscore characters _ are so-called unbound variables.
> > > That is the same syntax minion-0.12 is using ( alldifferent )!
> > > It would be great to have a small Forth version of primitives like
> > > abs, alldiff, difference, diseq, hamming ineq, occurence, ...
> > >
> > > -marcel
> > Hi,
> > There is also PICAT and MiniZinc for constraint logic programming, they all share approximately the same syntaxe as prolog.
> > Prolog is "programmation logique" (logic programming), but not for constraint logic programming. Prolog use the module clp(fd) for finite domain constraint logic programming (module in the library to be consulted with use).
> > But Picat and MiniZinc are oriented for contraint logic programming.
> > look at :
> > http://picat-lang.org
> > https://www.minizinc.org
> > have good investigations
> PICAT is the worthy successor of BProlog. But back to Forth:
>
> Apart from the intellectually stimulating exercise, are there any
> real-world applications to use Prolog-like inference engines
> or even CLP within a Forth control or software solution?

Hi,
I don't know.
You can see these papers
https://vfxforth.com/flag/jfar/vol4/no4/article4.pdf
https://vfxforth.com/flag/jfar/vol4/no4/article3.pdf
I use matlab for my lectures (automatic control, system identification, artificial intelligence in control systems like fuzzy logic, artificial neural nets, neuro-fuzzy systems, GA, PSO, meta-heuristic and nature inspired optimization algorithms, probabilistic reasoning, expert systems, and use forth to express my ideas and to sharpen my understandings.
I looked to different software ( programming languages and others) to get ideas.
Bye

Re: new version of magic hexagon program

<fc6f829c-1c00-49d4-8883-07841073bb56n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24647&group=comp.lang.forth#24647

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:ad4:58ce:0:b0:63f:d7bd:a835 with SMTP id dh14-20020ad458ce000000b0063fd7bda835mr91915qvb.10.1695378971718; Fri, 22 Sep 2023 03:36:11 -0700 (PDT)
X-Received: by 2002:a05:6870:c7b3:b0:1d5:9692:731a with SMTP id dy51-20020a056870c7b300b001d59692731amr3416299oab.1.1695378971383; Fri, 22 Sep 2023 03:36:11 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!feeder.usenetexpress.com!tr3.iad1.usenetexpress.com!69.80.99.18.MISMATCH!border-1.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Fri, 22 Sep 2023 03:36:10 -0700 (PDT)
In-Reply-To: <8d0096c8-28b0-4110-b848-33da4271c6cen@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=154.121.98.5; posting-account=KJSw4AoAAACRkUCek5r_78mFj6sHzH4C
NNTP-Posting-Host: 154.121.98.5
References: <3b96660a-56e6-4a84-ac82-2758fe6b9d06n@googlegroups.com> <ed0dfb07-3b15-431d-a9d1-b3ed28f6d096n@googlegroups.com> <nnd$08d3555d$3b44d837@d33df914ac13dc27> <cc5591bf-12b0-4b67-b3b2-c63004224d81n@googlegroups.com> <8bbd9e41-e13b-4af6-9d7f-7b53718523e2n@googlegroups.com> <968c2cc6-abc6-4e67-a275-7af21b99471an@googlegroups.com> <d579bb45-e21e-4ea8-a98e-599d7073846en@googlegroups.com> <b5d24a6c-1736-4c63-9c15-7b1780b9d5e4n@googlegroups.com> <3620042f-e5bc-417a-86a5-c5ade886607cn@googlegroups.com> <8d0096c8-28b0-4110-b848-33da4271c6cen@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <fc6f829c-1c00-49d4-8883-07841073bb56n@googlegroups.com>
Subject: Re: new version of magic hexagon program
From: ahmed.melahi@univ-bejaia.dz (Ahmed MELAHI)
Injection-Date: Fri, 22 Sep 2023 10:36:11 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 41
 by: Ahmed MELAHI - Fri, 22 Sep 2023 10:36 UTC

Le vendredi 22 septembre 2023 à 07:54:48 UTC, minforth a écrit :
> Ahmed MELAHI schrieb am Mittwoch, 20. September 2023 um 21:00:18 UTC+2:
> > Le mercredi 20 septembre 2023 à 17:32:27 UTC, Marcel Hendrix a écrit :
> > > On Wednesday, September 20, 2023 at 6:40:23 PM UTC+2, minforth wrote:
> > > > Ahmed MELAHI schrieb am Mittwoch, 20. September 2023 um 08:04:14 UTC+2:
> > > > > Le mercredi 20 septembre 2023 à 05:17:19 UTC, minforth a écrit :
> > > [..]
> > > > %row restrictions
> > > > alldifferent([X11,X12,X13, X14,X15,X16, X17,X18,X19]),
> > > > Underscore characters _ are so-called unbound variables.
> > > That is the same syntax minion-0.12 is using ( alldifferent )!
> > > It would be great to have a small Forth version of primitives like
> > > abs, alldiff, difference, diseq, hamming ineq, occurence, ...
> > >
> > > -marcel
> > Hi,
> > There is also PICAT and MiniZinc for constraint logic programming, they all share approximately the same syntaxe as prolog.
> > Prolog is "programmation logique" (logic programming), but not for constraint logic programming. Prolog use the module clp(fd) for finite domain constraint logic programming (module in the library to be consulted with use).
> > But Picat and MiniZinc are oriented for contraint logic programming.
> > look at :
> > http://picat-lang.org
> > https://www.minizinc.org
> > have good investigations
> PICAT is the worthy successor of BProlog. But back to Forth:
>
> Apart from the intellectually stimulating exercise, are there any
> real-world applications to use Prolog-like inference engines
> or even CLP within a Forth control or software solution?
Hi again,
you can get a look at this too:
https://vfxforth.com/flag/jfar/vol4.html
Enjoy.

Re: new version of magic hexagon program

<nnd$0a375dbe$4bf524b7@368c73b5ae6b56a2>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24690&group=comp.lang.forth#24690

  copy link   Newsgroups: comp.lang.forth
Newsgroups: comp.lang.forth
References: <3b96660a-56e6-4a84-ac82-2758fe6b9d06n@googlegroups.com>
Subject: Re: new version of magic hexagon program
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
From: albert@cherry (none)
Originator: albert@cherry.(none) (albert)
Message-ID: <nnd$0a375dbe$4bf524b7@368c73b5ae6b56a2>
Organization: KPN B.V.
Date: Wed, 27 Sep 2023 13:46:24 +0200
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!feeder1.feed.usenet.farm!feed.usenet.farm!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feed.abavia.com!abe005.abavia.com!abp003.abavia.com!news.kpn.nl!not-for-mail
Lines: 112
Injection-Date: Wed, 27 Sep 2023 13:46:24 +0200
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
X-Received-Bytes: 4628
 by: none - Wed, 27 Sep 2023 11:46 UTC

In article <3b96660a-56e6-4a84-ac82-2758fe6b9d06n@googlegroups.com>,
Ahmed MELAHI <ahmed.melahi@univ-bejaia.dz> wrote:
>Hi,
>I rewrote the program for the magic hexagon.
>It appears elegant without any loss of performance. I think it is faster than the last versions I have already posted.
>
>Here begin the program:
>
>\ Place the integers 1..19 in the following Magic Hexagon of rank 3
>\ __A_B_C__
>\ _D_E_F_G_
>\ H_I_J_K_L
>\ _M_N_O_P_
>\ __Q_R_S__
>\ so that the sum of all numbers in a straight line (horizontal and diagonal)
>\ is equal to 38.
>
>: values 0 ?do 0 value loop ;
>19 values vA vB vC vD vE vF vG vH vI vJ vK vL vM vN vO vP vQ vR vS
>
>create marking_table 77 allot
>marking_table 77 1 fill
>
>marking_table 38 + value marked
>marked 20 erase
>
>: -- 2 .r 2 spaces ;
>: .mag_hex
> cr
> cr
> 4 spaces vA -- vB -- vC -- cr
> 2 spaces vD -- vE -- vF -- vG -- cr
> vH -- vI -- vJ -- vK -- vL -- cr
> 2 spaces vM -- vN -- vO -- vP -- cr
> 4 spaces vQ -- vR -- vS --
> cr
>;
>
>0 value nloops_prec
>0 value nloops
>0 value constraint_num
>20 value max_num_constraints
>create loop_loc max_num_constraints allot
>loop_loc max_num_constraints erase
>: mark 1 swap marked + c! ;
>: unmark 0 swap marked + c! ;
>: marked? marked + c@ 0= ;
>
>: .-- nloops 1+ to nloops postpone do postpone i ; immediate
>: ?, postpone dup postpone marked? postpone if postpone mark ; immediate
>: --> postpone to constraint_num 1+ to constraint_num nloops nloops_prec <> if 1 loop_loc constraint_num + c! nloops to nloops_prec then ; immediate
>: constraints_begin( marked 20 erase ;
>: finish: nloops 0 do postpone unloop loop postpone exit ; immediate
>: --- ; immediate
>: _begin_ marked 20 erase ;
>: | postpone unmark postpone else postpone drop postpone then loop_loc constraint_num + c@ if postpone loop then constraint_num 1- to constraint_num ; immediate
>: _end_ ; immediate
>
>: solve
> _begin_
> 20 1 .-- --> vA vA ?,
> 20 1 .-- --> vB vB ?,
> 38 vA vB + - --- --> vC vC ?,
> 20 1 .-- --> vG vG ?,
> 38 vC vG + - --- --> vL vL ?,
> 20 1 .-- --> vP vP ?,
> 38 vL vP + - --- --> vS vS ?,
> 20 1 .-- --> vR vR ?,
> 38 vS vR + - --- --> vQ vQ ?,
> 20 1 .-- --> vM vM ?,
> 38 vQ vM + - --- --> vH vH ?,
> 38 vA vH + - --- --> vD vD ?,
> 20 1 .-- --> vE vE ?,
> 38 vD vE + vG + - --- --> vF vF ?,
> 38 vB vF + vP + - --- --> vK vK ?,
> 38 vG vK + vR + - --- --> vO vO ?,
> 38 vP vO + vM + - --- --> vN vN ?,
> 38 vR vN + vD + - --- --> vI vI ?,
> 38 vH vI + vK + vL + - --- --> vJ vJ ?,
>
> finish: vJ | vI | vN | vO | vK | vF | vE | vD | vH | vM | vQ | vR | vS | vP | vL | vG | vC | vB | vA |
> _end_
>;
>
>
>Tested with: gforth, vfxforth anf iforth v4 (evaluation) on my PC:
>gforth: 4.5 ms
>vfxforth: 0.734 ms
>iforth: 0.976 ms
>

I have investigated the lisp versions. They run in the seconds (10-15)
where the Forth program runs in 33 ms (ciforth) 16 ms (gforth) and faster
still at home.
Both programs rely on macro expansion.

He las the comparison is not fair, because lisp calculates all solutions
(which doesn't make sense because all solutions are equivalent, but anyway.)

Could some one alter the program, such that all solutions are generated?
Then we can go boasting on comp.lang.lisp.

>Enjoy
>

Groetjes Albert
--
Don't praise the day before the evening. One swallow doesn't make spring.
You must not say "hey" before you have crossed the bridge. Don't sell the
hide of the bear until you shot it. Better one bird in the hand than ten in
the air. First gain is a cat spinning. - the Wise from Antrim -

Re: new version of magic hexagon program

<45ecaf3c-8eca-4347-90c9-f53c093cb448n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24691&group=comp.lang.forth#24691

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:620a:271b:b0:773:f669:bc27 with SMTP id b27-20020a05620a271b00b00773f669bc27mr16951qkp.4.1695817164312;
Wed, 27 Sep 2023 05:19:24 -0700 (PDT)
X-Received: by 2002:a05:6808:1814:b0:3ad:f3e6:66fe with SMTP id
bh20-20020a056808181400b003adf3e666femr827618oib.4.1695817164025; Wed, 27 Sep
2023 05:19:24 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Wed, 27 Sep 2023 05:19:23 -0700 (PDT)
In-Reply-To: <nnd$0a375dbe$4bf524b7@368c73b5ae6b56a2>
Injection-Info: google-groups.googlegroups.com; posting-host=41.111.207.115; posting-account=KJSw4AoAAACRkUCek5r_78mFj6sHzH4C
NNTP-Posting-Host: 41.111.207.115
References: <3b96660a-56e6-4a84-ac82-2758fe6b9d06n@googlegroups.com> <nnd$0a375dbe$4bf524b7@368c73b5ae6b56a2>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <45ecaf3c-8eca-4347-90c9-f53c093cb448n@googlegroups.com>
Subject: Re: new version of magic hexagon program
From: ahmed.melahi@univ-bejaia.dz (Ahmed MELAHI)
Injection-Date: Wed, 27 Sep 2023 12:19:24 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 5793
 by: Ahmed MELAHI - Wed, 27 Sep 2023 12:19 UTC

Le mercredi 27 septembre 2023 à 13:46:27 UTC+2, none albert a écrit :
> In article <3b96660a-56e6-4a84...@googlegroups.com>,
> Ahmed MELAHI <ahmed....@univ-bejaia.dz> wrote:
> >Hi,
> >I rewrote the program for the magic hexagon.
> >It appears elegant without any loss of performance. I think it is faster than the last versions I have already posted.
> >
> >Here begin the program:
> >
> >\ Place the integers 1..19 in the following Magic Hexagon of rank 3
> >\ __A_B_C__
> >\ _D_E_F_G_
> >\ H_I_J_K_L
> >\ _M_N_O_P_
> >\ __Q_R_S__
> >\ so that the sum of all numbers in a straight line (horizontal and diagonal)
> >\ is equal to 38.
> >
> >: values 0 ?do 0 value loop ;
> >19 values vA vB vC vD vE vF vG vH vI vJ vK vL vM vN vO vP vQ vR vS
> >
> >create marking_table 77 allot
> >marking_table 77 1 fill
> >
> >marking_table 38 + value marked
> >marked 20 erase
> >
> >: -- 2 .r 2 spaces ;
> >: .mag_hex
> > cr
> > cr
> > 4 spaces vA -- vB -- vC -- cr
> > 2 spaces vD -- vE -- vF -- vG -- cr
> > vH -- vI -- vJ -- vK -- vL -- cr
> > 2 spaces vM -- vN -- vO -- vP -- cr
> > 4 spaces vQ -- vR -- vS --
> > cr
> >;
> >
> >0 value nloops_prec
> >0 value nloops
> >0 value constraint_num
> >20 value max_num_constraints
> >create loop_loc max_num_constraints allot
> >loop_loc max_num_constraints erase
> >: mark 1 swap marked + c! ;
> >: unmark 0 swap marked + c! ;
> >: marked? marked + c@ 0= ;
> >
> >: .-- nloops 1+ to nloops postpone do postpone i ; immediate
> >: ?, postpone dup postpone marked? postpone if postpone mark ; immediate
> >: --> postpone to constraint_num 1+ to constraint_num nloops nloops_prec <> if 1 loop_loc constraint_num + c! nloops to nloops_prec then ; immediate
> >: constraints_begin( marked 20 erase ;
> >: finish: nloops 0 do postpone unloop loop postpone exit ; immediate
> >: --- ; immediate
> >: _begin_ marked 20 erase ;
> >: | postpone unmark postpone else postpone drop postpone then loop_loc constraint_num + c@ if postpone loop then constraint_num 1- to constraint_num ; immediate
> >: _end_ ; immediate
> >
> >: solve
> > _begin_
> > 20 1 .-- --> vA vA ?,
> > 20 1 .-- --> vB vB ?,
> > 38 vA vB + - --- --> vC vC ?,
> > 20 1 .-- --> vG vG ?,
> > 38 vC vG + - --- --> vL vL ?,
> > 20 1 .-- --> vP vP ?,
> > 38 vL vP + - --- --> vS vS ?,
> > 20 1 .-- --> vR vR ?,
> > 38 vS vR + - --- --> vQ vQ ?,
> > 20 1 .-- --> vM vM ?,
> > 38 vQ vM + - --- --> vH vH ?,
> > 38 vA vH + - --- --> vD vD ?,
> > 20 1 .-- --> vE vE ?,
> > 38 vD vE + vG + - --- --> vF vF ?,
> > 38 vB vF + vP + - --- --> vK vK ?,
> > 38 vG vK + vR + - --- --> vO vO ?,
> > 38 vP vO + vM + - --- --> vN vN ?,
> > 38 vR vN + vD + - --- --> vI vI ?,
> > 38 vH vI + vK + vL + - --- --> vJ vJ ?,
> >
> > finish: vJ | vI | vN | vO | vK | vF | vE | vD | vH | vM | vQ | vR | vS | vP | vL | vG | vC | vB | vA |
> > _end_
> >;
> >
> >
> >Tested with: gforth, vfxforth anf iforth v4 (evaluation) on my PC:
> >gforth: 4.5 ms
> >vfxforth: 0.734 ms
> >iforth: 0.976 ms
> >
> I have investigated the lisp versions. They run in the seconds (10-15)
> where the Forth program runs in 33 ms (ciforth) 16 ms (gforth) and faster
> still at home.
> Both programs rely on macro expansion.
>
> He las the comparison is not fair, because lisp calculates all solutions
> (which doesn't make sense because all solutions are equivalent, but anyway.)
>
> Could some one alter the program, such that all solutions are generated?
> Then we can go boasting on comp.lang.lisp.
>
> >Enjoy
> >
>
> Groetjes Albert
> --
> Don't praise the day before the evening. One swallow doesn't make spring.
> You must not say "hey" before you have crossed the bridge. Don't sell the
> hide of the bear until you shot it. Better one bird in the hand than ten in
> the air. First gain is a cat spinning. - the Wise from Antrim -
Hi,
To get the 12 solutions with printing them on the terminal:
In the word solve: put the word finish: in parenthesis ( comment it out), and before it add the word .mag_hex
with gforth: I got 265200 us ( printing included)
For timing, I use :
utime solve utime d>f d>f f- f. ." us"

Enjoy

Re: new version of magic hexagon program

<nnd$6b96b261$5296f3fa@2da2f88336c936f7>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24722&group=comp.lang.forth#24722

  copy link   Newsgroups: comp.lang.forth
Newsgroups: comp.lang.forth
Subject: Re: new version of magic hexagon program
References: <3b96660a-56e6-4a84-ac82-2758fe6b9d06n@googlegroups.com>
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
From: albert@cherry (none)
Originator: albert@cherry.(none) (albert)
Message-ID: <nnd$6b96b261$5296f3fa@2da2f88336c936f7>
Organization: KPN B.V.
Date: Fri, 29 Sep 2023 13:33:23 +0200
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!feeder1.feed.usenet.farm!feed.usenet.farm!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feed.abavia.com!abe006.abavia.com!abp002.abavia.com!news.kpn.nl!not-for-mail
Lines: 106
Injection-Date: Fri, 29 Sep 2023 13:33:23 +0200
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
X-Received-Bytes: 4392
 by: none - Fri, 29 Sep 2023 11:33 UTC

In article <3b96660a-56e6-4a84-ac82-2758fe6b9d06n@googlegroups.com>,
Ahmed MELAHI <ahmed.melahi@univ-bejaia.dz> wrote:
>Hi,
>I rewrote the program for the magic hexagon.
>It appears elegant without any loss of performance. I think it is faster than the last versions I have already posted.
>
>Here begin the program:
>
>\ Place the integers 1..19 in the following Magic Hexagon of rank 3
>\ __A_B_C__
>\ _D_E_F_G_
>\ H_I_J_K_L
>\ _M_N_O_P_
>\ __Q_R_S__
>\ so that the sum of all numbers in a straight line (horizontal and diagonal)
>\ is equal to 38.
>
>: values 0 ?do 0 value loop ;
>19 values vA vB vC vD vE vF vG vH vI vJ vK vL vM vN vO vP vQ vR vS
>
>create marking_table 77 allot
>marking_table 77 1 fill
>
>marking_table 38 + value marked
>marked 20 erase
>
>: -- 2 .r 2 spaces ;
>: .mag_hex
> cr
> cr
> 4 spaces vA -- vB -- vC -- cr
> 2 spaces vD -- vE -- vF -- vG -- cr
> vH -- vI -- vJ -- vK -- vL -- cr
> 2 spaces vM -- vN -- vO -- vP -- cr
> 4 spaces vQ -- vR -- vS --
> cr
>;
>
>0 value nloops_prec
>0 value nloops
>0 value constraint_num
>20 value max_num_constraints
>create loop_loc max_num_constraints allot
>loop_loc max_num_constraints erase
>: mark 1 swap marked + c! ;
>: unmark 0 swap marked + c! ;
>: marked? marked + c@ 0= ;
>
>: .-- nloops 1+ to nloops postpone do postpone i ; immediate
>: ?, postpone dup postpone marked? postpone if postpone mark ; immediate
>: --> postpone to constraint_num 1+ to constraint_num nloops nloops_prec <> if 1 loop_loc constraint_num + c! nloops to nloops_prec then ; immediate
>: constraints_begin( marked 20 erase ;
>: finish: nloops 0 do postpone unloop loop postpone exit ; immediate
>: --- ; immediate
>: _begin_ marked 20 erase ;
>: | postpone unmark postpone else postpone drop postpone then loop_loc constraint_num + c@ if postpone loop then constraint_num 1- to constraint_num ; immediate
>: _end_ ; immediate
>
>: solve
> _begin_
> 20 1 .-- --> vA vA ?,
> 20 1 .-- --> vB vB ?,
> 38 vA vB + - --- --> vC vC ?,
> 20 1 .-- --> vG vG ?,
> 38 vC vG + - --- --> vL vL ?,
> 20 1 .-- --> vP vP ?,
> 38 vL vP + - --- --> vS vS ?,
> 20 1 .-- --> vR vR ?,
> 38 vS vR + - --- --> vQ vQ ?,
> 20 1 .-- --> vM vM ?,
> 38 vQ vM + - --- --> vH vH ?,
> 38 vA vH + - --- --> vD vD ?,
> 20 1 .-- --> vE vE ?,
> 38 vD vE + vG + - --- --> vF vF ?,
> 38 vB vF + vP + - --- --> vK vK ?,
> 38 vG vK + vR + - --- --> vO vO ?,
> 38 vP vO + vM + - --- --> vN vN ?,
> 38 vR vN + vD + - --- --> vI vI ?,
> 38 vH vI + vK + vL + - --- --> vJ vJ ?,
>
> finish: vJ | vI | vN | vO | vK | vF | vE | vD | vH | vM | vQ | vR | vS | vP | vL | vG | vC | vB | vA |
> _end_
>;
>
>
>Tested with: gforth, vfxforth anf iforth v4 (evaluation) on my PC:
>gforth: 4.5 ms
>vfxforth: 0.734 ms
>iforth: 0.976 ms
>
>Enjoy

I'm puzzled why there is a 77 long array of bytes.
As far as I can see there are only 20 bytes used in the
`marked subtable.
I have decorated the `mark with { DUP . } and sure enough
the parameters passed to `mark are in the range 1..19.

Groetjes Albert
>
--
Don't praise the day before the evening. One swallow doesn't make spring.
You must not say "hey" before you have crossed the bridge. Don't sell the
hide of the bear until you shot it. Better one bird in the hand than ten in
the air. First gain is a cat spinning. - the Wise from Antrim -

Re: new version of magic hexagon program

<0cfbec25-d022-4200-85d0-d134a5838badn@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24723&group=comp.lang.forth#24723

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:ad4:4e6f:0:b0:656:2660:5c40 with SMTP id ec15-20020ad44e6f000000b0065626605c40mr50945qvb.11.1695992389485;
Fri, 29 Sep 2023 05:59:49 -0700 (PDT)
X-Received: by 2002:a05:6870:1a89:b0:1dd:1837:c70b with SMTP id
ef9-20020a0568701a8900b001dd1837c70bmr1525986oab.4.1695992389253; Fri, 29 Sep
2023 05:59:49 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!border-2.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Fri, 29 Sep 2023 05:59:48 -0700 (PDT)
In-Reply-To: <nnd$6b96b261$5296f3fa@2da2f88336c936f7>
Injection-Info: google-groups.googlegroups.com; posting-host=154.121.99.148; posting-account=KJSw4AoAAACRkUCek5r_78mFj6sHzH4C
NNTP-Posting-Host: 154.121.99.148
References: <3b96660a-56e6-4a84-ac82-2758fe6b9d06n@googlegroups.com> <nnd$6b96b261$5296f3fa@2da2f88336c936f7>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <0cfbec25-d022-4200-85d0-d134a5838badn@googlegroups.com>
Subject: Re: new version of magic hexagon program
From: ahmed.melahi@univ-bejaia.dz (Ahmed MELAHI)
Injection-Date: Fri, 29 Sep 2023 12:59:49 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 149
 by: Ahmed MELAHI - Fri, 29 Sep 2023 12:59 UTC

Le vendredi 29 septembre 2023 à 11:33:27 UTC, none albert a écrit :
> In article <3b96660a-56e6-4a84...@googlegroups.com>,
> Ahmed MELAHI <ahmed....@univ-bejaia.dz> wrote:
> >Hi,
> >I rewrote the program for the magic hexagon.
> >It appears elegant without any loss of performance. I think it is faster than the last versions I have already posted.
> >
> >Here begin the program:
> >
> >\ Place the integers 1..19 in the following Magic Hexagon of rank 3
> >\ __A_B_C__
> >\ _D_E_F_G_
> >\ H_I_J_K_L
> >\ _M_N_O_P_
> >\ __Q_R_S__
> >\ so that the sum of all numbers in a straight line (horizontal and diagonal)
> >\ is equal to 38.
> >
> >: values 0 ?do 0 value loop ;
> >19 values vA vB vC vD vE vF vG vH vI vJ vK vL vM vN vO vP vQ vR vS
> >
> >create marking_table 77 allot
> >marking_table 77 1 fill
> >
> >marking_table 38 + value marked
> >marked 20 erase
> >
> >: -- 2 .r 2 spaces ;
> >: .mag_hex
> > cr
> > cr
> > 4 spaces vA -- vB -- vC -- cr
> > 2 spaces vD -- vE -- vF -- vG -- cr
> > vH -- vI -- vJ -- vK -- vL -- cr
> > 2 spaces vM -- vN -- vO -- vP -- cr
> > 4 spaces vQ -- vR -- vS --
> > cr
> >;
> >
> >0 value nloops_prec
> >0 value nloops
> >0 value constraint_num
> >20 value max_num_constraints
> >create loop_loc max_num_constraints allot
> >loop_loc max_num_constraints erase
> >: mark 1 swap marked + c! ;
> >: unmark 0 swap marked + c! ;
> >: marked? marked + c@ 0= ;
> >
> >: .-- nloops 1+ to nloops postpone do postpone i ; immediate
> >: ?, postpone dup postpone marked? postpone if postpone mark ; immediate
> >: --> postpone to constraint_num 1+ to constraint_num nloops nloops_prec <> if 1 loop_loc constraint_num + c! nloops to nloops_prec then ; immediate
> >: constraints_begin( marked 20 erase ;
> >: finish: nloops 0 do postpone unloop loop postpone exit ; immediate
> >: --- ; immediate
> >: _begin_ marked 20 erase ;
> >: | postpone unmark postpone else postpone drop postpone then loop_loc constraint_num + c@ if postpone loop then constraint_num 1- to constraint_num ; immediate
> >: _end_ ; immediate
> >
> >: solve
> > _begin_
> > 20 1 .-- --> vA vA ?,
> > 20 1 .-- --> vB vB ?,
> > 38 vA vB + - --- --> vC vC ?,
> > 20 1 .-- --> vG vG ?,
> > 38 vC vG + - --- --> vL vL ?,
> > 20 1 .-- --> vP vP ?,
> > 38 vL vP + - --- --> vS vS ?,
> > 20 1 .-- --> vR vR ?,
> > 38 vS vR + - --- --> vQ vQ ?,
> > 20 1 .-- --> vM vM ?,
> > 38 vQ vM + - --- --> vH vH ?,
> > 38 vA vH + - --- --> vD vD ?,
> > 20 1 .-- --> vE vE ?,
> > 38 vD vE + vG + - --- --> vF vF ?,
> > 38 vB vF + vP + - --- --> vK vK ?,
> > 38 vG vK + vR + - --- --> vO vO ?,
> > 38 vP vO + vM + - --- --> vN vN ?,
> > 38 vR vN + vD + - --- --> vI vI ?,
> > 38 vH vI + vK + vL + - --- --> vJ vJ ?,
> >
> > finish: vJ | vI | vN | vO | vK | vF | vE | vD | vH | vM | vQ | vR | vS | vP | vL | vG | vC | vB | vA |
> > _end_
> >;
> >
> >
> >Tested with: gforth, vfxforth anf iforth v4 (evaluation) on my PC:
> >gforth: 4.5 ms
> >vfxforth: 0.734 ms
> >iforth: 0.976 ms
> >
> >Enjoy
> I'm puzzled why there is a 77 long array of bytes.
> As far as I can see there are only 20 bytes used in the
> `marked subtable.
> I have decorated the `mark with { DUP . } and sure enough
> the parameters passed to `mark are in the range 1..19.
> Groetjes Albert
> >
> --
> Don't praise the day before the evening. One swallow doesn't make spring.
> You must not say "hey" before you have crossed the bridge. Don't sell the
> hide of the bear until you shot it. Better one bird in the hand than ten in
> the air. First gain is a cat spinning. - the Wise from Antrim -
Hi,
The idea was to avoid the use of the test (range check) 20 1+ 1 within in the definition of the word ?,
We have
77 = 38 +38 +1
77 = (19 +19) + (19 +19) +1
For example: we know that 1<=vA<=19, ... 1<=vS<=19 and all different.
But when using the constraints for example the last one: 38 - (vH + vI + vK + vL) == vJ, we have to verify that vJ is between 1 and 19.
For extreme values (whithout considering all different) 38 - (19 + 19 +19 +19 ) = -38
and 38 - ( 0 + 0 + 0 + 0) = 38
so 38 - (-38) +1 = 77 possible values for vJ ...
But by filling the marking_table initially with 1s and and then erasing the 20 bytes from 38 to (38 +19) ( see the definition of marked) we can get:
0 ..........38......(38+19).....76
-38 .......0.............19......... 38
1111110000000001111111
So we can see that all the values from -38 to 0 and from 20 to 38 are marked initially and not changed when solving the problem.
but the values from 1 to 19 can be marked or unmarked.
using this trick, I avoided the tests for example 1<=vJ <=19 which is 1<=38-(vH+vI+ vK + vL)<=19.
Like this, I can use the word ?, in the same manner for the cases (for example):
20 1 .-- ---> vA vA ?, ( here I haven't to to check the range)
38 vA vB + - --- --> vC vC ?, ( here we must check the range, but using this trick I avoided range checking)
but one can use range checking with for example 20 1+ 1 within in the word ?,
I don't know if the expalanation is clear?

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor