I am not sure what I'm looking at -------
Now back to my collector obsessions ---
Here it is modified to use the oof - array and that does somewhat reduce the size and complexity ---
Now the following will demonstrate an interesting point ---- the process of removing errors - when I change course in what I'm doing --- In this case I had the clever idea about changing state because I was eliminating some other code ( specifically - nzp@ )
Anyone, one more pattern to match:
\-- find not contained in one array and put it into a second array
\-- for sudoku solver
\-- arraycollector.fs
include oofarray.fs
create vbp_ 9 cells allot
create vbpx_ 9 cells allot
42 42 42 42 42 42 42 42 42 9 int new[] 9 array : vbp
42 42 42 42 42 42 42 42 42 9 int new[] 9 array : vbpx
obj class precollector
method nextval@
method nextval!
method sv-next@
method sv-next!
method nv@
method nv!
method dump-collection
method nextval-prt
method reset-all
method sv-nextval
method reset-nextval
method check-unique
method store-input
method backup-current-vpb
method restore-current-vpb
method backup-current-vpbx
method restore-current-vpbx
method backup-current
method restore-current
method nextvalinc
method mode-set-1
method mode-init
method mode-get
method mode-get-prt
method mode-swt
method check-possible
method store-possible-lcl
method find-possible-lcl
method get-first
method set-this-collection-max
method get-this-collection-max
method process-empty-space
class;
precollector class arraycollector
cell var nextval
cell var sv-next
cell var inpv
cell var dupr
cell var lclvbp
cell var lclvbpx
cell var mode
cell var fnd
cell var collection-max
how:
: store-cell board line-no + col-no 9 * + nvp@ ! ;
: nextval@ nextval @ ;
: nextval! nextval ! ;
: nextvalinc nextval@ 1 + nextval! ;
: sv-next@ sv-next @ ;
: sv-next! sv-next ! ;
: nv! nextval@ 1 - vbp ! ;
: nv@ nextval@ 1 - vbp @ ;
: nvp! nextval@ 1 - vpbx ! ;
: nvp@ nextval@ 1 - vpbx @ ;
: reset-nextval sv-next@ nextval! ;
: sv-nextval nextval@ sv-next! ;
: nextval-prt cr s" nextval = " type nextval@ . ;
: reset-all 10 1 ?do i nextval! 42 nv! loop 1 nextval ! ;
: dump-collection sv-nextval 10 1 ?do i nextval! nv@ dup 10 < if . else emit then s" - " type loop reset-nextval ;
: check-unique inpv ! 0 dupr ! sv-nextval
10 1 ?do i nextval! nv@ inpv @ = if 1 dupr ! leave then loop
reset-nextval dupr @ ;
: get-first sv-nextval 1 nextval ! nv@ reset-nextval ;
: store-input check-unique 0 = if inpv @ nv! nextval@ 1 + nextval! then ;
: check-possible nextpval @ 1 - ;
: store-possible nvp! nextpval @ 1 + nextpval ! ;
: find-possible 0 fnd ! 10 1 ?do i dup check-val ! nextval! nv@ check-val @ = if 1 fnd ! then loop fnd @ 0 = if store-possible then ;
class;
.jpg)

No comments:
Post a Comment