Aai-2 wrote:
>
> Just for fun: seen on the seqfan forum.
>
>
> The sowing technique performed below could recall the Oware game.
>> Let's start with the integer 541, for example - which will be seen as
>> three bowls containing respectively 5, 4 and 1 seed (there are as many
>> bowls as figures in the original integer). At the start of a "game" one
>> takes all the seeds of the leftmost bowl, which are then sowed one by one
>> to the right (the last bowl on the right is followed by the first bowl on
>> the left). The bowl where the sowing ends is also the one by which the
>> next sowing begins. And so on. Here is how the 541 game starts (and
>> ends); the yellow color marks the starting bowl and the one where the
>> sowing ends:
>>
>> 5 4 1 0
>> 1 6 3 2
>> 2 7 1 2
>> 3 7 0 0
> The column at the right gives the starting index(instead of the yellow
> color marks in the text above).
>
> A straightforward method to generate the loop is as follows:
>
> owareX=: 3 :0
> r=. # s=. y
> z=.i.0 0
> j=.0
> whilst. (0~:j) +.-. y -: s do.
> n=.j{s
> s=.0 j } s
> for. i.n do.
> j=.r|j+1
> s=. j (>:@{)`[`]} s
> end.
> z=.z,s
> end.
> )
>
> owareX 5 4 1
> 1 6 3
> 2 7 1
> 3 7 0
> 1 8 1
> 0 9 1
> ...
> 1 9 0
> 0 10 0
> 3 3 4
> 5 4 1
>
> The above example has a loop length of 51.
>
> Of course I'm not very satisfied with the inner (explicit) loop and the
> speed.
>
> To give you some idea of speed: https://oeis.org/A216476 has a PARI
> program. Calling PARI/GP from J (using 'shell') with the following
> expression:
>
> (mind line wrapping)
>
> arg=.'n=799989;{my(o=n=Vecsmall(Str(n)), c, p=Mod(0, #n)); until(!p &
> o==n, c++; for(i=1,n[lift(p)+1]-n[lift(p)+1]=48, n[lift(p++)+1]++)); c}'
>
> ts'it=.GP <arg' [1]
> 12.9263 14400
>
> it
> 1534716
>
> The idea is to match or even beat that timing with J. Here's my best
> attempt so far (only counts loop length):
>
> oware3C=: 3 :0
> db=. 9,~,/(<9) 1&+ >/~i.r=. # s=. y
> c=.j=.0
> whilst. (0~:j) +.-. y -: s do.
> s=. (0 j } s)+(-j+1)|.db{~d=.j{s
> j=.r|j+d
> c=.1+c
> end.
> )
>
> ts 'oware3C 7 9 9 9 8 9'
> 30.9805 13440
>
> less than 2.5x slower.
>
>
> Anyway, something to chew on for those interested.
>
>
> [1] GP is a verb of mine that streamlines calling PARI/GP with 'shell'.
> It also does limited converting of GP output.
>
>
>
> --
> Met vriendelijke groet,
> @@i = Arie Groeneveld
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
>
Here is a somewhat faster version:
spread=.(1+9*])(-@i.@[,.[>/&i.>.)]
tab=.-@i. |."0 1"0 2 [: +/"2 - ]\"1 spread
owareX1=:3 :0
t=.tab]r=.#y
s=.,:c=.y+y{&{.t
i=.r|{.y
whilst.(-.c-:y)+.*i do.
d=.i{c
c=.c+d{i{t
i=.r|i+d
s=.s,c
end.
)
owareC1=:3 :0
t=.tab]r=.#y
c=.y+y{&{.t
i=.r|{.y
k=.1
whilst.(-.c-:y)+.*i do.
d=.i{c
c=.c+d{i{t
i=.r|i+d
k=.k+1
end.
)
Timings on a very loaded computer:
ts'c=.oware3C 7 9 9 9 8 9'
8.87146 26880
ts'c1=.owareC1 7 9 9 9 8 9'
7.75966 75264
c-:c1
1
c
1534716
The program works by constructing a lookup table t so that
the update of a configuration c is
c=.c+d{i{t
where d is the current digit at position i.
The main thing to consider when constructing the table is
that sum of digits is constant during the run
because seeds only go from one bowl to other(s),
so the largest possible number of seeds in a bowl
is 9 * number of bowls.
(similarly the largest possible no of seeds in a bowl
for a given configuration is just the sum of its digits.)
So
$tab 3
3 28 3
tab 3
0 0 0
_1 1 0
_2 1 1
_2 1 1
_3 2 1
_4 2 2
_4 2 2
_5 3 2
_6 3 3
...
8 8 _16
9 8 _17
9 9 _18
9 9 _18
Note that because of the conservation of seeds
every row must sum to zero.
--
View this message in context:
http://old.nabble.com/Oware-based-sequence-tp34433424s24193p34436182.html
Sent from the J Chat mailing list archive at Nabble.com.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm