Re: [Jprogramming] Bug in sorting?

2023-12-28 Thread 'Michael Day' via Programming

Also,  perhaps unsurprisingly,
   ~.@:/:~ p
crashes jqt in my Windows 11 installation of J 9.5

Strangely enough,
   ~./:~ p
seems not to crash;  however the results are inconsistent, and usually wrong!

Bill's assertion about the bug being related to the Boolean
type appears to hold in this installation too.

As for Jios,  Ian Clark's app for iPhones & iPads,  effectively J9.03 beta k,

defining
   datatype p =. #: 4 | 10?10
boolean

leads to no obvious problems of consistency,  correctness,  nor any JE crash.

Mike


On 28/12/2023 10:01, Marcin Żołek wrote:

Hello,
I was trying to run my code on j9.4 Linux, j9.4 MacOS, j9.5 MacOS and it 
crashes.

In terminal
/Applications/j9.5/bin/jconsole bug.ijs < input.txt
JE has crashed, likely due to an internal bug.  Please report the code which 
caused the crash, as well as the following printout, to the J programming forum.
Could not generate stack trace: no debug info in Mach-O executable (-1)
...
-
5 3 1 1[1]6692 abort  /Applications/j9.5/bin/jconsole bug.ijs < 
input.txt

bug.ijs:
":@((#/.~ +/@, ~.)@/:~)@(".;._2)&.stdin''

input.txt:
0 0
1 1
1 0
0 0
0 1
1 0
1 0
0 0
I figured out that the problem is with sorting:
 p =. 8 2 $ 0 0 1 1 1 0 0 0 0 1 1 0 1 0 0 0
 p
0 0
1 1
1 0
0 0
0 1
1 0
1 0
0 0
 /:~ p NB. returns various and wrong results
0 0
0 0
0 0
1 0
1 0
1 0
1 1
1 1

or

0 0
0 0
0 0
1 0
1 0
1 0
0 0
0 0
 ~.@:/:~ p NB. crashes jqt

Best regards,
Marcin
--
For information about J forums seehttp://www.jsoftware.com/forums.htm

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] j9.5.0-beta9 available

2023-12-14 Thread 'Michael Day' via Programming
I'm still getting an error, reported earlier for beta 7 (msg copied 
below), when using upgrade - still can't
see why.  The laptop has been through many on/off switches,  so it's not 
a transient error.


I think I've updated to beta9 by using the zip file.  Jversion info 
follows my sign-off.  I see the Library

verson is 9.5.5 .

However,  a similar problem occurs when I try to update addons using 
Package Manager.   A dialog box
diagnostic shows the same message as below in my earlier msg about beta 
version 7:

   "Connection failed: curl: (35) ... for the certificate"

So I can't keep my addons up-to-date unless I can download them 
"manually" from jsoftware.com,  but

I don't know/remember their location.

Bill had suggested updating the base libraries - are they in addons?

Thanks for any help,

Mike

JVERSION

Engine: j9.5.0-beta9/j64/windows

Build: commercial/2023-12-06T14:20:54/clang-16-0-6/SLEEF=1

Library: 9.5.5   is this wrong

Qt IDE: 2.5.1/6.5.3(6.5.3)

OS Ver: Windows 11 Version 22H2 10.0.22621

Platform: Win 64

Installer: j9.5 install

InstallPath: c:/d/j9.5

Contact: www.jsoftware.com


On 29/11/2023 18:56, Michael Day wrote:
Never mind vn 7 or 8,  I'm getting this error (I've added some 
line-feeds):


<<
   load'pacman'
   'upgrade'jpkg'jengine'

Connection failed: curl: (35) schannel: next InitializeSecurityContext 
failed:
Unknown error (0x80092012) - The revocation function was unable to 
check revocation for the certificate.


Connection failed:

curl: (35) schannel: next InitializeSecurityContext failed: Unknown 
error (0x80092012) -
The revocation function was unable to check revocation for the 
certificate.


upgrade - read jengine folder failed
|syntax error in je_update, unexecutable fragment (noun verb)
|   log    'upgrade - read jengine folder failed'return

>>

Any ideas?  My set-up or J-side?

(I could presumably reinstall from scratch,  but still...)

Thanks,

Mike

On 29/11/2023 18:00, Eric Iverson wrote:

j9.5.0-beta7 available

If you already run the beta, then upgrade is easy:
    load'pacman'
    'upgrade'jpkg'jengine'

To install 9.5 beta:
https://code.jsoftware.com/wiki/System/Installation/J9.5

Release notes:
https://code.jsoftware.com/wiki/System/ReleaseNotes/J9.5

Questions/bug reports/etc. should go to the beta forum.
--
For information about J forums see http://www.jsoftware.com/forums.htm



--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Get all indexes of a boolean array

2023-12-11 Thread 'Michael Day' via Programming

Sorry,  Viktor,  but I don't see your point.
(>:i.8)* 8 8 $ 1j2 # 1
generates an integer array, not a Boolean.

I agree (5&=) yields a boolean,  but is it in any way a general-purpose 
condition?


You might note that Henry Rich proposed the same solution to LdBeth's 
enquiry.

He (HR) might understand what you're driving at!

Cheers,

Mike

On 11/12/2023 17:09, 'Viktor Grigorov' via Programming wrote:

A fully tacit solution would encapsulate the predicate too, here parenthesized 
for emphasis:

    ($ #: [: I. [: (5&=) ,)  (>:i.8)* 8 8 $ 1j2 # 1
4 1
4 4
4 7



Dec 11, 2023, 17:01 byprogramm...@jsoftware.com:


I see Pablo has just replied,  but here's a similar/same approach, as a tacit
expression:

  b =. 0=3|i.2 3 4
  ($#:I.@,)  b
0 0 0
0 0 3
0 1 2
0 2 1
1 0 0
1 0 3
1 1 2
1 2 1
Might be of use,

Mike

Sent from my iPad


On 11 Dec 2023, at 10:06, LdBeth  wrote:

I've been running to too many situations that I uses  4$.$.y  a lot to
get indexes of all non zero elements to an array, I wonder if there
are any alternative ways to do that in J, especially when  y  is a
boolean array.

Also monadic I. only works for 1D array, while  ⍸ from APL works
for higher dimension cases, how to implement this in J?

LdBeth

--
For information about J forums seehttp://www.jsoftware.com/forums.htm


--
For information about J forums seehttp://www.jsoftware.com/forums.htm


--
For information about J forums seehttp://www.jsoftware.com/forums.htm

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] j9.5.0-beta7 available

2023-11-29 Thread 'Michael Day' via Programming

Never mind vn 7 or 8,  I'm getting this error (I've added some line-feeds):

<<
   load'pacman'
   'upgrade'jpkg'jengine'

Connection failed: curl: (35) schannel: next InitializeSecurityContext 
failed:
Unknown error (0x80092012) - The revocation function was unable to check 
revocation for the certificate.


Connection failed:

curl: (35) schannel: next InitializeSecurityContext failed: Unknown 
error (0x80092012) -

The revocation function was unable to check revocation for the certificate.

upgrade - read jengine folder failed
|syntax error in je_update, unexecutable fragment (noun verb)
|   log    'upgrade - read jengine folder failed'return

>>

Any ideas?  My set-up or J-side?

(I could presumably reinstall from scratch,  but still...)

Thanks,

Mike

On 29/11/2023 18:00, Eric Iverson wrote:

j9.5.0-beta7 available

If you already run the beta, then upgrade is easy:
load'pacman'
'upgrade'jpkg'jengine'

To install 9.5 beta:
  https://code.jsoftware.com/wiki/System/Installation/J9.5

Release notes:
  https://code.jsoftware.com/wiki/System/ReleaseNotes/J9.5

Questions/bug reports/etc. should go to the beta forum.
--
For information about J forums see http://www.jsoftware.com/forums.htm


--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Interesting Quora Problem:

2023-09-11 Thread 'Michael Day' via Programming
I wasn't going to comment - I'd worked up a clunky version for my own 
amusement,

but not very interesting...  but it does use power,  ^: .  So here goes:
(I later incorporated Ben Gorte's wheeze for limiting new digits to odd 
or even,

though I didn't force the 5.)

NB.  Given a partial answer,  append extra suitable digits.
app=:{{
if. 10=nd =. >: #":{.y do. y return.
elseif. 2 = nd do.
y  =.1 3 5 7 9 end.
par=. 2|<:{:y    NB. plagiarising Ben Gorte's idea re odds & evens!
q  =. q#~(=<.) nd%~ q=. ,(par+2*i.5) +/ 10*y
q#~(-:~.)@":"0 q
}}

Its time & space performance is ok:
   app^:_] 0
381654729
   ts'app^:_] 0'
0.0003165 16480

But I also came up with this loopy version - essentially the same as app 
- which I rather prefer:

day =: {{) v
r =. odds =. >:+:i.5
for_w. 2 + i.8 do.
   NB. get all width w divisible by w
   r =. w (]#~ (=<.)@%~) ,(odds - 0 = 2 | w) +/ 10 * r
NB. OR   r =. w (]#~ 0 = |) ,(odds - 0 = 2 | w) +/ 10 * r NB. less 
time,  more space

   NB. ensure no repeated digits
   r =. (#~ (-:~.)@":"0) r
NB. OR   r =. (#~ 

Re: [Jprogramming] polycubes

2023-07-20 Thread 'Michael Day' via Programming
In what I've just sent,  a couple of comments are missing their NB. at 
the very beginning

of my definitions:

NB. Prepare all 24 general 3x3 rotation matrices
mm =: +/ . *    NB. matrix multiply
I3 =: =i.3  NB. 3x3 identity matrix

It seems to load ok with this corrected.

Sorry,

Mike

On 20/07/2023 20:03, 'Michael Day' via Programming wrote:
[snipped all]
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] polycubes

2023-07-20 Thread 'Michael Day' via Programming

Mainly for Raul, as nobody else has commented,  at least publicly.

OK - I didn't mean to spend much time on this,  but I started wondering 
how a

coordinate representation would work.

The 3-d boolean representation is more intuitive,  but one advantage of the
coordinate approach is that the representation is less ragged,  at least 
when
we're dealing with all n-polycubes ;  I haven't yet dealt with sets of 
polycubes
with different numbers of component cubes.  So the set of 29 
penta-polycubes

has shape 29 5 3, for example.

The main problem with this approach is that I didn't quite solve the 
canonicity

task.  "Rotating" (and sorting) the coords does most of what's needed,  but
I've resorted to flipping to binary,  applying Raul's "canon" routine,  
then
flipping back to coordinates.  Naturally this adds to the computation 
time. It would

be much neater to remove all the isomers at the coordinate level.

So here's quite a long screed copied from my current script,  which 
includes
Raul's definitions.  I'll keep those in for completeness but will remove 
his inline
comments;  these definitions appear first. Apologies if I've omitted 
anything.


NB. https://en.wikipedia.org/wiki/Polycube
rotx=: |."2@(2 1&|:)  NB. rotate in the yz plane about the x axis
roty=: |.@(1 0 2&|:)  NB. rotate in the xz plane about the y axis
rotz=: |.@(2 1 0&|:)  NB. rotate in the xy plane about the z axis

rotall=: {{
  'X Y Z'=: y
  rotx^:X roty^:Y rotz^:Z x
}}"3 1&(4 4 4#:(i.20),24+i.4)

extend=: {{
  Y=. (-2+$y){.(1+$y){.y
  new=. ($#:I.@,)Y < (_1&|. +. 1&|. +. 1&|."2 +. _1&|."2 +. 1&|."1 +. 
_1&|."1) Y

  ~.new {{canon 1 (,:x)} y}}"1 3 Y
}}

offset=: {{ 1 i.~ +./+./"2 x |: *y }}
trim=: {{ (0 offset y)}."3 (1 offset y)}."2 (2 offset y)}."1 y }}
rtrim=: trim&.|.&.:(|."2)&.:(|."1)

canon=: {{ rtrim {. (/: +/@p:@I.@,"3) rotall trim y }}^:2

extendall=: {{ ~.;<@extend"3 y }}

NB.    #@> extendall&.>^:(i.8)<1 1 1 1$1
NB. 1 1 2 8 29 166 1023 6922

NB. My stuff follows (the copy & paste has removed my indentations!)
NB. I've repaired a couple of line-wraps - others might lurk!
NB. =
NB. Prepare all 24 general 3x3 rotation matrices

mm =: +/ . * matrix multiply

I3 =: =i.3 3x3 identity matrix


NB. define some helper matrices

Rx =: >1 0 0; 0 0 _1; 0 1 0 NB. pi/2 rotation around x axis

Ry =: _1 |. _1 |."1 Rx NB. y

Rz =: 1 |. 1 |."1 Rx NB. z

Rx3=: Rx mm Rx2=: mm~ Rx

Ry3=: Rx mm Ry2=: mm~ Ry

Rz3=: Rx mm Rz2=: mm~ Rz

Rxs=: I3,Rx,Rx2,:Rx3 NB. rotations by 0, pi/2, pi, 3pi/2 around x axis

Rys=: I3,Ry,Ry2,:Ry3 NB. rotations by 0, pi/2, pi, 3pi/2 around y axis

Rzs=: I3,Rz,Rz2,:Rz3 NB. rotations by 0, pi/2, pi, 3pi/2 around z axis


NB. combine them to generate all 24 rotation matrices


irots =: (4 4 4#:(i.20),24+i.4)


makeRots =: {{

r =. {{1 (0 1 2 ,each y) } 3 3$0}}"1 tap 3 NB. all 6 permutations of 3 
axes' labels ==> 3 x 1s in 3x3 matrices


s =. ~./:~,/1 _1,"0 1/,/(,"0)/~1 _1 NB. 8 sets of triples of signs

rs =. ,/s *"1/ r NB. output 48 (!) matrices

}}


NB. Can't see yet how to limit them to 24 except by comparison with 
Raul's rotall results on


NB. an irregular set of 3 points

# q=. {{/:~ {{y +"1 <./y}} y -"1 <./ y}}each ($#:I.@:,)each <"3 rotall 1 
(0 0 0;1 1 1;1 2 3) } 2 3 4$0 24


#r =. {{ /:~ {{y +"1 <./y}} y -"1 <./ y}}each<"2(0 0 0,1 1 1,:1 2 3) mm 
"2 Rots =: makeRots''48


+/ok =. r e. q

24

NB. Global set of rotation matrices to help with finding canonical 
coordinate representations


Rots =: (q i.~ ok#r){ ok# Rots NB. !!!


NB. Demonstration that the 24 Rots can be used for rotation analogously 
to Raul's rotall function


NB. compare with Raul's results on all flips of these 3 points - not 
face-adjacent cubes as it happens!


NB. but that doesn't matter much

NB. limited to 1st 16 for easier display...

NB. 16{.{{/:~ {{y +"1 <./y}} y -"1 <./ y}}each ($#:I.@:,)each <"3 rotall 
1 (0 0 0;1 1 1;1 2 3) } 2 3 4$0


NB. 
┌─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┐


NB. │0 0 0│0 2 1│0 1 2│0 0 1│0 1 3│0 0 1│0 0 0│0 3 0│0 0 3│0 2 0│0 2 3│0 
0 0│0 1 0│0 0 0│0 0 3│0 3 1│


NB. │1 1 1│2 1 1│0 2 0│1 1 0│1 1 1│1 2 1│1 0 2│1 1 0│0 1 1│1 1 1│1 0 0│2 
1 0│1 0 1│1 1 1│1 1 2│1 2 0│


NB. │1 2 3│3 0 0│1 0 3│3 2 0│2 0 0│2 3 0│2 1 3│2 0 1│1 2 0│3 0 1│1 1 2│3 
2 1│2 0 3│2 3 1│2 1 0│2 0 0│


NB. 
└─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┘



NB. 16{.{{ /:~ {{y +"1 <./y}} y -"1 <./ y}}each<"2(0 0 0,1 1 1,:1 2 3) 
mm "2 Rots


NB. 
┌─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┐


NB. │0 0 0│0 2 1│0 1 2│0 0 1│0 1 3│0 0 1│0 0 0│0 3 0│0 0 3│0 2 0│0 2 3│0 
0 0│0 1 0│0 0 0│0 0 3│0 3 1│


NB. │1 1 1│2 1 1│0 2 0│1 1 0│1 1 1│1 2 1│1 0 2│1 1 0│0 1 1│1 1 1│1 0 0│2 
1 0│1 0 1│1 1 1│1 1 2│1 2 0│


NB. │1 2 3│3 0 0│1 0 3│3 2 0│2 0 0│2 3 0│2 1 3│2 0 1│1 2 0│3 0 1│1 1 2│3 
2 1│2 0 3│2 3 1│2 1 0│2 0 0│


NB. 

Re: [Jprogramming] polycubes

2023-07-18 Thread 'Michael Day' via Programming

My not particularly small laptop manages to do that task in 19sec!

Running jpm for extendall ^: (i.7) - taking ca 2.5 sec on this m/c -
seems to reveal
0.08 sec for ~70500 reps in rotx,
0.26 - ~28 in roty,
0.33,  ~32 in rotz

I haven't looked deeply into the rots (!) - perhaps you could do something
otherthan use powers up to 3 .

The representation is nice & concise.  Wikipedia mentions dual graphs,
with cubes as nodes and face-face adjacency as links, but afaics, this
loses the 3rd dimension, even the 2nd in some cases; eg the V-tricube
is identical to the straight-3 polyomino in this rep.  Arthur O'Dwyer
@ quuxplusone.github.io, subject polycube snakes & ouroboroi
uses srd ..  as straight, right, down etc for the sub-set of singly 
connected

(I think) pc's.

All for now - got to go out,

Mike

On 15/07/2023 22:03, Raul Miller wrote:

https://en.wikipedia.org/wiki/Polycube

Today, I've been playing with polycubes (which are polyhedrons formed
from adjacent cubes).

This requires both a representation -- a rank 3 bit array works
nicely, and a mechanism for working with cubic symmetry. For that, I
went with:

rotx=: |."2@(2 1&|:)  NB. rotate in the yz plane about the x axis
roty=: |.@(1 0 2&|:)  NB. rotate in the xz plane about the y axis
rotz=: |.@(2 1 0&|:)  NB. rotate in the xy plane about the z axis

rotall=: {{
   'X Y Z'=. y
   rotx^:X roty^:Y rotz^:Z x
}}"3 1&(4 4 4#:(i.20),24+i.4)

Here, rotall gives all 24 rotations of cubic symmetry for a given
collection of 3d cubes represented by a bit array.

I decided to use a brute force mechanism to generate polycubes. In
other words, pad the array representation and add a single cube in
each of the locations adjacent to an existing cube:

extend=: {{
   Y=. (-2+$y){.(1+$y){.y
   new=. ($#:I.@,)Y < (_1&|. +. 1&|. +. 1&|."2 +. _1&|."2 +. 1&|."1 +.
_1&|."1) Y
   ~.new {{canon 1 (,:x)} y}}"1 3 Y
}}

Here, Y is the y argument with an extra 0 of padding in all
directions. And 'new' is the list of indices of empty locations
adjacent to cube locations.

I also need a verb (canon) to reduce these generated polycubes to
canonical form. A lot of this is removing unnecessary rows, columns
and planes of zeros. The rest of it is picking arbitrarily (but
consistently) from the 24 possible symmetric rotations:

offset=: {{ 1 i.~ +./+./"2 x |: *y }}
trim=: {{ (0 offset y)}."3 (1 offset y)}."2 (2 offset y)}."1 y }}
rtrim=: trim&.|.&.:(|."2)&.:(|."1)

canon=: {{ rtrim {. (/: +/@p:@I.@,"3) rotall trim y }}^:2

Finally, I want to work with all polycubes of a specific order, and to
get larger batch I can use;

extendall=: {{ ~.;<@extend"3 y }}

And, testing, this works:

#@> extendall&.>^:(i.8)<1 1 1 1$1
1 1 2 8 29 166 1023 6922

But, this is slow -- since I'm brute forcing all possibilities then
discarding duplicates, I need almost seven seconds on the little
laptop I'm currently using, to generate the above sequence.

(Also, for visualization of individual polycubes,
https://code.jsoftware.com/wiki/Scripts/Plot_3D works passibly well.)

Does anyone here have the geometric insight to improve on this approach?

Thanks,



--
For information about J forums see http://www.jsoftware.com/forums.htm


[Jprogramming] JQt startup time - again!

2023-07-16 Thread 'Michael Day' via Programming
I've recently been suffering a problem starting JQt under Windows 11 on 
this laptop.
Dr Google had suggested assigning administrator status to the startup a 
few months ago;
the problem seemed to have wandered off.  Lately the JQt terminal window 
has come
to life after perhaps 10 minutes,  so I've kept J open throughout the 
life of the Windows

session,  including the laptop's times in sleep/hibernation.

But today it's not appearing at all.  My latest attempt to start was at 
10:10 am - it's now

10:33.

Task manager shows it's running:
┌───┬─┬───┬┬───┬──┬┬┬───┐
│Name   │PID  │Status │Username│CPU│Memory│(..)│Architecture│Description│
├───┼─┼───┼┼───┼──┼┼┼───┤
│jqt.exe│15540│Running│mike_   │00 │18,912│K   │x64 │J  │
└───┴─┴───┴┴───┴──┴┴┴───┘

(Sorry if this doesn't display well but you should get the idea!)

This is the version info:
   JVERSION
Engine: j9.5.0-beta4/j64avx2/windows
Build: commercial/2023-07-07T22:38:55/clang-15-0-7/SLEEF=1
Library: 9.5.1
Platform: Win 64
Installer: j9.5 install
InstallPath: c:/d/j9.5
Contact: www.jsoftware.com

Quasi-immediate start up for the console & JHS versions,  which I hardly 
use unfortunately!


Thanks in advance,

Mike
PS - it hasnt opened yet @10:64am !
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Jios expiry?

2023-07-16 Thread 'Michael Day' via Programming

Yes, of course.  I'd forgotten that AppStore was the official option.
TestFlight was what it says on the tin!

Thanks,  Rob

Mike

On 16/07/2023 09:56, 'Rob B' via Programming wrote:

Mike,

The version I downloaded from the app store is still working on my iPad.

Regards, Rob.


On 16 Jul 2023, at 00:21, 'Mike Day' via Programming 
 wrote:

Mainly for Ian Clark & users of the new iPad J installation.

Trying to open JIOS just now on the iPad failed with this msg:

"jios 903.2" Beta has expired
[OK]

Can the current TestFlight copy (version 57?) be reinstated while Ian develops 
the
next one?

Thanks

Mike


Sent from my iPad
--
For information about J forums see http://www.jsoftware.com/forums.htm

--
For information about J forums see http://www.jsoftware.com/forums.htm


--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] jios 903.2 glitch

2023-07-10 Thread 'Michael Day' via Programming

Raul asked off-list for the definitions of gcd2x and foo.
I doubt if this is the problem,  but fwiw,  I didn't bother defining foo 
(!),

while here is Cliff's gcd2x .  (After all,   the Windows Js don't have
any trouble just loading the script,  even with an undefined foo.)

NB. From Cliff Reiter 2/4/23
NB. I dug up an old extended gcd to build an adverb for modular divide

NB. Find the gcd of two numbers
NB. and coef giving gcd as a linear combination of y

gcd2x=: 3 : 0
'r0 r1'=.y
's0 s1'=.1 0x
't0 t1'=.0 1x
while. r1 ~: 0 do.
   q=. r0 <.@% r1
   'r0 r1'=. r1,r0-q*r1
   's0 s1'=. s1,s0-q*s1
   't0 t1'=. t1,t0-q*t1
end.
r0,s0,t0
)

Cheers,
Mike

On 10/07/2023 20:19, 'Mike Day' via Programming wrote:

Sorry, that was a bit ambiguous.   I meant that load '...finite...' still 
results
in a syntax error if "gcd2x" is replaced by "foo",  in JIOS on this iPad.
I don't now have J903 beta-k on the laptop,  so can't investigate whether it's 
an
old beta problem.

Not desperately important, but puzzling,

Cheers,
Mike

Sent from my iPad


On 10 Jul 2023, at 19:15, Mike Day  wrote:

A gcd function,  courtesy Cliff Reiter,  but I get the same with a generic 
"foo" fn.
"mi" isn't invoked by the load.

M

Sent from my iPad


On 10 Jul 2023, at 18:23, Raul Miller  wrote:


What is gcd2x?

--
Raul


On Mon, Jul 10, 2023 at 12:49 PM 'Mike Day' via Programming
 wrote:

I'm probably missing the blindingly obvious but why does this happen in JIOS on my 
iPad but not in J903, J9.4 & J9.5 under Windows?

   JVERSION
Engine: j903/j64/iOS
beta-k: GPL3/2023-04-16T23:21:00
Platform: iOS/iPadOS
Version: 903.2 57
Installer: App Store
Contact: www.jsoftware.com

   load'~user/finite.ijs' NB. or any implicit load of finite.ijs
|syntax error
|   mi=:{{'r0 s0 t0'=:gcd2x m,y...}}"0
|[-277] 
/private/var/mobile/Containers/Data/Application/219E805B-EDC1-4B43-858D-814C13F48E94/Documents/j/user/finite.ijs

Here's mi:
NB. adverb giving divide (inverse) mod m
mi=: {{
'r0 s0 t0'=:gcd2x m,y
if. r0=1 do. m|t0 else. 1r0 end.
:
m|x*m mi y
}}"0

This "syntax error" also occurs when using the alternative method of definition,
mi =: 1 : 0"0
...
)

Thanks,

Mike


Sent from my iPad
--
For information about J forums see http://www.jsoftware.com/forums.htm

--
For information about J forums see http://www.jsoftware.com/forums.htm

--
For information about J forums see http://www.jsoftware.com/forums.htm


--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] GitHub Copilot anyone used this with J?

2023-05-09 Thread 'Michael Day' via Programming
I realise this thread is about experimenting with AI coding in J, so 
forgive me for
merely suggesting just another function  for a shortest derived 
palindrome formed

by prepending a string to a given string:

NB. Test palindrome-ness with a hook:
ispal =: -:|.

NB. Form palindrome given character string (or numeric vector) y
mdpal =: {{
   y,~ |.y}.~ (>:@i:&1) ispal \ y
}}

   mdpal 'abcd'
dcbabcd
   mdpal 'aacecaaa'
aaacecaaa

Appending a string might be better:
   mdpal 'abcbadefg'
gfedabcbadefg

   mdpal&.|. 'abcbadefg'  NB. simulate appending by working on reverse...
abcbadefgfedabcba
... though not in this case!

Just for fun,

Mike
PS - I am not  a Robot !?



On 07/05/2023 10:30, Thomas McGuire wrote:

Forgive me for keeping my own thread alive.

This article at Hackernoon put together a comparison of Coding AI bots using 
Leetcode questions as the stem:
https://hackernoon.com/how-ai-bots-code-comparing-bing-claude-co-pilot-gpt-4-and-bard
How AI Bots Code: Comparing Bing, Claude+, Co-Pilot, GPT-4 and Bard
hackernoon.com

Co-pilot was the easiest one for me to access so that’s why I chose it.

So following hackernoon’s lead here are the results on Leetcode question 214:

STEM:
NB. find the shortest palindrome for a string by adding letters to the front of 
it
shortpal =: 3 : 0

Copilot code:
NB. find the shortest palindrome for a string by adding letters to the front of 
it
shortpal =: 3 : 0
   's'=.y
   n=. #s
   for_i. n do.
 if. (s i.~ |. s) = s do.
   return. s
 end.
 s=. (i{a.) , s
   end.
)

Now the copilot code doesn’t work but the structure of this very un-J-like code 
is workable. I made some changes and got it working:
Copilot code fixed to work:
shortpal1 =: 3 : 0
   's'=.y
   n=. #s
   for_i. s do.
 if. s -: |. s do.
   return. s
 end.
 s=. (|.(_1-i_index){.s) , y
   end.
)

the changes were
- fixed the palindrome test to exit the function.
- fixed the building of the palindrome alway starting from the original string, 
catenating the reverse of the next increment of letters from the end of the 
string.



My J way of handling this problem is as follows:
NB. fpal - filter for palindromes, return the palindrome else return
NB.empty atom if not a palindrome
fpal=: 0&$`]@.(] -: |.)

NB. mkpalindrome - make palindrome by catenating reversed suffixes
NB.filter out the palindromes, remove empty boxed
NB.elements. Then get the shortest one created which
NB.is the tail of the boxed list. unbox the answer
mkpalindrome =: {{>@{:@-.&(<'') <@fpal@(,)@|.\.y}}

Running this on the leetcode simple examples:
mkpalindrome 'abcd'
dcbabcd
mkpalindrome 'aacecaaa'
aaacecaaa

Interestingly, in my previous email ,Copilot was able to discern the fork for 
average. In the palindrome case the fairly well known fork for palindrome 
testing was not discovered by Copilot.  Yet when I was developing my 'improved 
'J example. I happened to type the following:
NB. test if string is a palindrome

Copilot responded:
pal =: 3 : 0
   s=.y
   s -: |. s
)

This is close to the fork implementation.

I won’t post the code, but by using the {{}} method of function calls Copilot 
produced a child like attempt at a J one liner. When I used an open paren ‘(' 
to see if I could force a fork implementation it again gave a child like 
response for a J fork. Neither of the answers were working code.

Copilot is supposed to be pair programming with an AI bot. The github site 
indicates that in Python about 40% of the Copilot suggested Python code gets 
used. In other languages it is about 20%-25%.  In my limited use, I find that, 
rather than peers. I am the Senior programmer and Copilot is the High School 
intern just learning J. Still it’s a fun toy to play with when your programming.

The major question at this point is will these AI bots ever write good J code 
(or any array language code for that matter) or is the terseness of an array 
language too abstracted for AI to become proficient in it?



On May 5, 2023, at 12:07 AM, Thomas McGuire  wrote:

GitHub Copilot works under Visual Studio Code

GitHub user tikkanz published an extension for VS Code to edit and run J. 
Fairly easy to install.

VSCode then needs to have the Copilot extensions installed. It will ask you to 
login into your account and then you are all set.

I typed in the following into a new .ijs file:
NB. average list of numbers in language-j
ave =:

copilot then finished the line with and offered an example run of the function, 
so after I pressed the tab key I had the following:
NB. average list of numbers in language-j
ave =: +/ % #
ave 1 2 3 4 5

Now I know the fork for average is in about 20 different electronic documents. 
Still I was surprised that Copilot worked for J at all and more surprised that 
it picked up the fork paradigm from the language. I was expecting more of a 
functional approach such as:
ave1 =: 3 : 0
(+/ y) % #y
)

It costs 100 bucks per 

[Jprogramming] How should the new m. deal with missing reciprocals?

2023-04-27 Thread 'Michael Day' via Programming

Henry has introduced a new primitive for finite arithmetic,  m.

NuVoc already has an entry in
   https://code.jsoftware.com/wiki/NuVoc
and further details in
   https://code.jsoftware.com/wiki/Vocabulary/mdot

In accordance with the current beta,  we see on that page:
    "
    x % m. n y, and x ^ m. n y when y is negative, operate on the 
modular multiplicative

   inverse and give domain error if that inverse does not exist
   "

He and I have corresponded briefly about the best option here.  He 
suggests opening the

discussion to the J forum(s).

There is a possibility to change behaviour in the presence of "errors";  
instead of domain error,
the result could include "wrong" value(s),  probably 0 to keep the 
result integer,  or, much less
likely to be implemented,  positive or negative infinity - more 
obviously "wrong" but promoting

all values in an array from integer to floating.

Here's the behaviour for a prime modulus, m,   with all arguments in 
[1,...,m-1] :


   minv =: {{ 1 % m. x y }}
   mtimes =: {{ x * m. m y }}

   5 minv q =. >:i.4
1 3 2 4

   q (5 mtimes) 5 minv q
1 1 1 1

but, currently, for a simple composite modulus:
   10 minv r =. 1 3 7 9   NB. inverse mod 10 is well -defined for 1 3 7 
9 only

1 7 3 9

   10 minv q =. >:i.9
|domain error in minv, executing dyad %m.10
|   1    %m.x y

We could do-it-ourselves to ensure results with an inefficient 
get-around such as:

   minv0 =: {{ try.
1 % m. x y
catch.
  0   NB. or _ or __ ???
end.
}} " 0

   10 minv0 q =. >:i.9
1 0 7 0 0 0 3 0 9

but it would be more efficient for these "wrong" answers to be done under
the bonnet/hood.

We as users would of course need to be aware that 0s  would be 
unreliable items in

the array.

Henry points out that J routinely returns
   0 % 0
0

ALSO:
Despite a remark about monads on that page,  I believe Henry intends to
also allow the monad case for -  so that both these would result in 2 :
   0 ( - m. 5) 3
2
 ( - m. 5) 3
|valence error, executing monad -m.5
|verb has no monadic valence
|   (-m.5)3

The latter might as well behave as monad - does in its normal usage in 
the absence of

a modulus.

I suppose monadic * could work as well,  presumably always producing 1 .
There is perhaps a slight advantage of having monad defined for all of + 
- * % and (%.) ,
in that users could work up their own modular conjunctions & adverbs 
defined for any  u .


Any thoughts on reciprocals/negstive powers and perhaps on extending the 
support of

monad (u m. n) ?

Thanks,

Mike
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] J9.5 beta

2023-04-26 Thread 'Michael Day' via Programming

Oh - I forgot that we need to do
   install 'qtide'
in jconsole.

A reminder might be helpful for others!

Sorry, all - I was in a hurry - have now delayed myself and wasted the 
forum's time!


Mike


On 26/04/2023 15:53, Don Guinn wrote:

It installed ok for me on windows 11. The only problem I ran into was that
it didn't make the shortcuts on the screen.

On Wed, Apr 26, 2023 at 8:46 AM 'Michael Day' via Programming <
programm...@jsoftware.com> wrote:


Just tried installing from the zip-file, under Windows.

Perhaps nobody else has tried yet - am I the first to find jqt.exe
missing?  Perhaps I've
overlooked something...

Thanks,

Mike


On 23/04/2023 21:50, Eric Iverson wrote:

The 9.5 beta cycle has started!

https://code.jsoftware.com/wiki/System/Installation/J9.5

Install it now to help make it as stable as possible come release time,

but

also to steer it in directions that are relevant to you.
--
For information about J forums see http://www.jsoftware.com/forums.htm

--
For information about J forums see http://www.jsoftware.com/forums.htm


--
For information about J forums see http://www.jsoftware.com/forums.htm


--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] J9.5 beta

2023-04-26 Thread 'Michael Day' via Programming

Just tried installing from the zip-file, under Windows.

Perhaps nobody else has tried yet - am I the first to find jqt.exe 
missing?  Perhaps I've

overlooked something...

Thanks,

Mike


On 23/04/2023 21:50, Eric Iverson wrote:

The 9.5 beta cycle has started!

https://code.jsoftware.com/wiki/System/Installation/J9.5

Install it now to help make it as stable as possible come release time, but
also to steer it in directions that are relevant to you.
--
For information about J forums see http://www.jsoftware.com/forums.htm


--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Problem with integer arithmetic

2023-04-17 Thread 'Michael Day' via Programming

u m. n ?  I thought m. disappeared many versions ago, along with x. y. etc !
Could you provide an example?    And is m&|@u deprecated for other verbs u ?

Float results would be helpful.  Presumably an array would be returned 
as float

if at least one element needed to float,  as usual.

Thanks again,

Mike

On 16/04/2023 17:15, Henry Rich wrote:

I think I have figured out a way to return float when the result has been
made inaccurate.

We had no choice about m&|@^ for negative y: the behavior of that is
defined by the language, and it isn't modular.

u m. n is a much cleaner solution, and faster. m&|@^ is deprecated.

Henry Rich

On Sun, Apr 16, 2023, 11:51 AM 'Michael Day' via Programming <
programm...@jsoftware.com> wrote:


Thanks for this and your previous comment re  (-:<.@*<:)
I'm afraid I've only just noticed this later reply in my J mail folder.

I was going to grumble about x!y remaining integer even when the value
might be wrong.
Perhaps you or others might think of a suitable warning comment in NuVoc
about dyadic !  .
2!y could perhaps be treated as special case,  being a triangular
number,  y(y+1)/2 where
one could right shift whichever of y, y+1 is even, but presumably that
would involve too
much overhead.   Caveat Calculator,  I suppose.

BTW,  I see you've decided against implementing x m&|@^ y for negative
integer y, integer x,
and extended m.   (Though I don't remember m needing to be extended in
earlier discussions!)
A pity,  but it's been useful to learn that the idiom is well supported
for positive y.

Cheers,

Mike

On 14/04/2023 14:22, Henry Rich wrote:

As (x!y) is coded, the calculation is done in floating-point and then
converted to integer if the result will fit.  Loss of significance
during the calculation will make the result inaccurate.

I think it's a JE error to return an integer value when that value
might be wrong.  Unfortunately, the way the internal interfaces are,
it's difficult to leave the value as floating-point, so you cannot use
the fact that an integer was returned as a guarantee of accuracy.

Henry Rich

On 4/13/2023 11:34 AM, 'Michael Day' via Programming wrote:

Yet again I found myself resorting to Pari GP for a calculation;  my
J function had been giving
correct answers to a problem for lowish inputs,  but apparently gave
up at some stage for
higher values;  I then coded the calculation in Pari GP which gave
the same results for low
inputs,  but diverged from J at the business end.

Looking for inconsistencies between the two functions,  the
divergence seems to appear
around this case:

m =. 134235395
2^.m NB. plenty of room for multiplication in 64-bits???
27.0002

2!m
9009570568285316
datatype 2!m
integer

(-:<.@*<:)m
9009570568285316
((*<:)m)<.@%2
9009570568285315
_1 (33 b.) (*<:)m
9009570568285315

datatype (*<:)m
integer

So - why am I getting 2!m returned as integer but wrong?  If there's
overflow,
why isn't it a float?  Why does(-:<.@*<:)m  return the wrong
integer when
((*<:)m)<.@%2   yields the correct integer?

This was in J.04,
Engine: j9.4.2/j64avx2/windows
Build: commercial/2023-04-10T01:19:53/clang-15-0-7/SLEEF=1

I haven't checked behaviour in earlier releases.  I didn't try
extended integers
for this problem.

Thanks,

Mike



--
For information about J forums see http://www.jsoftware.com/forums.htm

--
For information about J forums see http://www.jsoftware.com/forums.htm

--
For information about J forums see http://www.jsoftware.com/forums.htm


--
For information about J forums see http://www.jsoftware.com/forums.htm


--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Problem with integer arithmetic

2023-04-16 Thread 'Michael Day' via Programming

Thanks for this and your previous comment re  (-:<.@*<:)
I'm afraid I've only just noticed this later reply in my J mail folder.

I was going to grumble about x!y remaining integer even when the value 
might be wrong.
Perhaps you or others might think of a suitable warning comment in NuVoc 
about dyadic !  .
2!y could perhaps be treated as special case,  being a triangular 
number,  y(y+1)/2 where
one could right shift whichever of y, y+1 is even, but presumably that 
would involve too

much overhead.   Caveat Calculator,  I suppose.

BTW,  I see you've decided against implementing x m&|@^ y for negative 
integer y, integer x,
and extended m.   (Though I don't remember m needing to be extended in 
earlier discussions!)
A pity,  but it's been useful to learn that the idiom is well supported 
for positive y.


Cheers,

Mike

On 14/04/2023 14:22, Henry Rich wrote:
As (x!y) is coded, the calculation is done in floating-point and then 
converted to integer if the result will fit.  Loss of significance 
during the calculation will make the result inaccurate.


I think it's a JE error to return an integer value when that value 
might be wrong.  Unfortunately, the way the internal interfaces are, 
it's difficult to leave the value as floating-point, so you cannot use 
the fact that an integer was returned as a guarantee of accuracy.


Henry Rich

On 4/13/2023 11:34 AM, 'Michael Day' via Programming wrote:
Yet again I found myself resorting to Pari GP for a calculation;  my 
J function had been giving
correct answers to a problem for lowish inputs,  but apparently gave 
up at some stage for
higher values;  I then coded the calculation in Pari GP which gave 
the same results for low

inputs,  but diverged from J at the business end.

Looking for inconsistencies between the two functions,  the 
divergence seems to appear

around this case:

m =. 134235395
   2^.m NB. plenty of room for multiplication in 64-bits???
27.0002

   2!m
9009570568285316
   datatype 2!m
integer

   (-:<.@*<:)m
9009570568285316
   ((*<:)m)<.@%2
9009570568285315
   _1 (33 b.) (*<:)m
9009570568285315

   datatype (*<:)m
integer

So - why am I getting 2!m returned as integer but wrong?  If there's 
overflow,
why isn't it a float?  Why does    (-:<.@*<:)m  return the wrong 
integer when

   ((*<:)m)<.@%2   yields the correct integer?

This was in J.04,
Engine: j9.4.2/j64avx2/windows
Build: commercial/2023-04-10T01:19:53/clang-15-0-7/SLEEF=1

I haven't checked behaviour in earlier releases.  I didn't try 
extended integers

for this problem.

Thanks,

Mike



--
For information about J forums see http://www.jsoftware.com/forums.htm


--
For information about J forums see http://www.jsoftware.com/forums.htm


--
For information about J forums see http://www.jsoftware.com/forums.htm


[Jprogramming] Problem with integer arithmetic

2023-04-13 Thread 'Michael Day' via Programming
Yet again I found myself resorting to Pari GP for a calculation;  my J 
function had been giving
correct answers to a problem for lowish inputs,  but apparently gave up 
at some stage for
higher values;  I then coded the calculation in Pari GP which gave the 
same results for low

inputs,  but diverged from J at the business end.

Looking for inconsistencies between the two functions,  the divergence 
seems to appear

around this case:

m =. 134235395
   2^.m NB. plenty of room for multiplication in 64-bits???
27.0002

   2!m
9009570568285316
   datatype 2!m
integer

   (-:<.@*<:)m
9009570568285316
   ((*<:)m)<.@%2
9009570568285315
   _1 (33 b.) (*<:)m
9009570568285315

   datatype (*<:)m
integer

So - why am I getting 2!m returned as integer but wrong?  If there's 
overflow,
why isn't it a float?  Why does    (-:<.@*<:)m  return the wrong integer 
when

   ((*<:)m)<.@%2   yields the correct integer?

This was in J.04,
Engine: j9.4.2/j64avx2/windows
Build: commercial/2023-04-10T01:19:53/clang-15-0-7/SLEEF=1

I haven't checked behaviour in earlier releases.  I didn't try extended 
integers

for this problem.

Thanks,

Mike



--
For information about J forums see http://www.jsoftware.com/forums.htm


[Jprogramming] Fwd: j901 903.2 (55) for iOS is now available to test.

2023-04-11 Thread 'Michael Day' via Programming

Thanks, Ian

Any release notes yet?

It appears to not overwrite or erase our own existing "user" and other 
folders such as "config",

nor their contents which we've set up in earlier version/s.

Cheers,

Mike

 Forwarded Message 
Subject:j901 903.2 (55) for iOS is now available to test.
Date:   Mon, 10 Apr 2023 12:29:35 + (GMT)
From:   "TestFlight" 
Reply-To:   earthspo...@gmail.com
To: mike_liz@tiscali.co.uk



iTunes Connect

j901, app icon


 j901 903.2 (55) is ready to test on iOS.

To test this app, open TestFlight 
 on your 
iOS device using iOS 16.2 or later and install the update.


By using j901, you agree that crash data as well as statistics about how 
you use j901 will be provided to Ian Clark and linked to your email 
address. Ian Clark may contact you regarding this information. Review 
the TestFlight Terms and Conditions, as well as the terms, policies, and 
practices of Ian Clark. Beta versions of apps may crash or result in 
data loss.


TestFlight is a service provided by Apple.
Terms of Service  
| Privacy Policy  | Unsubscribe 
 


Copyright © 2023 Apple Inc. One Apple Park Way
Cupertino, CA 95014, United States.
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Modular Matrix Divide

2023-04-05 Thread 'Michael Day' via Programming

Thanks, Cliff

Yes,  I also wrote a function some years ago, "m_gauss_jordan", merely 
converted from a
gauss-jordan I found somewhere - sorry not to attribute it...  I 
couldn't locate it under

addons/math,  but perhaps it's there.

I think the only changes were to replace the primitives * % + - and (+/ 
. *) by their modular
equivalents,  and not to worry about checking for tolerance as 
everything's finite integer.


m_gauss_jordan=: 3 : 0
0 m_gauss_jordan y
:
M   =. x

NB. modular equivalents of %, *, +, -, and (+/ . *)
div =. M mdivide
by  =. M mtimes
add =. M madd
sub =. add -
mby =. add/ . by

m    =. y
'r c'=. $m
rws  =. i.r
i    =. j=. 0
max  =. i.>./
while. (i:i
  end.
  j=. >:j
end.
m
)

It can do some of your Md calculation:
   a
4 1 3
1 0 3
1 1 1

  [aa =:  (,.=@i.@#) a
4 1 3 1 0 0
1 0 3 0 1 0
1 1 1 0 0 1

   [ai =:  3}."1 ] 17 m_gauss_jordan aa
15  7  2
 7 12 11
12 15  5

It doesn't manage to work with your A =: a, 1 , though:

   17 m_gauss_jordan A,.=i.4
1 0 0 15  7 0  2
0 1 0  7 12 0 11
0 0 1 12 15 0  5
0 0 0  0  0 1 16

Interesting,

Mike


On 05/04/2023 20:09, Clifford Reiter wrote:

load modular_matrix_divide.ijs
open script for function/adverb definitions

gcd's, gauss-jordan, modulo divide and modular matrix divide


I think this is a draft of the modular matrix system solver that I imagined
a couple decades ago. It may still have some rough edges/mistakes.

gcd2x 51 119

17 _2 1

_2 1 +/ . * 51 119

17

NB. more general than integer

gcd2x 53r3 20

1r3 17 _15

NB. md is meant to be like % mod m

7 md 6

6

m md i.&.<:m=:7

1 4 5 2 3 6

m md i.&.<:m=:8

1 _ 3 _ 5 _ 7

5 m md i.&.<:m

5 _ 7 _ 1 _ 3

NB. Md is meant to be like %. mod m

-/ . * a=:?.3 3$5

_7

a

4 1 3

1 0 3

1 1 1

]ai=: 17 Md a

15 7 2

7 12 11

12 15 5

17|ai mp a

1 0 0

0 1 0

0 0 1

1 2 3 (17) Md a

1 13 6

NB. Non square case includes:

NB. Can take an independent direction b and

NB. make one, B, orthogonal to the columns of A --

NB. as in Gram-Schmidt even if not "least squares fit"

$A=:a,1

4 3

17 Md A NB. Left inverse

15 7 1 1

7 12 14 14

12 15 11 11

17|(17 Md A)mp A

1 0 0

0 1 0

0 0 1

b=:1 2 3 4

s=:b 17 Md A

17| (B=:17|b-A mp s) mp A

0 0 0

B

0 0 8 9
--
For information about J forums see http://www.jsoftware.com/forums.htm


--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Modular arithmetic support

2023-04-04 Thread 'Michael Day' via Programming

Thanks,  Chris,  and Cliff too.

Yes,  a mod inverse helps a lot.  Once you've got an inverse, it's easy 
to derive a modular divide,  or vice

versa.

inversep in primutil.ijs is well defined for a prime modulus - the name 
"primutil" does of course imply

a prime modulus.
inversep also appears to work ok for those numbers in the ring of 
integers modulo non-prime modulus.


eg members of the ring modulo 10 are {1 3 7 9}
   {{ y,:y (10 mtimes) (10)"0 y}} 1 3 7 9
1 3 7 9
1 1 1 1
   {{ y,:y (10 mtimes) (10)"0 y}} 1 3 7 9
1 3 7 9
1 1 1 1

I find rather better performance with my mrecip:
ts =: 6!:2 , 7!:2@]

   1 p: 19
1

   ts'10009 mrecip 99000 + >:i.1007'
0.0061255 22592
   ts'10009 inversep"0] 99000 + >:i.1007'
0.0798054 97160
   ts'10009 mi"0] 99000 + >:i.1007'
0.0908823 174192

A bit surprising as the Extended Euler Algorithm is supposed to be best
for getting a modular inverse.

  19 (mrecip-:inversep"0) 99000 + >:i.1007
1
   19 ((19 mi)"0 @] -:inversep"0) 99000 + >:i.1007
1

Here's mrecip:

mrecip =: {{
y (x&|@^) <: 5 p: x
}}"0

As for inversep,  and Cliff's mi,  mrecip is well-defined for prime x,  
and also for composite

x for y in x's ring,  ie where 1 = x +. y

Results are NOT reliable for arguments not coprime with the modulus.

Thanks,

Mike

On 03/04/2023 16:22, chris burke wrote:

Cliff

There are some mod functions in the math/misc addon, e.g. this gives
Mike Day's table

load 'math/misc/primutil'
f=: (17 timesmod) (17)
2 3 4 f"0 table >:i.8
+---+-+
|f"0|1  2  3 4  5  6  7  8|
+---+-+
|2  |2  1 12 9 14  6 10 13|
|3  |3 10  1 5  4  9 15 11|
|4  |4  2  7 1 11 12  3  9|
+---+-+

Any improvements welcome, thanks.

Chris

On Mon, Apr 3, 2023 at 5:49 AM Clifford Reiter  wrote:

I dug up an old extended gcd to build an adverb for modular divide

NB. Find the gcd of two numbers

NB. and coef giving gcd as a linear combination of y

gcd2x=: 3 : 0

'r0 r1'=.y

's0 s1'=.1 0x

't0 t1'=.0 1x

while. r1 ~: 0 do.

q=. r0 <.@% r1

'r0 r1'=. r1,r0-q*r1

's0 s1'=. s1,s0-q*s1

't0 t1'=. t1,t0-q*t1

end.

r0,s0,t0

)

gcd2x 51 119

17 _2 1

_2 1 +/ . * 51 119

17

NB. adverb giving divide (inverse) mod m

mi=:1 : 0"0

'r0 s0 t0'=:gcd2x m,y

if. r0=1 do. m|t0 else. 1r0 end.

:

m|x*m mi y

)

17 mi 6

3

NB. Mike Day's Table

2 3 4 (17 mi)table >:i.8

+-+-+

| |1 2 3 4 5 6 7 8|

+-+-+

|2|2 1 12 9 14 6 10 13|

|3|3 10 1 5 4 9 15 11|

|4|4 2 7 1 11 12 3 9|

+-+-+


I have some questions regarding system solving modulo m that I will offer
in a new thread in a few days.

Best, Cliff

On Thu, Mar 30, 2023 at 12:11 PM Clifford Reiter
wrote:


I think I recall a conversation, some decades ago, with Roger about
whether specifying a modulus for system solving makes sense for J. I
thought maybe that was a use for the fit conjunction but now think that
would be a poor choice for such a numeric function. I have vague memories
of J essays on guass-jordan row reduction and extended gcds but didn't find
them poking around J help.
They could be useful for what I had in mind and modular inverses would be
part of that. Perhaps someone has those handy and could offer an addon? New
adverbs giving b m %.: a and m %.: a anyone?
Best, Cliff

On Wed, Mar 29, 2023 at 5:02 PM 'Michael Day' via Programming <
programm...@jsoftware.com> wrote:


While this primitve works nicely in an example:

 (2 3 4) (17&|@*)/ table >:i.8
+---+-+
|17&|@*/|1 2  3  4  5  6  7  8|
+---+-+
|2  |2 4  6  8 10 12 14 16|
|3  |3 6  9 12 15  1  4  7|
|4  |4 8 12 16  3  7 11 15|
+---+-+

I find this less satisfying:
 (2 3 4) (17&|@%)/ table >:i.8
+---+---+
|17&|@%/|1   234   567 8|
+---+---+
|2  |2   1 0.67  0.5 0.4 0.33 0.285714  0.25|
|3  |3 1.51 0.75 0.6  0.5 0.428571 0.375|
|4  |4   2  1.31 0.8 0.67 0.571429   0.5|
+---+---+

I have a function which does what one would expect.  I'll rename it as
m17div here,  details unimportant for this discussion:
 (2 3 4) m17div/ table >:i.8
+---+-+
|m17div/|1  2  3 4  5  6  7  8|
+---+-+
|2  |2  1 12 9 14  6 10 13|
|3  |3 10  1 5  4  9 15 11|
|4  |4  2  7 1 11 12  3  9|
+---+-+
( eg 3 % 2 == 10 mod 17  because 3 = 17 | 2 * 10 )

Would anyone else find this return of integer results useful or is it
better
to force a floating output?

(Henry 

[Jprogramming] Modular arithmetic support

2023-03-29 Thread 'Michael Day' via Programming

While this primitve works nicely in an example:

   (2 3 4) (17&|@*)/ table >:i.8
+---+-+
|17&|@*/|1 2  3  4  5  6  7  8|
+---+-+
|2  |2 4  6  8 10 12 14 16|
|3  |3 6  9 12 15  1  4  7|
|4  |4 8 12 16  3  7 11 15|
+---+-+

I find this less satisfying:
   (2 3 4) (17&|@%)/ table >:i.8
+---+---+
|17&|@%/|1   2    3    4   5    6    7 8|
+---+---+
|2  |2   1 0.67  0.5 0.4 0.33 0.285714  0.25|
|3  |3 1.5    1 0.75 0.6  0.5 0.428571 0.375|
|4  |4   2  1.3    1 0.8 0.67 0.571429   0.5|
+---+---+

I have a function which does what one would expect.  I'll rename it as
m17div here,  details unimportant for this discussion:
   (2 3 4) m17div/ table >:i.8
+---+-+
|m17div/|1  2  3 4  5  6  7  8|
+---+-+
|2  |2  1 12 9 14  6 10 13|
|3  |3 10  1 5  4  9 15 11|
|4  |4  2  7 1 11 12  3  9|
+---+-+
( eg 3 % 2 == 10 mod 17  because 3 = 17 | 2 * 10 )

Would anyone else find this return of integer results useful or is it 
better

to force a floating output?

(Henry tells me that m&|@^ returns integer results,  working ok when m^2
can be represented as a non-extended integer.)

Thanks,

Mike

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Applying a cyclic gerund

2023-02-26 Thread 'Michael Day' via Programming

Oh, sorry.

However, if you look at the copy of your message below my
reply,   both still appearing hereunder,  you'll see something rather like

|
|: ; ((]`".) @. isChar) &.> '3';33;'9 99';12 13;1;2;'10 11 1e6'
|

(I've typed in the 3 vertical bars at the left-hand side!)
In any case,  it looked a bit odd!  As I recall,  what the iPad showed 
at the

lhs resembled monadic transpose, |: !    It definitely wasn't >:   .

The iPad doesn't have the message any more,  so I can't easily check 
directly.


No matter - sorry I commented on that,   but the essential points were 
made,

that there are pleasing ways of dealing with these mixed types which can
avoid using gerunds.

Cheers,

Mike

On 26/02/2023 19:19, Devon McCormick wrote:

The second result was simply an increment to demonstrate that the result is
numeric.

On Sun, Feb 26, 2023 at 6:28 AM 'Mike Day' via Programming <
programm...@jsoftware.com> wrote:


This is quite nice,  though nothing to do with gerunds as such!

; ]&.":each '3';33;'9 99';12 13;1;2;'10 11 1e6'
3 33 9 99 12 13 1 2 10 11 100
I have been known to use ".@":  - but using under only just occurred to me!

This also works:
   abc =. 2345
;   ]&.":  each '3';33;'9 99';12 13;1;2;'10 11 1e6';'abc'
3 33 9 99 12 13 1 2 10 11 100 2345

though using names could prove difficult without building in some checks:
;   ]&.":  each '3';33;'9 99';12 13;1;2;'10 11 1e6';'def';'abc'   NB.
def is undefined
3 33 9 99 12 13 1 2 10 11 100 2345
Checking the boxed form for empty elements might suffice.

BTW, I'm puzzled by Devon's second "result": 4 34 10 etc.  Perhaps a slip
with
copy?

Cheers,

Mike

Sent from my iPad


On 26 Feb 2023, at 09:48, Devon McCormick  wrote:

If you don't want to be at the mercy of your data's ordering, you could
selectively convert to numeric or not:
   isChar=: ' ' -: [: ({.) 0 $ ]
   ; ((]`".) @. isChar) &.> '3';33;'9 99';12 13;1;2;'10 11 1e6'
3 33 9 99 12 13 1 2 10 11 100

: ; ((]`".) @. isChar) &.> '3';33;'9 99';12 13;1;2;'10 11 1e6'

4 34 10 100 13 14 2 3 11 12 101


On Sat, Feb 25, 2023 at 4:39 PM Henry Rich 

wrote:

Now that gerund"n applies gerund cyclically, the need for the oblique
trick is reduced.

Henry Rich

On 2/25/2023 3:26 PM, neit...@gaertner.de wrote:

I want to convert the second one into numerical data
Can you simplify the above expression?

Applying a gerund cyclically, as asked for in the subject:

   ] list =. ;: 'foo 1 bar 2.17 baz 3.14'
+---+-+---++---++
|foo|1|bar|2.17|baz|3.14|
+---+-+---++---++

, ]`(".each)/.  list
+---+-+---++---++
|foo|1|bar|2.17|baz|3.14|
+---+-+---++---++

(,: datatype each)  , ]`(".each)/.  list
+---+---+---++---++
|foo|1  |bar|2.17|baz|3.14|
+---+---+---++---++
|literal|boolean|literal|floating|literal|floating|
+---+---+---++---++


Obliquing over a vector is often overlooked.  It picks up every item
as a singleton "diagonal".  The final "," is required to compensate
for that.

  Martin Neitzel
--
For information about J forums see http://www.jsoftware.com/forums.htm

--
For information about J forums see http://www.jsoftware.com/forums.htm



--

Devon McCormick, CFA

Quantitative Consultant
--
For information about J forums see http://www.jsoftware.com/forums.htm

--
For information about J forums see http://www.jsoftware.com/forums.htm





--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] JHS addon update available

2023-02-12 Thread 'Michael Day' via Programming

Not surprising!

Possibly more important - though it's probably something mysterious in 
my configuration:

I got to the bit about 20 second delay and double use of ctrl-c.
First time I tried,  I forgot to do the break in the console window.
Second time,  double break in the console closed the console, with this 
resulting message

in a dialogue box in the jijx session:

   127.0.0.1:65001 says
   ev_advance_click failed: NetworkError: Failed to execute 'send' on
   'XMLHttpRequest': Failed to load 'http://127.0.0.1:65001/jijx'.
                        [OK]

So then, a mini-experiment:
After restarting JHS,  with the jijx tab waiting for input,  I tried a 
single ctrl-c in
the console.   That session closes after a slight delay (1/2 - 1 
second?) , and the
jijx session fails to respond to input,  though the error box doesn't 
appear.

This suggests a problem in the console set-up/configuration rather than JHS
itself(?)

I'm running Windows 11.  Here's the installation info:

   JVERSION
Engine: j904/j64avx2/windows
Beta-k: commercial/2023-01-24T04:48:26
Library: 9.04.11
Qt IDE: 2.0.3/6.2.4(6.2.4)
Platform: Win 64
Installer: J904 install
InstallPath: c:/d/j904-beta
Contact: www.jsoftware.com

Apologies if I've misunderstood something!

Cheers,

Mike

On 12/02/2023 14:30, Eric Iverson wrote:

It has been there for years! Fixed in the next release.

On Sun, Feb 12, 2023 at 8:01 AM 'Michael Day' via Programming <
programm...@jsoftware.com> wrote:


Thanks.

NB.  In the comment,  very early in menu>tour>overview :
 " NB. sum over - (Note Bene) starts comment "
please note that the "N" in "NB" stands for "Nota", not "Note" .

Sorry for pedantry,  but it might put off a potential fan! Apologies, too,
if it's been there for years,

Cheers,

Mike

On 11/02/2023 21:13, Eric Iverson wrote:

JHS major new release now available. I think it is worth a look.

See menu>help>welcome

Try out the new plot facility menu>tool>plot-chart
   (chartjs is very nice and easy to use)

Take menu>tour>overview tutorial
--
For information about J forums seehttp://www.jsoftware.com/forums.htm

--
For information about J forums seehttp://www.jsoftware.com/forums.htm


--
For information about J forums seehttp://www.jsoftware.com/forums.htm

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] JHS addon update available

2023-02-12 Thread 'Michael Day' via Programming

Thanks.

NB.  In the comment,  very early in menu>tour>overview :
   " NB. sum over - (Note Bene) starts comment "
please note that the "N" in "NB" stands for "Nota", not "Note" .

Sorry for pedantry,  but it might put off a potential fan! Apologies, too,
if it's been there for years,

Cheers,

Mike

On 11/02/2023 21:13, Eric Iverson wrote:

JHS major new release now available. I think it is worth a look.

See menu>help>welcome

Try out the new plot facility menu>tool>plot-chart
  (chartjs is very nice and easy to use)

Take menu>tour>overview tutorial
--
For information about J forums seehttp://www.jsoftware.com/forums.htm

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Grade behavior

2023-02-02 Thread 'Michael Day' via Programming

Having sent this,  I went back to the script for day 13.

Resorting to APL (Dyalog version),  I wrote a direct definition function
to replace the [ ] & , symbols appropriately,  and evaluate the results as
APL expressions.  Each of the 8 example pairs sorted correctly - ie 
"wrongly"

or "rightly" consistently with the stated requirements!

So, having spent days puzzling over this in December,  this approach
yielded the correct results in an hour or so!

You need to put something inside the brackets if there's nothing there,  eg
[] becomes [''] which, with suitable symbol changes can be evaluated.

I see Raul mentions recursion,  which is what had blown my mind when I
considered it for day 13; however,  this evening's effort needed no 
explicit

recursion.  The APL interpreter might perhaps have used recursion in its
evaluation,  but that would be hidden under the bonnet/hood.

Cheers,

Mike

On 02/02/2023 21:19, 'Michael Day' via Programming wrote:

Day 13 was one of my dead-ends.  Couldn't get my head round it!
I did try ordering,  though I forget how,  and didn't get the approach 
to work.

anyway!

I thought I could understand day 14 quite well,  but couldn't see
what was wrong with my code!

Have at last finished the rest.  Day 25 was traditionally (?) easy; 
day 24 took

me ages to find a nice model.

Really "Chat" again - sorry!

Cheers,

Mike

On 30/01/2023 18:08, Brian Schott wrote:

Raul,

Yes, your example and its explanation are correct.
I'll rethink this approach, perhaps as you suggested.




--
For information about J forums see http://www.jsoftware.com/forums.htm


--
For information about J forums see http://www.jsoftware.com/forums.htm


--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Grade behavior

2023-02-02 Thread 'Michael Day' via Programming

Day 13 was one of my dead-ends.  Couldn't get my head round it!
I did try ordering,  though I forget how,  and didn't get the approach 
to work.

anyway!

I thought I could understand day 14 quite well,  but couldn't see
what was wrong with my code!

Have at last finished the rest.  Day 25 was traditionally (?) easy; day 
24 took

me ages to find a nice model.

Really "Chat" again - sorry!

Cheers,

Mike

On 30/01/2023 18:08, Brian Schott wrote:

Raul,

Yes, your example and its explanation are correct.
I'll rethink this approach, perhaps as you suggested.




--
For information about J forums see http://www.jsoftware.com/forums.htm


--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Is there a Fold for AOC day 6? - was Re: Questions on Advent of code Day 5

2022-12-08 Thread 'Michael Day' via Programming

Thanks for your replies - I'll try to get round to understanding them.
It's a pity the Fold approach to this problem appears to need to be verbose.

Cheers,

Mike


On 08/12/2022 19:34, 'Pascal Jasmin' via Programming wrote:

mistake in Z definition found,

Zl =: ] [ _3 Z: [

makes this work,

((4;~4{.]) ((1>:@{::]),&<~[,~ _3{.0{::])`(_2 Z:1:)@.(4=0#@~.@{::]) ((100 Zl ]) 
F..) (4}.])) ex

but still

((4;~4{.]) ((1>:@{::]),&<~[,~ _3{.0{::])`(_2 Z:1:)@.(4=0#@~.@{::]) ((100 Zl ]) 
F.) (4}.])) ex

|domain error




On Thursday, December 8, 2022 at 02:15:39 p.m. EST, 'Pascal Jasmin' via Programming 
 wrote:





The short circuit you are trying to avoid is to skip the full partitioning part

4 #@~.\4

one approach is to separate into the simplest possible partition, then hope 
that i. special code finds the short circuit.

4 + (1 i.~ 4 = #@~."1) 4 ]\ ex

your power approach is completely reasonable.

A fold approach is complicated by seeking the index rather than a "computed 
result"

There might be too much manipulated computation involved, but the general 
approach would be:

x parameter to fold is (a: ,< 0)  NB. initial y.
if head cell of y is shorter than 4, then append x to last 3 chars. (better to 
preprocess y such that x (to F.) has first 4 chars, and y omits first 4.)
if head is length 4, then apply test  ((1 >:@{:: ] ) ,&<~ [,~ _3{.0{::])`(_2 Z: 
1:)@.(4 = #@~. 0 {:: ])

((4;~4{.]) ((1>:@{::]),&<~[,~ _3{.0{::])`(_2 Z:1:)@.(4=0#@~.@{::]) (] F..) 
(4}.])) ex
┌┬─┐
│jpqm│7│
└┴─┘

I don't understand why this fails:  (F. instead of F..)


Z =: ] [ Z:


    ((4;~4{.]) ((1>:@{::]),&<~[,~ _3{.0{::])`(_2 Z:1:)@.(4=0#@~.@{::]) ((100 Z~ 
_3:) F.) (4}.])) ex

|domain error

or

  ((4;~4{.]) ((1>:@{::]),&<~[,~ _3{.0{::])`(_2 Z:1:)@.(4=0#@~.@{::]) (] F.) 
(4}.])) ex

|domain error


also it is not documented whether F. or F: are forward or reverse.

On Thursday, December 8, 2022 at 11:28:12 a.m. EST, 'Michael Day' via Programming 
 wrote:





Having remarked recently (re Advent of Code day 6):

     Very easy today, in J at least,  and probably in APL & K/Q. (Though it
     suggests one should learn the new fold features,  as it's inefficient to
     examine all the data for something that might occur early.  No problem
     with 4kb,  but )

I've just had a look at the Jwiki entries about Fold,  and wonder how it
would work
for day 6.

The problem is so easy for J-ers that I don't think this will spoil it
for forum users:
    ex
mjqjpqmgbljsphdztnvjfqwrcgsmlb
    4 + 4 i.~ 4 #@~.\ ex
7

QED

    #data   NB. the size of my data set
4096
    ts'4 + 4 i.~ 4 #@~.\ data'   NB.  time & space
0.0008555 67232

I didn't bother making a function for this!

One way to stop early,  rather than process the whole array, is this:
    ts'4 + (# - #@:((}.`])@.(4&([ = #@:~.@:{.))^:_)) data'
0.0007299 4736

(I know it's ugly,  and non-optimal!)

Similar time but with ca 14x space-saving.

But there must be some sort of Fold to progressively examine 4-windows,
or 14-windows in part 2,  until the first appropriate window is found,
when
it stops.   That should save time as well as space.  Not necessary
here,  of
course,  but if there was a real application with many megabytes of data...

Cheers,

Mike



On 06/12/2022 19:46, Brian Schott wrote:

I have successfully solved Day 5 using the following looping verb `tomove`
but cannot craft a Fold version, and would like help.

*[FYI I have included an attachment that seems to load and execute
properly, but I could NOT get the email versions to load correctly,
presumably because of some funny characters.]*

tomove=: dyad define
while. #y do.
x=.x move {. y
y =. }.y
end.
x
)


NB. The verb `move` for part 1 is very simple:

move =: dyad define
'n f t'=. _1 1 1*y - 0 1 1
take =. |.n{.>f{x
left =. f{x
put =. t{x
(left,put) (f,t)}x
)

NB. the inputs are produced as follows.

top =: 0 :0
       [D]
[N] [C]
[Z] [M] [P]
   1  2  3
)

state=.deb each ;/ |:|.}:1 5 9&{;._2 top

bottom =: 0 :0
move 1 from 2 to 1
move 3 from 1 to 3
move 2 from 2 to 1
move 1 from 1 to 2
)
alpha =. a. {~97+i.26
moves =. ".-. ;._2 bottom

NB. finally the result is produced by the next phrase

{:every state tomove moves


--
For information about J forums seehttp://www.jsoftware.com/forums.htm

--
For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm


--
For information about J forums see http://www.jsoftware.com/forums.htm


[Jprogramming] Is there a Fold for AOC day 6? - was Re: Questions on Advent of code Day 5

2022-12-08 Thread 'Michael Day' via Programming

Having remarked recently (re Advent of Code day 6):

   Very easy today, in J at least,  and probably in APL & K/Q. (Though it
   suggests one should learn the new fold features,  as it's inefficient to
   examine all the data for something that might occur early.  No problem
   with 4kb,  but )

I've just had a look at the Jwiki entries about Fold,  and wonder how it 
would work

for day 6.

The problem is so easy for J-ers that I don't think this will spoil it 
for forum users:

   ex
mjqjpqmgbljsphdztnvjfqwrcgsmlb
   4 + 4 i.~ 4 #@~.\ ex
7

QED

   #data   NB. the size of my data set
4096
   ts'4 + 4 i.~ 4 #@~.\ data'   NB.  time & space
0.0008555 67232

I didn't bother making a function for this!

One way to stop early,  rather than process the whole array, is this:
   ts'4 + (# - #@:((}.`])@.(4&([ = #@:~.@:{.))^:_)) data'
0.0007299 4736

(I know it's ugly,  and non-optimal!)

Similar time but with ca 14x space-saving.

But there must be some sort of Fold to progressively examine 4-windows,
or 14-windows in part 2,  until the first appropriate window is found,  
when
it stops.   That should save time as well as space.  Not necessary 
here,  of

course,  but if there was a real application with many megabytes of data...

Cheers,

Mike



On 06/12/2022 19:46, Brian Schott wrote:

I have successfully solved Day 5 using the following looping verb `tomove`
but cannot craft a Fold version, and would like help.

*[FYI I have included an attachment that seems to load and execute
properly, but I could NOT get the email versions to load correctly,
presumably because of some funny characters.]*

tomove=: dyad define
while. #y do.
x=.x move {. y
y =. }.y
end.
x
)


NB. The verb `move` for part 1 is very simple:

move =: dyad define
'n f t'=. _1 1 1*y - 0 1 1
take =. |.n{.>f{x
left =. f{x
put =. t{x
(left,put) (f,t)}x
)

NB. the inputs are produced as follows.

top =: 0 :0
 [D]
[N] [C]
[Z] [M] [P]
  1   2   3
)

state=.deb each ;/ |:|.}:1 5 9&{;._2 top

bottom =: 0 :0
move 1 from 2 to 1
move 3 from 1 to 3
move 2 from 2 to 1
move 1 from 1 to 2
)
alpha =. a. {~97+i.26
moves =. ".-. ;._2 bottom

NB. finally the result is produced by the next phrase

{:every state tomove moves


--
For information about J forums seehttp://www.jsoftware.com/forums.htm

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Questions Advent of Code 2022 Day 5

2022-12-05 Thread 'Michael Day' via Programming
Interesting.    I hadn't spotted the double LF,  which, as I now know, 
has its own moniker,  LF2.
I'd started looking at the puzzle on this laptop,  then moved my 
proto-script and the datafile to

the iPad as I was going out for a few hours.

Ian Clark might note that,  and will understand why,  I found different 
positions for LF:


on the Windows 11 laptop,  J904 beta-g:
   I.LF = 350{.data
35 71 107 143 179 215 251 287 323 324 343
(with the double LF at 323 324)
and on the iPad (iOS 15.xxx) running Jios 903.1 release 52:
   I.LF = 350{.data
27 55 87 119 155 191 227 263 298 317 336
(with no double LF)
- which is possibly why I didn't spot it!

However,  this turns out to be an artefact of transferring data from 
laptop to iPad.
I've just logged back in to day 5 for the purpose of this message, and 
downloaded
the data from the aoc site to the tablet.  It then duplicates the LF 
indexes as found

on the laptop.

Warning to self!

BTW,  my first nearly successful pass on the example gave MCD as the 
answer for part 1
before I realised I needed to reverse the removed items as the 
CrateMover 9000 could only

manage individual crates,  so part 2 was trivial by comparison!

Mike

On 05/12/2022 16:45, Raul Miller wrote:

To find the splitting point in the file, I used:

split=. 2+I. LF2 E. y

To handle the moves, converted the part after the split to a rank 2
array of characters (one row per line), defined
to=: ,
from=: ,

And used:
".parse sample
and
".parse input

This means that I had a (slightly) different 'move' verb for part 2
from what I had for part 1.

FYI,



--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Questions Advent of Code 2022 Day 5

2022-12-05 Thread 'Michael Day' via Programming

I looked for a match with the line reading
 1 2 3
ie
break =. I. y E.~ ' 1 2 3'

Does that help?

Mike

On 05/12/2022 15:58, Jaume wrote:

Hello again.

I managed to solve day 3 and 4, so maybe when I clean up my solutions I
will ask to review them. But right now I have a problem and some questions
on the first part of day 5.

Main things I need in bold, mainly the last one. Feel free to code review
this message as much or as little as you want to.

I can read and parse both the stacks and the instructions without problem,
but I have to manually choose where to separate them.

]p=:1!:1<'/home/deck/projects/adventofcode/2022/d05t1.input'

[D]

[N] [C]

[Z] [M] [P]

1 2 3


move 1 from 2 to 1

move 3 from 1 to 3

move 2 from 2 to 1

move 1 from 1 to 2


]lines=.|:>4{.cutopen p

[[

NZ1

]]

[[[

DCM2

]]]

[

P3

]

]textstacks=:(4,:1)<;.3 }.lines

┌┬┬┐

│ NZ1│DCM2│ P3│

└┴┴┘

]wo=:}:each dltb each ,each textstacks

┌──┬───┬─┐

│NZ│DCM│P│

└──┴───┴─┘

]pc=.cutopen toJ p

┌───┬───┬───┬───┬──┬──┬──┬──┐

│ [D] │[N] [C] │[Z] [M] [P]│ 1 2 3 │move 1 from 2 to 1│move 3 from 1 to
3│move 2 from 2 to 1│move 1 from 1 to 2│

└───┴───┴───┴───┴──┴──┴──┴──┘

ins=: [: ". 'movefrt' -.~ ]

]moves =: ins each 4}. pc

┌─┬─┬─┬─┐

│1 2 1│3 1 3│2 2 1│1 1 2│

└─┴─┴─┴─┘

So I can separate the data, but I don't know how to find the line where to
separate them. I tried some things but to no avail. Some variations like
this one.

'm' i.&1@: sta pc
1


*So finding the first box that starts with 'm', or the first that is only
numbers would help. How could I find this kind of things?*

Now onto the hard part, how to iterate through the whole array of moves.

I can process the moves like this:
move=: 4 : 0

from=:(1{y)-1

to=:(2{y)-1

times=:0{y

m2=:x

for. i.times do.

m1=:(<(({.>from{m2),>to{m2))to}m2

m2=:(<}.>from{m1)from}m1

end.

m2

)

wo move 1 1 2

┌─┬┬─┐

│Z│NDCM│P│

└─┴┴─┘

wo move 1 2 1

┌───┬──┬─┐

│DNZ│CM│P│

└───┴──┴─┘

 From here *I would like to change the for. but I don't trust myself to do
it well using the power conjunction*. And it brings me up to the last part
that I have problems with, applying this to the whole array of moves.

I tried the \. \ /\. and /\ constructs, but none have worked for me.

1 (ww@>)\moves
┌┬┬┐
│DNZ │CM  │P   │
└┴┴┘

┌┬┬┐
││DCM │ ZNP│
└┴┴┘

┌┬┬┐
│CDNZ│M   │P   │
└┴┴┘

┌┬┬┐
│Z   │NDCM│P   │
└┴┴┘

1 (ww@>)/\moves
┌─┬─┬─┬─┐
│1 2 1│3 1 3│2 2 1│1 1 2│
└─┴─┴─┴─┘

And some more variations. *How do I execute the same function, with one
parameter being the result from the previous computation (except on the 1st
step)?*

Thanks in advance.
--
For information about J forums see http://www.jsoftware.com/forums.htm


--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Differentiation problem

2022-11-24 Thread 'Michael Day' via Programming
This does the trick in J904 - perhaps there's a better way of emulating 
D.(i.3) ...


   load'plot'
   load'~addons/math/calculus/calculus.ijs'

   u =. ^@-@-:@*:"0
   u1=. (u deriv_jcalculus_ 1)
   u2=. (u1 deriv_jcalculus_ 1)
   $>(u;u1;u2)10%~50-~i.101
3 101
   plot >(u;u1;u2)10%~50-~i.101

Mike

On 24/11/2022 18:54, 'Michael Day' via Programming wrote:

Well, I've discovered that this works ok in J807:

    plot|:^@-@-:@*:"0 D.(i.3)10%~50-~i.101 NB. replace ^&2 by *:   
(!)


I wasn't sure that you needed "0 so tried

    plot|:^@-@-:@*: D.(i.3)10%~50-~i.101


but that suffers the same problem with the 2nd derivative!


We're supposed to use deriv for d. and pderiv for D. in J90x, x > 0 .

Others will know how to do the equivalent of (u D.(i.3)) - I couldn't 
see how just now,


but you're presumably a version or two behind these.


Mike



On 24/11/2022 18:01, 'Bo Jacoby' via Programming wrote:

    plot|:^@-@-:@^&2"0 D.(i.3)10%~50-~i.101


NB. The blue curve is the bell curve. Mean value = 50. Standard 
deviation = 10NB. The read curve is the derivative of the blue curve. 
It crosses Y=0 at X=50NB. The green curve is the derivative of the 
red curve. It crosses Y=0 at X=50-10 and X=50+10

NB. But why is the green curve so ugly around X=50?
Thank you!
Bo.


--
For information about J forums seehttp://www.jsoftware.com/forums.htm

--
For information about J forums see http://www.jsoftware.com/forums.htm


--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Differentiation problem

2022-11-24 Thread 'Michael Day' via Programming

But... as I've just discovered,  the equivalent function expressed as
   ^@-@-:@*:
does yield a "smooth" curve for the 2nd differential,  so presumably 
there's a

different need to do or level of approximation with ^&2 compared to *:
There is a remark
   Generating higher-order partial derivatives with  D. 2 fails. Use 
repeated application of  D. 1 instead

in the  documentation at
https://code.jsoftware.com/wiki/Vocabulary/dcapdot

Mike

On 24/11/2022 18:36, Raul Miller wrote:

Presumably you're working with an older version of J, like J807. (J9
tossed the D. conjunction and requires we use the math/calculus
library manually.)

Anyways, if you increase the size of the plot, you'll see that the
display artifact you're looking at is a consequence of discretization
-- the plot is composed of lines and at that particular point in the
graph these lines do not adequately conform to the underlying curve.

FYI,


--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Differentiation problem

2022-11-24 Thread 'Michael Day' via Programming

Well,  I've discovered that this works ok in J807:

    plot|:^@-@-:@*:"0 D.(i.3)10%~50-~i.101 NB. replace ^&2 by *:   (!)

I wasn't sure that you needed "0 so tried

    plot|:^@-@-:@*: D.(i.3)10%~50-~i.101


but that suffers the same problem with the 2nd derivative!


We're supposed to use deriv for d. and pderiv for D. in J90x, x > 0 .

Others will know how to do the equivalent of (u D.(i.3)) - I couldn't 
see how just now,


but you're presumably a version or two behind these.


Mike



On 24/11/2022 18:01, 'Bo Jacoby' via Programming wrote:

    plot|:^@-@-:@^&2"0 D.(i.3)10%~50-~i.101


NB. The blue curve is the bell curve. Mean value = 50. Standard deviation = 
10NB. The read curve is the derivative of the blue curve. It crosses Y=0 at 
X=50NB. The green curve is the derivative of the red curve. It crosses Y=0 at 
X=50-10 and X=50+10
NB. But why is the green curve so ugly around X=50?
Thank you!
Bo.


--
For information about J forums seehttp://www.jsoftware.com/forums.htm

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Truncating primes

2022-11-19 Thread 'Michael Day' via Programming

A (surely not THE) verb?:

   (#~{{*/ (1 p:".) ry #~"1 -.=i.#ry =. ":y }}"0) range 100 200

111 113 117 119 131 137 171 173 179 197



Mike



On 19/11/2022 23:46, 'Skip Cave' via Programming wrote:

Interesting!

Now what is the J verb that will find an n-digit integer that is still
prime when each of the digits are removed?


Skip Cave
Cave Consulting LLC


On Sat, Nov 19, 2022 at 3:51 PM Richard Donovan
wrote:


Hi

I am doing experiments with large primes, in particular looking at primes
that remain primes when n digits are truncated from the left. For example
6391373391373913731373373733 remains prime at each
step.

The largest of these in base 10 is 357686312646216567629137.

I wrote the following code in preparation for further investigation but I
find that the 24 digit number above is not handled as I wish it to be, as
you will see below.

What have I missed?

Thanks




digits
"."0@":

ltrunc
3 : 0"0 0 0
n=: ": 0, }. digits y
x: ". n-. ' '
)



NB. Works fine with 7 digit number...
ltrunc^:a: 6391373
6391373391373913731373   3737330


NB. But I can’t get it working for a 24 digit number!
ltrunc 357686312646216567629137
0 0 5 7 6 8 6 0 2 3
ltrunc 357686312646216567629137x
57686312646216568012800
ltrunc x:357686312646216567629137x
57686312646216568012800

Is there a way around the limit?

--
For information about J forums seehttp://www.jsoftware.com/forums.htm


--
For information about J forums seehttp://www.jsoftware.com/forums.htm

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Truncating primes

2022-11-19 Thread 'Michael Day' via Programming
I think this is similar to your other replies,  but it might still be of 
interest:


   1 p: ". }.^:(i.@<:@#) @: ('x',~":) 357686312646216567629137x
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

With your smaller example:
   ltruncall =: }.^:(i.@<:@#) @: ('x',~":)

   ltruncall 6391373x
6391373x
391373x
91373x
1373x
373x
73x
3x

   (1 p: ".) ltruncall 6391373x
1 1 1 1 1 1 1

Mike





On 19/11/2022 21:51, Richard Donovan wrote:

Hi

I am doing experiments with large primes, in particular looking at primes that 
remain primes when n digits are truncated from the left. For example
6391373391373913731373373733 remains prime at each step.

The largest of these in base 10 is 357686312646216567629137.

I wrote the following code in preparation for further investigation but I find 
that the 24 digit number above is not handled as I wish it to be, as you will 
see below.

What have I missed?

Thanks




digits
"."0@":

ltrunc
3 : 0"0 0 0
n=: ": 0, }. digits y
x: ". n-. ' '
)



NB. Works fine with 7 digit number...
ltrunc^:a: 6391373
6391373391373913731373   3737330


NB. But I can’t get it working for a 24 digit number!
ltrunc 357686312646216567629137
0 0 5 7 6 8 6 0 2 3
ltrunc 357686312646216567629137x
57686312646216568012800
ltrunc x:357686312646216567629137x
57686312646216568012800

Is there a way around the limit?

--
For information about J forums seehttp://www.jsoftware.com/forums.htm

--
For information about J forums see http://www.jsoftware.com/forums.htm


[Jprogramming] testing

2022-09-15 Thread 'Michael Day' via Programming

Please ignore - with apoplogies - Mike

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Antivirus alarm when installing not signed J programming language on windows ?

2022-08-04 Thread 'Michael Day' via Programming
I don't know about other Windows users,  but I find the "run anyway" 
button doesn't appear
unless you scroll the dialog box.  So it's very easy to overlook this 
get-out,  at least with my

set-up!

Mike

On 03/08/2022 21:42, Don Guinn wrote:

YOu should be getting a box warning you and you have to ignore the default
and get to the "run anyway". You only have to do this once for each
executable.

On Wed, Aug 3, 2022 at 2:28 PM Elijah Stone  wrote:


On Wed, 3 Aug 2022, tu...@posteo.de wrote:


not signed

I guess this is the problem.  As I understand it (and I am no expert in
these
matters), this is some draconion, self-serving policy from microsoft: they
sell certificates for some hundreds of dollars which you can use to sign
your
applications, and then the OS will bad-mouth any application which is not
signed.  Apple does the same thing.  (It's not _inherently_ bad to have
signed
binaries, but the way the cards have crumbled here is, I think, somewhat
problematic.)

It should be possible to run the binary anyway; I have no idea how.  For
the
time being, the web playground should be usable.
--
For information about J forums see http://www.jsoftware.com/forums.htm


--
For information about J forums see http://www.jsoftware.com/forums.htm



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Sudoku16

2022-06-24 Thread 'Michael Day' via Programming
It looks as if some line-wrapping hid the singleton " : " at the end of 
the preceding line.

Sorry I didn't spot it!
M

On 24/06/2022 18:37, Brian Schott wrote:

Mike,

What I mean is, I never saw a line starting with : in your solve script.
Maybe I missed a script or email somewhere?

On Fri, Jun 24, 2022 at 1:31 PM 'Mike Day' via Programming <
programm...@jsoftware.com> wrote:


Sorry, Brian.  I thought I’d removed the h from solveh- the h was for
Hui,  but not
relevant for the version I prepared for this example.  I had another
“solve” in a larger
script.

As for the dyadic version,  the line below solve =: 3 : 0 , and before the
: line,  shows a
default lhs argument to be used for a monadic application.
Most lines are unaltered.

Cheers,

Mike



Sent from my iPad


On 24 Jun 2022, at 16:43, Brian Schott  wrote:

Mike,

To check the inputs of a grid I found that Hui's verb 'ok' works for me.

Your revision of the verb 'solve' looks problematic to me because it
suggests there is a dyadic version, but I could only find a monadic

version

from your earlier post. Also there is an example in this post using a

verb

'solveh' that is undocumented, I believe.

As you mention, I lean toward the tokens starting at 0, not at 1, too.

I especially like your way of initializing the nouns such as r, c and b
based on the input shape or count.

Also, your link to https://www.sudoku-puzzles-online.com/ was most

helpful.


On Fri, Jun 24, 2022 at 6:34 AM 'Michael Day' via Programming <
programm...@jsoftware.com> wrote:


Sorry for late posting - apparently a problem with my broadband
provider's server.

Yes, it can be worth doing a limited feasibility check on your input.
Every column,
row and small box should have no repeated elements apart from the

"missing"

indicator,  such as 0 or perhaps one of '.-*0' ,  eg,  using my
generalisation of Roger's code:
 */ (2 */ @: > #/.~@: -.&0)"1 R{,fiend   NB. fiend is a numeric 9x9
puzzle

1


It might be of minor interest to note I've got my modification of Roger
Hui's wiki essay

code to solve a 25x25 puzzle which I lifted from an online source,

https://www.sudoku-puzzles-online.com/

Annoyingly,  I haven't dicovered how to download it in a form usable
directly by J.  I
spent far too much time transcribing just one 25x25 puzzle by eye and

hand.

I modified the solve function , posted on 20 June. just a tad to allow
the input of a character
representation.  I'll just reproduce the new and amended lines:

solve =: 3 : 0
'.123456789abcdefghjklmnpqrstuvwxyzA' solve y  NB. x is a default
representation for up to 36x36 just:
if. ' ' = 1{.0{.ry =. , y do.
chars =. ''
chars =. chars, /:~ ~., ' .*-' (e.~#]) ry NB. any other
representations of unknown cells?
chars =. chars, /:~ ~., '123456789' (+./@:e.~#[) ry
chars =. chars, /:~ ~., 'abcdefghijklmnopqrstuvwxyz' (+./@:e.~#[)
ry
chars =. chars, /:~ ~., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' (+./@:e.~#[)
ry
sudokurep =: chars
y =. chars i. y
else.
sudokurep =: x
end.
.
see1 =: (;~n2$n1{.1)&(<;.1) @ ({) @ (n22&$) @ ,

.

)


[snip]


--
For information about J forums see http://www.jsoftware.com/forums.htm

--
For information about J forums see http://www.jsoftware.com/forums.htm






--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Sudoku16

2022-06-24 Thread 'Michael Day' via Programming
Sorry for late posting - apparently a problem with my broadband 
provider's server.


Yes, it can be worth doing a limited feasibility check on your input.  
Every column,

row and small box should have no repeated elements apart from the "missing"
indicator,  such as 0 or perhaps one of '.-*0' ,  eg,  using my 
generalisation of Roger's code:
    */ (2 */ @: > #/.~@: -.&0)"1 R{,fiend   NB. fiend is a numeric 9x9 
puzzle


1


It might be of minor interest to note I've got my modification of Roger 
Hui's wiki essay


code to solve a 25x25 puzzle which I lifted from an online source,

https://www.sudoku-puzzles-online.com/

Annoyingly,  I haven't dicovered how to download it in a form usable 
directly by J.  I

spent far too much time transcribing just one 25x25 puzzle by eye and hand.

I modified the solve function , posted on 20 June. just a tad to allow 
the input of a character

representation.  I'll just reproduce the new and amended lines:

solve =: 3 : 0
'.123456789abcdefghjklmnpqrstuvwxyzA' solve y  NB. x is a default 
representation for up to 36x36 just:

if. ' ' = 1{.0{.ry =. , y do.
   chars =. ''
   chars =. chars, /:~ ~., ' .*-' (e.~#]) ry NB. any other 
representations of unknown cells?

   chars =. chars, /:~ ~., '123456789' (+./@:e.~#[) ry
   chars =. chars, /:~ ~., 'abcdefghijklmnopqrstuvwxyz' (+./@:e.~#[) ry
   chars =. chars, /:~ ~., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' (+./@:e.~#[) ry
   sudokurep =: chars
   y =. chars i. y
else.
   sudokurep =: x
end.
.
see1 =: (;~n2$n1{.1)&(<;.1) @ ({) @ (n22&$) @ ,

.

)


Here's the puzzle I copied,  "confirmed" or "advanced" number 7957:


t25 =: (#{."1 ] ) dtb"1 >LF cut 0 : 0
j  g n  os wc iy   r aup
 o  qf   w    n  mgeb
 ycaix rlp  t  b d  nvs
n qcb e  vg  x  t
wbmks   ig   pnf  cd
 p s    w fxa d   v u l
k  u   xyv rhog    cj p q
   tj e nq  sy xo mbf w
 lxob ufk i   t   d    ns
  rqdtc   w uh   o g
u    kt  o i    vbpm gj h
  j   xv   pdrqwat  o   u
atib sym   h w   jod nfcx
o   w  dfbtkns   ux   a
v he ligq    b c  fk    d
 g x   ud m   yebqt
lh    r   p   s dmw gcxu
  q rmn pk tw  fg b sh
m b ac    hoej urx   p  y
  t o s   d bga h    f i
 cn  yps   db   vukfe
x  p  vh  b kwa j
  ajy  n f  p  hte sdriw
bfud  n    v   im  x
 wli j   ur xv pf  q b  n
)


see {:solveh t25
┌─┬─┬─┬─┬─┐
│jxegv│nktos│bwcdi│ymqhr│laupf│
│toprq│fdjvw│syuxn│icakl│hmgeb│
│hycai│xmrlp│ogtkf│bedju│nvsqw│
│ndflu│aqcby│ejmph│swvgo│ixrkt│
│wbmks│uheig│qlvar│txpnf│yjcdo│
├─┼─┼─┼─┼─┤
│ipysh│rgowm│fxaed│qnkvj│utlbc│
│knwue│ibxyv│lrhog│asftc│jdpmq│
│gavtj│delnq│cusyp│xoimb│fkwhr│
│clxob│hufkj│ivqmt│gprdw│aeyns│
│fmrqd│tcpsa│wbknj│luhey│xovgi│
├─┼─┼─┼─┼─┤
│usdcl│ktwao│xiyfe│nvbpm│qgjrh│
│ykjfn│exvhc│mpdrq│watig│olbsu│
│atibp│symur│ghlwv│eqjod│knfcx│
│oqgmw│pjdfb│tknsc│rluxh│eiayv│
│vrhex│ligqn│jaobu│cysfk│pwmtd│
├─┼─┼─┼─┼─┤
│pgsxc│waudh│vfrlm│oinye│bqtjk│
│lhkyf│orbte│pniqs│jdmwv│gcxua│
│djqvr│mnipk│ytwux│fgcba│sheol│
│mibna│cfqgl│hoejk│urxst│wpdvy│
│eutwo│vsyjx│dcbga│khlqp│rfnim│
├─┼─┼─┼─┼─┤
│rcnhg│ypsmi│aqjtw│dbolx│vukfe│
│xeopt│gvhrd│usfib│mkwan│cyqlj│
│qvajy│blnxf│kmpco│hteus│driwg│
│bfudk│qwact│neghl│vjyri│msoxp│
│swlim│jokeu│rdxvy│pfgcq│tbhan│
└─┴─┴─┴─┴─┘


   ts
6!:2 , 7!:2@]
   ts'solveh t25'   NB. performance ok for this example
0.0374274 1461408

They offer even larger puzzles,  but I'll avoid those until I see how to 
download them

in a usable format!



On 20/06/2022 18:00, Brian Schott wrote:

All,

My code is not perfect, but the error I was noticing in trying to step
through the algorithm using the verbs f and diff were correct, BUT my
initial data in the noun raw was missing a starting SPACE. So the example
data was unsolvable. When I corrected the data, I was able to get an answer
with Mike's most recent verb 'solve', and it looks like it is the correct
answer.

I apologize for the noise. And will try to improve my solution now; for
some reason my version of 'sudoku' is flawed, but I think I can rectify
that now that I have a working version of the verbs f and diff.

Again, I apologize. And thank you.
--
For information about J forums seehttp://www.jsoftware.com/forums.htm



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Sudoku16

2022-06-20 Thread 'Michael Day' via Programming
Purists may object to the number representation in the 16x16 puzzle, in 
the generalisation I've just posted;
numbers 1-16 are encoded as 1-g !  Clearly they could be "better" as 
0-f.  I don't know which is preferable!

I normally stick to a numeric output,  involving no encoding.

NB - I haven't copied the correspondence in this remark.

Cheers,

Mike

--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Sudoku16

2022-06-19 Thread 'Michael Day' via Programming
FWIW,  I've been looking at this,  and my own slower and more 
space-consuming versions.
I tried amending Roger's similar original code,  posted in the forum,  I 
think, with obvious
changes as follows.  Some of his verbs,  including your ac & ar I think 
differ in the wiki article

from the ones I have.  I've used suffixes x or hx for hex:

NB. Hui's solution for 16x16?

size2x  =: 2#sizex  =: *: smallx =: 4
jx  =. (]/. i.@#) ,{;~smallx#i.smallx
rx  =. size2x $"1 i.size2x
cx  =. (size2x$i.sizex){|:i.size2x
bx  =. (jx{sizex#i.sizex) { jx
Ix  =: rx,"1 cx ,"1 bx
Rx  =: jx,(,|:)i.size2x

freex   =: 0&= > (1+i.sizex)"_ e."1 Ix"_ { ,
regionsx=: Rx"_ {"_ 1 ,"2
eux =: e.&(i.sizex+1) *. 0&= +. ~:"1
okx =: (1$~(smallx,1)*size2x)"_ -:"2 eux@regionsx

s1ux    =: 3 : 0
 m=. 1=+/"2 Rx{,/y
 j=. I. +./"1 m
 k=. 1 i."1~ j{m
 i=. ,(k{"_1 |:"2 (j{Rx){,/y) #"1 j{Rx
 size2x$(1+k) i}0$~*/size2x
)

NB. s1x    =: +/ .*&(1+i.9) * 1: = +/"1
NB. s1 =: (+ (s1x >. s1u)@free)^:_"2
NB. sudoku =: s2 @: (ok # ]) @: s1 ^:_

s1xx    =: +/ .*&(1+i.sizex) * 1: = +/"1
s1hx    =: (+ (s1xx >. s1ux)@freex)^:_"2

s2ax    =: 3 : 0
 if. -. 0 e. ,y do. ,:y return. end.
 b=. freex y
 i=. (i.<./),(+/"1 b){(1+sizex),}.i.sizex
 d=. 1+I.i{,/b
 y +"2 d *"0 2 i=i.size2x
)

s2x =: ; @: (<@s2ax"2)

sudokux =: s2x @: (okx # ]) @: s1hx ^:_
NB. ==

When I run this on my solvable array, sixteen2,  it fails:
   s1x sixteen2
|length error: s1x
|   s1x sixteen2

Debug shows the error occurs in or around freex,  but I haven't yet 
discovered how.


Here's sixteen2:
   sixteen2
 3  6  0  0  0  0  4 15 12 11 13  2  8  0  5 0
 0  0 15  0  1  0 14  0  0  0  8  0 13  0  0 0
 0 14 13  0  0  8 10  0  0 16  5  0  0  0  0 0
 0  5  4  0  0  0  0  0  0  0  0  7  3 11  0 2
 0  0  9  0  0  7  0  0  0  0  3 10  6  4  0 0
 0 11  0  0  4 13  0  0  0  0  0  0  7 15 10 8
 0  0  0  0 15  0  0  0  0  0  6  4 11  0 14 0
 0 15  0  0  0  0  6  0 13  2  0  0  9 12  0 0
12  1  0  0  0  3  0  6  9  4 14  8  5  0  0 0
 0  0  0  0 13  2  0 12  0  5 10  3  1 14  9 0
 2  0  0  9  0  5  0  0 11 12  7  0  0  8 15 0
 0  0  8 14  0  4  7 11  1 13  0  0  0  0  0 0
 4  0  0  0  3  0 16  0  0  6  0  0  0  0  0 0
16  7 12 13 14  9  0  2  8  0  0  0  0 10  0 0
11  0  1  0  0 15  0  0  0  0  0  0  0  5  0 0
15  8  0  0  6  0  5 10  3  0  0  0  0  7 11 0

My own code is more secure in APL,  and too long-winded
to share here!

Cheers,

Mike




On 19/06/2022 17:42, Brian Schott wrote:

Raul,

I truly appreciate your comments and while they seem very reasonable I do
not know how to delve more deeply into the permutations as you suggest. I
am leaning more to dropping the idea of finding a solution based on Roger’s
algorithm. Instead I want to look more closely at his results for the verbs
AR and AC. In his algorithm he takes the larger of the two results, that is
the larger of AR or AC , where he expects one of each pair to be zero and
the other to be a valid candidate. Whenever there is a nonzero AC it is a
unique and correct candidate, but the values for AR are selected using
index of, i. . I am suspicious that the selection of AR is almost arbitrary
and is causing the problem. I think a human being could do a better job of
selecting among the alternatives from AR.

By the way in my definition for the verb AR the final negative one should
be a zero, but it doesn’t change things much. Also in my text above I am
capitalizing AR and AC but they are lowercase verbs.

If I am correct about using AR and AC to help a human, I would use a
variation on AC that shows all of the possible results instead of the one
captured by the ‘index of’ primitive. In light of that I am looking for
ways to use 4 x 4 arrangements of dots to display each of the cell’s
information. I was looking in the Unicode lists for 4 x 4 dot arrangements
but was unable to find any, so I am trying to imagine alternatives. So far
I can only think of using viewmat to construct the dot patterns.

Any more ideas?




--

(B=) <-my sig
Brian Schott
--
For information about J forums see http://www.jsoftware.com/forums.htm



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] J904-beta-d

2022-05-20 Thread 'Michael Day' via Programming

Thanks.  The upgrade was easy,  but the result is unfortunate,  at
least on this laptop running Windows 11.

Attempting to open any of Jqt, JHS, Jconsole does establish a new 
instance of
jqt.exe or jconsole.exe, according to the details display of Task 
Manager,  but it

immediately shows its status as "suspended."

(Raul MIller recently suggested I use Process Explorer - it shows the same
information as far as I can see.)

Task Manager refused to terminate these tasks.  ("Unable to terminate 
process -

The operation could not be completed.  Access is denied")
Restarting windows removed them of course.

I had added some stuff to the startup.ijs file,  trying to establish 
threads,  and

I wondered whether that was creating a problem given Henry's changed some
behaviour;  After commenting out those operations in the startup, opening
the exes still results in suspended status.

I'm not aware of having changed the setup in any way other than doing the
upgrade,  until I altered the startup.ijs file,  anyway.

It's difficult to give any useful information.

Any ideas?

Thanks,

Mike

On 20/05/2022 16:06, Eric Iverson wrote:

J904-beta-d is available for windows/linux/macos.

If you already run J904-beta, then upgrade is easy:
load'pacman'
'upgrade'jpkg'jengine'

If you have not yet installed J904-beta, time to get started!
https://code.jsoftware.com/wiki/System/Installation/J904


Release notes:
https://code.jsoftware.com/wiki/System/ReleaseNotes/J904


Questions/bug reports/etc. should go to the beta forum.
--
For information about J forums see http://www.jsoftware.com/forums.htm



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] JQT not starting properly in Windows 11

2022-05-17 Thread 'Michael Day' via Programming
Thanks,  Raul.   I've downloaded Process Explorer, as you suggest, as it 
sounds useful.


I think you're right that this laptop offers two (or more?) "desktops",  
but I've never
deliberately used the feature,   and it doesn't look as though Jqt was 
hiding elsewhere.


Anyway,  as I mentioned in an earlier message,  the problem of the 
apparent non-availability

of Jqt9 seems to have resolved itself for the time being.

Cheers,

Mike





On 17/05/2022 17:29, Raul Miller wrote:

Here, I would recommend Process Explorer.

The current microsoft url for it is
https://docs.microsoft.com/en-us/sysinternals/downloads/process-explorer

Right click on the process here will give you window controls (like
"bring to front") if there is a window. If there's not, there's no
window (and "recovery" probably involves shutting it down (or,
rebooting)).

That said, Windows has (in at least some versions) a multiple desktop
feature (which I don't have enough practical experience with) which
might be relevant here.

I hope this helps,




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] JQT not starting properly in Windows 11

2022-05-17 Thread 'Michael Day' via Programming

Success???!!!

I really should clean up the old J installations - but as they're 
there,  I tried J902, J901, J807,  giving
up on each loading and usually closing their "task".  But the J807 
terminal has just leapt into life after
5-10 minutes of me looking at emails etc.  With this encouraging sign of 
survival,  I clicked on J904

beta's icon in the Taskbar and its terminal appeared almost immediately.

Weird.  I'll keep it running for a while now.

Sorry to cry wolf.

Mike

On 17/05/2022 17:19, 'Michael Day' via Programming wrote:
Thanks, but I'm pretty sure it's not off-screen.  At least, Alt+Tab 
doesn't find it,  and I frequently use those keys to swap windows.


I forgot to mention earlier that I did think of permissions,  and 
tried "run as administrator" with the same lack of a terminal screen.


And oh yes,  the yellow icon is indeed in the Windows 11 Taskbar, 
though only because I put it there!  Not a lot of use except it only 
needs a single click to evoke the non-apparent terminal!


Currently Clueless.

Thanks to you & Rob,

Mike

On 17/05/2022 12:00, Joe Bogner wrote:

I now find that Jqt doesn't display any window when I start it.  I can
see it in Task Manager but it's not usable.


I've had JQT show up off-screen once or twice and had to use a 
shortcut to

bring it back on screen. I think it was when I was in a multi-monitor
situation and went back to a single monitor. It hasn't happened in years
but passing along in case it helps

Press Alt + Tab to select the missing window.
Press Alt + Space + M to change the mouse cursor to the move cursor.
Use the left, right, up or down keys on your keyboard to bring the 
window

back into view.
Press Enter or click the mouse to let the window go once recovered.

https://www.google.com/search?q=windows+restore+off+screen+window

or
https://support.microsoft.com/en-us/topic/some-programs-are-displayed-off-the-screen-b2a915b7-4705-c455-febf-8ddb6e7f0ae4 



Is it showing the green J icon on the taskbar? Or maybe Windows 11 
doesn't

have that anymore..
--
For information about J forums see http://www.jsoftware.com/forums.htm






--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] JQT not starting properly in Windows 11

2022-05-17 Thread 'Michael Day' via Programming
Thanks,  but I'm pretty sure it's not off-screen.  At least, Alt+Tab 
doesn't find it,  and I frequently use those keys to swap windows.


I forgot to mention earlier that I did think of permissions,  and tried 
"run as administrator" with the same lack of a terminal screen.


And oh yes,  the yellow icon is indeed in the Windows 11 Taskbar, though 
only because I put it there!  Not a lot of use except it only needs a 
single click to evoke the non-apparent terminal!


Currently Clueless.

Thanks to you & Rob,

Mike

On 17/05/2022 12:00, Joe Bogner wrote:

I now find that Jqt doesn't display any window when I start it.  I can
see it in Task Manager but it's not usable.



I've had JQT show up off-screen once or twice and had to use a shortcut to
bring it back on screen. I think it was when I was in a multi-monitor
situation and went back to a single monitor. It hasn't happened in years
but passing along in case it helps

Press Alt + Tab to select the missing window.
Press Alt + Space + M to change the mouse cursor to the move cursor.
Use the left, right, up or down keys on your keyboard to bring the window
back into view.
Press Enter or click the mouse to let the window go once recovered.

https://www.google.com/search?q=windows+restore+off+screen+window

or
https://support.microsoft.com/en-us/topic/some-programs-are-displayed-off-the-screen-b2a915b7-4705-c455-febf-8ddb6e7f0ae4

Is it showing the green J icon on the taskbar? Or maybe Windows 11 doesn't
have that anymore..
--
For information about J forums see http://www.jsoftware.com/forums.htm



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


[Jprogramming] JQT not starting properly in Windows 11

2022-05-17 Thread 'Michael Day' via Programming
Hello.  I tried to wake up my laptop from sleep just now,  as usual - ie 
I leave it in sleep mode while I'm asleep...
But,  as occasionally happens, it must have restarted,  and nothing was 
open.


(I wanted to explore the Babylon Spiral topic,  which I've just woken up 
to see!)


I now find that Jqt doesn't display any window when I start it.  I can 
see it in Task Manager but it's not usable.

This goes for both J904 beta-c and J903.

I recall this happening before,  a few years ago, but can't remember how 
we got round the problem; perhaps it

just went away.

Yes,  I did do a full stop and reboot of Windows.  As far as I can see,  
Windows has NOT done a surreptitious
update while I wasn't looking.  It's Windows 11 Home,  version 21H2,  
installed on 26/10/21, OS build 22000.65 ,

Windows Feature Experience Pack 1000.22000.675.0  (very round numbers!?)

I'm nothing like as proficient in using J in other manifestations, ie 
JHS & Jconsole.


HELP!

Thanks,

Mike

PS - I'll keep trying to run from time to time - will report if Jqt 
suddenly decides to reveal itself.



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Extended precision question

2022-05-01 Thread 'Michael Day' via Programming

Mainly for Ed Gottsman:

Chat really,  but the thread is already here.

I've just solved Euler Problem 788 with the assistance of extended 
precision numbers.  The solution is
slow,  taking over 14 minutes,  but at least it's less than the lifetime 
of the universe,  unlike my (projected)

methods for some of these problems!

It's relatively easy,  compared with many of the recent questions; 
https://projecteuler.net/problem=788 .


As for Ed's original post,  I'll point out that x: features aren't 
necessary for the solution of problem 66
although they can possibly help in understanding it.  I don't think 
that's a spoiler.


Cheers,

Mike

On 21/04/2022 17:43, Ed Gottsman wrote:

Hello.
  
I’m working on the Project Euler “Diophantine equation” problem (#66) and using J’s extended precision facilities.  I’ve run into behavior that confuses me.  Boiled down (and overusing x: just to be sure):
  
x: %: x: 1 + x: *: x: 9

9
  
That is (if my syntax is right), the square root of (one plus the square of a really large n) is n.  I’m apparently misunderstanding something about extended precision.  I’ve tried it with a variety of uses of x: but to no avail, and as I read the x: documentation…this is an odd result.


Any help would be much appreciated.
  
(J901 on iPadOS, for which sincere kudos to Ian Clark.)
  
Many thanks.
  
Ed

--
For information about J forums see http://www.jsoftware.com/forums.htm



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] jpm niggle - was Re: [Jbeta] Beta users: please enable new diagnostic message

2022-04-12 Thread 'Michael Day' via Programming
Sorry, Henry - I just checked a dyadic function with jpm - STILL ALL 
ZEROS IN/UP TO J903.
HOWEVER - it is indeed reporting numbers of entries and times by line in 
J904, for the dyad as for monads !


So - Thanks for that,  and sorry that I didn't check.  I'd assumed that 
you'd been too

busy to deal with this issue for this beta release.

Cheers,

Mike

On 12/04/2022 16:45, Henry Rich wrote:
I thought I fixed that a while back & I believe I got good results in 
JPM.  I'll look again next time I have to profile.


Henry Rich

On 4/11/2022 1:03 PM, 'Michael Day' via Programming wrote:

Thanks.

BTW,  not a Beta problem,  I realise,  and I don't know how many 
users are affected,  but
I'm still having to make functions monadic if I want showdetail to 
provide a useful report;
dyads still yield zero times for all lines - last time I looked, 
anyway!  po


Mike

On 11/04/2022 17:57, Henry Rich wrote:
Ah, that's telling us showdetail should be updated.  Thanks for the 
report.


Henry Rich

On 4/11/2022 12:53 PM, 'Michael Day' via Beta wrote:
Is this an example of the error messages/warnings enabled with 
9!:55 ] 1e6;'   ?


   commas i.10 NB. no problem reported
0,1,2,3,4,5,6,7,8,9,

But suppose I wish to examine the performance of commas(!!):
   start_jpm_ 10
17857142
   timex'commas i.10'
4.11e_5
   showdetail_jpm_ 'commas'
recorded all lines
used and max record count: 24 17,857,142

(004) m}"n should be executed without " using leading axes of a: in m
(004) m}"n should be executed without " using leading axes of a: in m
(004) m}"n should be executed without " using leading axes of a: in m
 Time (seconds)
+++---+---+
|all |here    |rep|commas |
+++---+---+
|0.30|0.30|1  |monad 1 |. ' ' -.~ [: , ','&,@:":"0|
+++---+---+

The three diagnostics (004) m"}n ... are evidently evoked by 
something in

or called by showdetail_jpm_  .

I discovered this just now,  examining the performance of something a
bit more interesting than "commas",  but decided this example 
demonstrates

the point of interest.

Cheers,

Mike

On 09/04/2022 20:03, Henry Rich wrote:
It has long been known that J will execute many meaningless 
sentences without warning. Examples are


NB **

#if defined(AVX)

perform_important_function misspelled_noun

each of which does nothing.

It has been difficult to give warnings only on true errors. J904 
implements a warning, based on the observation that the erroneous 
sentences produces verbs, and taking into account contexts where a 
verb result would be valid.


This warning occasioned an unusually wide range of opinion at J 
Headquarters.  Is it: tantamount to a Critical Security Patch, 
fixing a gaping hole in the language; a novelty, perhaps of 
interest to a few; an unwarranted usurpation of a programmer's 
prerogatives, and likely to break working code?


Thus the warning is optional in beta-a.  We would like to get good 
data on whether the warning is welcome, noxious, or intolerable. I 
ask all beta users to enable the warning by adding


9!:55 ] 1e6;''

to your startup script.  After a few days, report your findings in 
this Forum.  Make note of any valid lines that were flagged, and 
also of any cases where the warning revealed code to be meaningless.


Henry Rich
















--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


[Jprogramming] jpm niggle - was Re: [Jbeta] Beta users: please enable new diagnostic message

2022-04-11 Thread 'Michael Day' via Programming

Thanks.

BTW,  not a Beta problem,  I realise,  and I don't know how many users 
are affected,  but
I'm still having to make functions monadic if I want showdetail to 
provide a useful report;

dyads still yield zero times for all lines - last time I looked, anyway!  po

Mike

On 11/04/2022 17:57, Henry Rich wrote:
Ah, that's telling us showdetail should be updated.  Thanks for the 
report.


Henry Rich

On 4/11/2022 12:53 PM, 'Michael Day' via Beta wrote:
Is this an example of the error messages/warnings enabled with 9!:55 
] 1e6;'   ?


   commas i.10 NB. no problem reported
0,1,2,3,4,5,6,7,8,9,

But suppose I wish to examine the performance of commas(!!):
   start_jpm_ 10
17857142
   timex'commas i.10'
4.11e_5
   showdetail_jpm_ 'commas'
recorded all lines
used and max record count: 24 17,857,142

(004) m}"n should be executed without " using leading axes of a: in m
(004) m}"n should be executed without " using leading axes of a: in m
(004) m}"n should be executed without " using leading axes of a: in m
 Time (seconds)
+++---+---+
|all |here    |rep|commas |
+++---+---+
|0.30|0.30|1  |monad 1 |. ' ' -.~ [: , ','&,@:":"0|
+++---+---+

The three diagnostics (004) m"}n ... are evidently evoked by 
something in

or called by showdetail_jpm_  .

I discovered this just now,  examining the performance of something a
bit more interesting than "commas",  but decided this example 
demonstrates

the point of interest.

Cheers,

Mike

On 09/04/2022 20:03, Henry Rich wrote:
It has long been known that J will execute many meaningless 
sentences without warning.  Examples are


NB **

#if defined(AVX)

perform_important_function misspelled_noun

each of which does nothing.

It has been difficult to give warnings only on true errors. J904 
implements a warning, based on the observation that the erroneous 
sentences produces verbs, and taking into account contexts where a 
verb result would be valid.


This warning occasioned an unusually wide range of opinion at J 
Headquarters.  Is it: tantamount to a Critical Security Patch, 
fixing a gaping hole in the language; a novelty, perhaps of interest 
to a few; an unwarranted usurpation of a programmer's prerogatives, 
and likely to break working code?


Thus the warning is optional in beta-a.  We would like to get good 
data on whether the warning is welcome, noxious, or intolerable. I 
ask all beta users to enable the warning by adding


9!:55 ] 1e6;''

to your startup script.  After a few days, report your findings in 
this Forum.  Make note of any valid lines that were flagged, and 
also of any cases where the warning revealed code to be meaningless.


Henry Rich










--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] [Jbeta] J904 multithreading

2022-04-11 Thread 'Michael Day' via Programming
The mechanism here is presumably common knowledge,  but might be worth 
sharing.

Here's what I use to allocate half of the laptop's cores for use by J:

NB. Processor Affinity
coclass 'affin'
require'dll'

GetCurrentProcess=: >@{.@('kernel32 GetCurrentProcess i'&(15!:0))
GetProcessAffinityMask=: ('kernel32 GetProcessAffinityMask i i * *'&(15!:0))
SetProcessAffinityMask=: ('kernel32 SetProcessAffinityMask i i i'&(15!:0))

setproc =: 3 : 0
'rc tid pam sam'=.GetProcessAffinityMask (GetCurrentProcess'');(,2-2);(,2-2)
ppr=. ,I. (8#2)#: sam
NB. choose random half of cores
cores =. ((?~ <.@-: ) # ppr )
SetProcessAffinityMask tid;0{,(8#2)#. 1 cores }8#0
)

So the number of cores is
   # #: sam
and you only need GetProcessAffinityMask and GetCurrentProcess for that
information.

Cheers,

Mike

On 10/04/2022 23:49, Raul Miller wrote:

There's currently no rush for deciding this kind of thing.

We need some experience with this mechanism, first. And, before that,
we need to support Henry's efforts to sort out the rough edges.

But counting cpu cores is a relatively simple task, if slightly
obscure. So I thought I should leave a note here about that.

Thanks,

-- Raul On Sun, Apr 10, 2022 at 6:34 PM Hauke Rehr 
 wrote:

why not have a command line argument providing a default number?
$USER may know better what they consider a good default

Am 11.04.22 um 00:31 schrieb Raul Miller:

It would be nice, I imagine, if we eventually had a mechanism like

https://www.cprogramming.com/snippets/source-code/find-the-number-of-cpu-cores-for-windows-mac-or-linux

to set up a default number of threads.


--
--
mail written using NEO
neo-layout.org
--
For information about J forums seehttp://www.jsoftware.com/forums.htm

--
For information about J forums seehttp://www.jsoftware.com/forums.htm



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] {{ }} definitions

2022-03-29 Thread 'Michael Day' via Programming

Yes: eg

NB. in your script,  say

foo =: {{
   x + y
}}"0 1  NB. just as an example! (Not necessarily a sensible use 
of rank!)


NB. displaying it in the terminal session;  direct definition functions
NB. are displayed as conventional explicit definitions

   foo
4 : '   x + y'"0 1

So the rank appears where you would have put it in the old form.

Probably in the wiki somewhere!

Mike



On 29/03/2022 17:42, P Padilcdx wrote:

Is there a way to declare the rank when using {{ }} definitions? Or is it only 
possible when defining via “:”?  Apologies if covered in the wiki and I missed 
it.
--
For information about J forums see http://www.jsoftware.com/forums.htm



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Cyclotomic Polynomials and FFT - was Re: polynomial division

2022-03-08 Thread 'Michael Day' via Programming
Thanks.  May I just suggest again having a look at the bullet points, 
which have the odd

error?
eg "...coefficients of A cyclotomic polynomialS after 1 ..."
"... coefficients of the cyclotomic polynomial for a prime number haS as 
many..."

capitals/upper case highlighting problem letters.

Cheers
Mike

On 08/03/2022 21:01, Raul Miller wrote:

On Tue, Mar 8, 2022 at 2:01 PM 'Michael Day' via Programming
 wrote:

for fft "division"),  I feel I can wonder if this helps the Rosetta
Code exposition of the virtues of J!  I like my idea,  of course,
and it's of potential interest to the J community,  but are Rosetta
coders interested in tweaks to improve performance?

Some of them are.

But, I've taken the hint, and trimmed the J treatment of fft for the
cyclotomic polynomial task, to remove unnecessary bulk.

Thanks,




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Cyclotomic Polynomials and FFT - was Re: polynomial division

2022-03-08 Thread 'Michael Day' via Programming

Sorry - a few days have passed

Interesting!

As I had put up this idea (using fft multiplication and a special case 
for fft "division"),  I feel I can
wonder if this helps the Rosetta Code exposition of the virtues of J!  I 
like my idea,  of course,
and it's of potential interest to the J community,  but are Rosetta 
coders interested in tweaks

to improve performance?

REBoss's contribution is quite different,  and very compact,  so worth 
including.


There's no chance the contribution will reach the length of the Java 
one,  say,  but casual readers
not familiar with J might get the impression that all the code presented 
is required.


Just a thought!

Anyway,  I had a look at saving some of the continued redefinition of 
roots of unit and reuse of "cube", given
the repeated use of fft in the cyclotomic function,by defining a 
function fft1 which would be used instead of
fft"1 for multiples of lists of polynomials all of the same extended 
length,   but it doesn't help much here,

and is of course more complicated,  so I won't share it.

However,  if the fft multiplication version is to be included in the 
Rosetta Code contribution,  I think the
following offers some improvement,  mainly from the point of view of 
exposition.  A bit of thinking reveals

that the maximum length of all the polynomials will be that of x^n - 1 .
I believe this block of code is self-contained,  assuming addons include 
the fftw library.  unpad only needs
redefinition here for self-containedness.  ctfft can be renamed of 
course!  Use of M. is a matter of taste,
I suppose;  it does save having to define your own cache,  as previously 
discussed.


NB. Rosetta Coders don't need to worry about fft v fftw - that's for J-ers.


load '~addons/math/fftw/fftw.ijs'
fft   =: fftw
ifft  =: ifftw
roundreal =: [: (<.) 0.5 + 9
unpad =: {.~ (1 + 0 i:~ 0 = ])

ctfft =:  {{ assert.0 ctlist  =. ctfft  "0 }:*/@>,{1,each q NB. ctlist is 2-d 
table of polynomial divisors
 dividend=. _1,(-y){.1 NB. coefficients of 
(x^n) - 1
 lg  =. >.&.(2&^.) y   NB. required length 
of each polynomial for fft transforms here
 fftdivis=. lg */  @:(fft @:{."1) ctlist   NB. fft of product 
of divisor polys = product of ffts of divisor polys
 fftquot =. fftdivis %~ fft  lg{.dividend  NB. (fft of 
(dividend%divisor) = (fft of dividend) % (fft of divisor)
 unpad roundreal ifft"1  fftquot   NB. clean up inverse 
fft of (dividend)

   end.
}} M.

Also,  I noticed a few minor typos in the remarks between "If you take 
all the divisors... " and "Task examples:"


Cheers,

Mike


On 02/03/2022 19:57, Raul Miller wrote:

I've updated the rosettacode page to include this implementation. And,
I plan on updating the j wiki polynomial division essay, also, once I
think through a bit how to describe this approach. (Descriptive
phrases and sentences would be welcome. Documentation needs good
perspectives, above all else.)

For the purpose of the rosettacode page, I used a different phrasing of rou:

rou   =: {{(,j.) r,(%:0j1),j.+|.}.r=.^o.j.(i.@%&8 % -:) y}}  NB.
roots of unity

This seems (to me) to be more concise, and straightforward, than the
purely tacit expression.

(That said, I'm not sure if this change in notation would be a good
fit for the FFT essay.)

Thanks,




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Power Conjunction

2022-03-06 Thread 'Michael Day' via Programming

Oops - please use this line in goeis,  just below,
   echo ' results found',~ ": +/ok
in place of
   echo '3 results found'

Mike

On 06/03/2022 17:05, 'Michael Day' via Programming wrote:

OK - Ian wondered about automating a search in OEIS.
With a little inspection of the "page source" I've come up with this 
script;  it seems to work!


Although lots of OEIS lists are potentially mentioned if a series is 
matched,  many are cross-references

rather than the lower number of series that actually match.

My research has hardly been far-reaching,  so there may well turn out 
to be exceptions to this rule,  but

so far it appears that the pattern
   ''
works for the headwords,  as a dictionary might describe these 
references.


=
load   '~addons/web/gethttp/gethttp.ijs'

goeis =: getoeisseries =: {{

 commas =. {{   NB. form a comma-separated list suitable for an OEIS 
search

 q   =. 1|.' '-.~,','&,@:":"0 y
 if. # imin=. I. q = '_' do.
 q   =. '-' imin } q
 end.
}}

NB. commas 10?10

NB. 6,1,9,0,8,2,4,7,3,5,


 OEIS =. 'http://oeis.org/search?q='
NB. read RAW; the result of searching in OEIS for commas y
NB. Using global RAW for later inspection by user
 RAW  =: gethttp OEIS,commas y
NB. find all occurrences of '}} RAW

NB.  looking for subset matching "/Axx/list">
 ix =. ix +/ 7 + 10 + i.7
if. +/ ok =. '/list">' -:"1 ix {"1 RAW do.
   echo '3 results found'
   RAW {~ _7 + ok#ix
else.
   echo 'Sorry, but the terms do not match anything in the table.'
   RAW =: ''
end.
}}

NB.    goeis 5 9 15 23 33 45 59
NB. 3 results found
NB. A027688
NB. A118403
NB. A134586

NB.    goeis 5 9 15 23 33 45 59 27
NB. Sorry, but the terms do not match anything in the table.
=== 



IF the series is found,  you can go on to examine - even parse?! - the 
global "RAW" -
though I expect it's just as useful to go to the browser.  I don't use 
JHS enough to know

how to integrate this approach in that enviornment.

Mike

On 06/03/2022 14:06, 'Michael Day' via Programming wrote:
I don't yet see how to separate the series itself/themselves from 
cross-refs!

M

On 06/03/2022 12:18, 'Michael Day' via Programming wrote:

Late to the power party!

This is one way to automate the OEIS look-up - I'm not an expert on 
parsing the result,  but hunting for 'A', a single digit seems

a good starter:

   OEIS =: 'http://oeis.org/search?q='  NB. fails with https://... !

   getoeisseries =:{{ {{(-.{.) ' ',,/ y&{{~.x{~(i.7)+/~ x I.@:E.~ 
'A',y}}"0 '0123456789' }} RAW=:gethttp OEIS,commas y}}


   getoeisseries 5 9 15 23 33 45 59
A027688
A002522
A007954
A176271
A118403
A118401
A118400
A118407
A118402
A134586

where commas is what I always use to format series for OEIS searches:

commas =: 3 : 0   NB. crude - I forget how to format negatives using 
- with some ": variant!!!

 q   =. 1|.' '-.~,','&,@:":"0 y
 if. # imin=. I. q = '_' do.
 q   =. '-' imin } q
 end.
)

Not a primitive adverb,  but it's my starter for 10,

Mike

On 06/03/2022 06:36, Ian Clark wrote:

Let's cheat and look it up in oeis.org …
Skip's sequence is A027688, dropping the first term
A027688 is defined as: (n^2 + n + 3)
but (n*n + n + 3) gives better results with (13 :)

q=: 13 : '(y*y) + y + 3'

q

*~ + 3 + ]

q >:i.10

5 9 15 23 33 45 59 75 93 113


Has anyone tried automating OEIS lookup? It could be the basis for 
a nifty

new primitive adverb: (...) as in:

5 9 15 23 33 ...


[NB NB NB snipped earlier posts!  MD]




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Power Conjunction

2022-03-06 Thread 'Michael Day' via Programming

I forgot about regular expressions in J, but not familiar with them anyway!
Used to know them in unix, once upon a time.
Yr commas much better,  too.

M

On 06/03/2022 17:02, Raul Miller wrote:

Here's a version of getoeisseries which only returns direct hits and
not cross references:

NB. install 'web/gethttp'
require'regex web/gethttp'

OEIS =: 'http://oeis.org/search?q='  NB. fails with https://... !

getoeisseries=: {{
   a0=. I.''E.RAW
   A=. ,{."1'href="/A\d{6}"'rxmatches RAW
   a=. RAW{L:0~(a0(+i.)&.>a1-a0){~<:a0 I.A
   keep=. -.(1: e. ' title=' E. ])S:0 a
   >(}.~1+i.&'>')&.> keep#a
}}

commas=: rplc&' ,_-'@":

FYI,




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Power Conjunction

2022-03-06 Thread 'Michael Day' via Programming

OK - Ian wondered about automating a search in OEIS.
With a little inspection of the "page source" I've come up with this 
script;  it seems to work!


Although lots of OEIS lists are potentially mentioned if a series is 
matched,  many are cross-references

rather than the lower number of series that actually match.

My research has hardly been far-reaching,  so there may well turn out to 
be exceptions to this rule,  but

so far it appears that the pattern
   ''
works for the headwords,  as a dictionary might describe these references.

=
load   '~addons/web/gethttp/gethttp.ijs'

goeis =: getoeisseries =: {{

 commas =. {{   NB. form a comma-separated list suitable for an OEIS 
search

 q   =. 1|.' '-.~,','&,@:":"0 y
 if. # imin=. I. q = '_' do.
 q   =. '-' imin } q
 end.
}}

NB. commas 10?10

NB. 6,1,9,0,8,2,4,7,3,5,


 OEIS =. 'http://oeis.org/search?q='
NB. read RAW; the result of searching in OEIS for commas y
NB. Using global RAW for later inspection by user
 RAW  =: gethttp OEIS,commas y
NB. find all occurrences of '}} RAW

NB.  looking for subset matching "/Axx/list">
 ix =. ix +/ 7 + 10 + i.7
if. +/ ok =. '/list">' -:"1 ix {"1 RAW do.
   echo '3 results found'
   RAW {~ _7 + ok#ix
else.
   echo 'Sorry, but the terms do not match anything in the table.'
   RAW =: ''
end.
}}

NB.    goeis 5 9 15 23 33 45 59
NB. 3 results found
NB. A027688
NB. A118403
NB. A134586

NB.    goeis 5 9 15 23 33 45 59 27
NB. Sorry, but the terms do not match anything in the table.
===

IF the series is found,  you can go on to examine - even parse?! - the 
global "RAW" -
though I expect it's just as useful to go to the browser.  I don't use 
JHS enough to know

how to integrate this approach in that enviornment.

Mike

On 06/03/2022 14:06, 'Michael Day' via Programming wrote:
I don't yet see how to separate the series itself/themselves from 
cross-refs!

M

On 06/03/2022 12:18, 'Michael Day' via Programming wrote:

Late to the power party!

This is one way to automate the OEIS look-up - I'm not an expert on 
parsing the result,  but hunting for 'A', a single digit seems

a good starter:

   OEIS =: 'http://oeis.org/search?q='  NB. fails with https://... !

   getoeisseries =:{{ {{(-.{.) ' ',,/ y&{{~.x{~(i.7)+/~ x I.@:E.~ 
'A',y}}"0 '0123456789' }} RAW=:gethttp OEIS,commas y}}


   getoeisseries 5 9 15 23 33 45 59
A027688
A002522
A007954
A176271
A118403
A118401
A118400
A118407
A118402
A134586

where commas is what I always use to format series for OEIS searches:

commas =: 3 : 0   NB. crude - I forget how to format negatives using 
- with some ": variant!!!

 q   =. 1|.' '-.~,','&,@:":"0 y
 if. # imin=. I. q = '_' do.
 q   =. '-' imin } q
 end.
)

Not a primitive adverb,  but it's my starter for 10,

Mike

On 06/03/2022 06:36, Ian Clark wrote:

Let's cheat and look it up in oeis.org …
Skip's sequence is A027688, dropping the first term
A027688 is defined as: (n^2 + n + 3)
but (n*n + n + 3) gives better results with (13 :)

q=: 13 : '(y*y) + y + 3'

q

*~ + 3 + ]

q >:i.10

5 9 15 23 33 45 59 75 93 113


Has anyone tried automating OEIS lookup? It could be the basis for a 
nifty

new primitive adverb: (...) as in:

5 9 15 23 33 ...


[NB NB NB snipped earlier posts!  MD]

--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Power Conjunction

2022-03-06 Thread 'Michael Day' via Programming
I don't yet see how to separate the series itself/themselves from 
cross-refs!

M

On 06/03/2022 12:18, 'Michael Day' via Programming wrote:

Late to the power party!

This is one way to automate the OEIS look-up - I'm not an expert on 
parsing the result,  but hunting for 'A', a single digit seems

a good starter:

   OEIS =: 'http://oeis.org/search?q='  NB. fails with https://... !

   getoeisseries =:{{ {{(-.{.) ' ',,/ y&{{~.x{~(i.7)+/~ x I.@:E.~ 
'A',y}}"0 '0123456789' }} RAW=:gethttp OEIS,commas y}}


   getoeisseries 5 9 15 23 33 45 59
A027688
A002522
A007954
A176271
A118403
A118401
A118400
A118407
A118402
A134586

where commas is what I always use to format series for OEIS searches:

commas =: 3 : 0   NB. crude - I forget how to format negatives using - 
with some ": variant!!!

 q   =. 1|.' '-.~,','&,@:":"0 y
 if. # imin=. I. q = '_' do.
 q   =. '-' imin } q
 end.
)

Not a primitive adverb,  but it's my starter for 10,

Mike

On 06/03/2022 06:36, Ian Clark wrote:

Let's cheat and look it up in oeis.org …
Skip's sequence is A027688, dropping the first term
A027688 is defined as: (n^2 + n + 3)
but (n*n + n + 3) gives better results with (13 :)

q=: 13 : '(y*y) + y + 3'

q

*~ + 3 + ]

q >:i.10

5 9 15 23 33 45 59 75 93 113


Has anyone tried automating OEIS lookup? It could be the basis for a 
nifty

new primitive adverb: (...) as in:

5 9 15 23 33 ...

On Sun, 6 Mar 2022 at 02:11, Elijah Stone  wrote:


Ah, David beat me to it! :)

On Sat, 5 Mar 2022, Elijah Stone wrote:


Here's how I would do it:

    3++/\+:i.10
3 5 9 15 23 33 45 59 75 93

This preserves the 'missing' initial term of 3.  If you don't want it,
replace i.10 with >:i.10.

  -E

On Sat, 5 Mar 2022, 'Skip Cave' via Programming wrote:


I have this series:

5 9 15 23 33 

5+4

9

9+6

15

15+8

23

23+10

33


How can I use the power conjunction to generate this series?

Is there a more concise method to generate this than the power

conjunction?


Skip


Skip Cave
Cave Consulting LLC
-- 

For information about J forums see 
http://www.jsoftware.com/forums.htm

--
For information about J forums see http://www.jsoftware.com/forums.htm


--
For information about J forums see http://www.jsoftware.com/forums.htm


--
For information about J forums see http://www.jsoftware.com/forums.htm






--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Power Conjunction

2022-03-06 Thread 'Michael Day' via Programming

Late to the power party!

This is one way to automate the OEIS look-up - I'm not an expert on 
parsing the result,  but hunting for 'A', a single digit seems

a good starter:

   OEIS =: 'http://oeis.org/search?q='  NB. fails with https://... !

   getoeisseries =:{{ {{(-.{.) ' ',,/ y&{{~.x{~(i.7)+/~ x I.@:E.~ 
'A',y}}"0 '0123456789' }} RAW=:gethttp OEIS,commas y}}


   getoeisseries 5 9 15 23 33 45 59
A027688
A002522
A007954
A176271
A118403
A118401
A118400
A118407
A118402
A134586

where commas is what I always use to format series for OEIS searches:

commas =: 3 : 0   NB. crude - I forget how to format negatives using - 
with some ": variant!!!

 q   =. 1|.' '-.~,','&,@:":"0 y
 if. # imin=. I. q = '_' do.
 q   =. '-' imin } q
 end.
)

Not a primitive adverb,  but it's my starter for 10,

Mike

On 06/03/2022 06:36, Ian Clark wrote:

Let's cheat and look it up in oeis.org …
Skip's sequence is A027688, dropping the first term
A027688 is defined as: (n^2 + n + 3)
but (n*n + n + 3) gives better results with (13 :)

q=: 13 : '(y*y) + y + 3'

q

*~ + 3 + ]

q >:i.10

5 9 15 23 33 45 59 75 93 113


Has anyone tried automating OEIS lookup? It could be the basis for a nifty
new primitive adverb: (...) as in:

5 9 15 23 33 ...

On Sun, 6 Mar 2022 at 02:11, Elijah Stone  wrote:


Ah, David beat me to it! :)

On Sat, 5 Mar 2022, Elijah Stone wrote:


Here's how I would do it:

3++/\+:i.10
3 5 9 15 23 33 45 59 75 93

This preserves the 'missing' initial term of 3.  If you don't want it,
replace i.10 with >:i.10.

  -E

On Sat, 5 Mar 2022, 'Skip Cave' via Programming wrote:


I have this series:

5 9 15 23 33 

5+4

9

9+6

15

15+8

23

23+10

33


How can I use the power conjunction to generate this series?

Is there a more concise method to generate this than the power

conjunction?


Skip


Skip Cave
Cave Consulting LLC
--
For information about J forums see http://www.jsoftware.com/forums.htm

--
For information about J forums see http://www.jsoftware.com/forums.htm


--
For information about J forums see http://www.jsoftware.com/forums.htm


--
For information about J forums see http://www.jsoftware.com/forums.htm



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Cyclotomic Polynomials and FFT - was Re: polynomial division

2022-03-02 Thread 'Michael Day' via Programming
Interesting!   I've got some thoughts on this,  but it's getting late 
here,  so I'll

defer a fuller reply.

Meanwhile,  a quickie:  since the memoisation does seem to work, might 
it be better
to dispense with cache?  A pity as you put some effort into its use,  
but the code is

simpler without it.

Thanks,

Mike

On 02/03/2022 19:57, Raul Miller wrote:

I've updated the rosettacode page to include this implementation. And,
I plan on updating the j wiki polynomial division essay, also, once I
think through a bit how to describe this approach. (Descriptive
phrases and sentences would be welcome. Documentation needs good
perspectives, above all else.)

For the purpose of the rosettacode page, I used a different phrasing of rou:

rou   =: {{(,j.) r,(%:0j1),j.+|.}.r=.^o.j.(i.@%&8 % -:) y}}  NB.
roots of unity

This seems (to me) to be more concise, and straightforward, than the
purely tacit expression.

(That said, I'm not sure if this change in notation would be a good
fit for the FFT essay.)

Thanks,




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Cyclotomic Polynomials and FFT - was Re: polynomial division

2022-03-01 Thread 'Michael Day' via Programming

We're back from the Pub Quiz - 4th place, so "just outside the money"

Raul asked about roundreal - it's one of the utilities in the J wiki 
article on FFT multiplication:

   roundreal
[: (<.) 0.5 + 9

Henry wondered about dividing ffts when non-zero remainders would 
exist.  it seems to fail, so we

can only use it safely when assured of divisibility:

   fft"1 ] 8 {."1 ] 1 5 20 10 5 1,: 1 3 3 1
42 _8.2426407j29.899495 _14j_4   0.24264069j_10.100505 10 
0.24264069j10.100505 _14j4 _8.2426407j_29.899495
 8  2.4142136j5.8284271   _2j2 _0.41421356j_0.17157288  0 
_0.41421356j0.17157288 _2j_2  2.4142136j_5.8284271

   %/fft"1 ] 8 {."1 ] 1 5 20 10 5 1,: 1 3 3 1
5.25 3.8786797j3.0208153 2.5j4.5 8.1213203j21.020815 _ 
8.1213203j_21.020815 2.5j_4.5 3.8786797j_3.0208153

   ifft %/fft"1 ] 8 {."1 ] 1 5 20 10 5 1,: 1 3 3 1
_ __ _ __ _ __ _ __

OK - here's ctfft without the inadvertent calls to ct :

ctfft=:  {{ assert.0 lgl =. {:$ ctlist  =. ctfft "0 }:*/@>,{1,each q   NB. ctlist 
is 2-d table of polynomial divisors
 lgd =. # dividend  =. _1,(-y){.1  NB. (x^n) - 
1,  and its size
 lg  =. >.&.(2&^.) lgl >. lgd  NB. required 
lengths of all polynomials for fft transforms
 fftdivis=. */ fft"1 lg{."1 ctlist NB. FFT 
article doesn't deal with lists of multiplicands
 unpad roundreal ifft"1 fftdivis %~ fft lg{.dividend   NB. similar 
to FFT article's multiplication

   end.
}} M.

NB. ... and crude measure of performance

NB. timer returns elpased time in minutes & seconds
  timer'cyclotomic taskorderu 5'    NB.  before cache/memoisation 
established!

┌─┬───┐
│1.0940018│1 105 385 1365 1785│
└─┴───┘
   timer'ctfft taskorderu 5'
┌─┬───┐
│4.3660049│1 105 385 1365 1785│
└─┴───┘
NB.  continuing with cache/memoisation as above
   timer'cyclotomic taskorderu 10'
┌───┬─┐
│4 35.623001│1 105 385 1365 1785 2805 3135 6545 6545 10465│
└───┴─┘
   timer'ctfft taskorderu 10'   NB. some improvement cf cyclotomic
┌───┬─┐
│3 58.355003│1 105 385 1365 1785 2805 3135 6545 6545 10465│
└───┴─┘

So not much significant difference in the running times from those in my 
earlier report.


Cheers,

Mike

On 01/03/2022 19:17, 'Michael Day' via Programming wrote:

Oops - ct was my memoised version of cyclotomic,  while still using pDiv.
I expect the results will be much the same,  but I'll have a look 
later as I've
got to go out now.  I'll have to replace ct by ctfft - perhaps you'd 
like to try

while I'm pub-quizzing!

Cheers,

Mike


On 01/03/2022 19:02, Raul Miller wrote:

Ah, I had forgotten about that bit of code. Thanks.

Next question:

What is 'ct' here?

Thanks again,







--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Cyclotomic Polynomials and FFT - was Re: polynomial division

2022-03-01 Thread 'Michael Day' via Programming

Oops - ct was my memoised version of cyclotomic,  while still using pDiv.
I expect the results will be much the same,  but I'll have a look later 
as I've
got to go out now.  I'll have to replace ct by ctfft - perhaps you'd 
like to try

while I'm pub-quizzing!

Cheers,

Mike


On 01/03/2022 19:02, Raul Miller wrote:

Ah, I had forgotten about that bit of code. Thanks.

Next question:

What is 'ct' here?

Thanks again,




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


[Jprogramming] Cyclotomic Polynomials and FFT - was Re: polynomial division

2022-03-01 Thread 'Michael Day' via Programming

Raul Miller's and RE Boss's (revised) entries here refer:
   http://rosettacode.org/wiki/Cyclotomic_polynomial#J

I think I'm partly responsible for pDiv in this (otherwise!) nicely 
concise and elegant

presentation of J routines to derive these polynomials.
Typically,
NB. (1+5x+10x^2+10x^3+5x^4+x^5 )%(1+3x+3x^2+x^3)  = 1+2x+x^2
   1 5 10 10 5 1 pDiv 1 3 3 1
1 2 1

pDiv is essentially elementary long division realised for polynomials 
rather than numbers;
it's rather inefficient for high-order polynomials,  and I was wondering 
how to speed it up.

I found a paper by Madhu Sudan which  addresses fast polynomial division:
   http://people.csail.mit.edu/madhu/ST12/scribe/lect06.pdf
but couldn't understand his hints at an algorithm.  I _think_ it 
successively improves
approximations to the solution,  working up from a constant term, then 
modulo x^2,
then x^4 ,  but it's very muddled to my mind,  and my mind couldn't see 
how to set about it!


Then I realised a compromise is to exploit polynomial multiplication 
using Fast Fourier Transforms,
as described first for this purpose,  I believe,  by Roger Hui; Henry's 
essay is to be found at

   https://code.jsoftware.com/wiki/Essays/FFT

That article desribes polynomial multiplication,  where we multiply the 
ffts of two
polynomials extended to an appropriate length,  a suitable power of 2.  
The inverse fft

is then applied to yield the required polynomial product.
If instead we divide one fft by another,  and take the inverse fft, we 
get the polynomial

quotient!

So here's a crib of Raul's functions;  I've merged cyclotomic and 
cyclotomic000,  dispensing

with "cache" and using the memoisation afforded by M.  :
(OK in fixed width font)

ctfft=:  {{ assert.0 lgl =. {:$ ctlist  =. ct "0 }:*/@>,{1,each q   NB. ctlist is 
2-d table of polynomial divisors
 lgd =. # dividend  =. _1,(-y){.1   NB. (x^n) - 1,  
and its size
 lg  =. >.&.(2&^.) lgl >. lgd   NB. required 
lengths of all polynomials for fft transforms

 NB. really, "divisor" is the fft of the divisor!
 divisor =. */ fft"1 lg{."1 ctlist  NB. FFT article 
doesn't deal with lists of multiplicands
 unpad roundreal ifft"1 divisor %~ fft lg{.dividend NB. similar to 
article's multiplication

   end.
}} M.

NB. fft, roundreal, ifft from FFT article.

NB. Performance - poor for lower orders...
NB. taskorderu is adverbial form of taskorder with required verb as left 
argument.


   timer'cyclotomic taskorderu 5'    NB. timer returns elpased time,  
before cache/memoisation established!

┌┬───┐
│1.163002│1 105 385 1365 1785│
└┴───┘
   timer'ctfft taskorderu 5' NB. not too good here cf cyclotomic!
┌─┬───┐
│3.5719986│1 105 385 1365 1785│
└─┴───┘
NB.  continuing with cache/memoisation as above
   timer'cyclotomic taskorderu 10'
┌───┬─┐
│5 7.8180008│1 105 385 1365 1785 2805 3135 6545 6545 10465│
└───┴─┘
   timer'ctfft taskorderu 10'   NB. some improvement!
┌┬─┐
│3 52.945│1 105 385 1365 1785 2805 3135 6545 6545 10465│
└┴─┘

So - not an order of magnitude effect,  but of some interest,  I hope!

Mike

On 20/02/2022 18:32, Raul Miller wrote:

Oh, bleah... of course.

y does not change. So that should be a test on {.x -- and that reveals
that I was using the wrong values throughout that section of code.

Here's a fixed version:

pDiv=: {{
   q=. $j=. 2 + x 

Re: [Jprogramming] polynomial division

2022-02-21 Thread 'Michael Day' via Programming

Apologies for a mistake in my previous post, below.

This was where I said

   "This trick for my [function] div is analogous to allowing for
   leading decimal zeros
   in 1234 % 0.0001 in "ordinary" long division."

I'd forgotten that J's representation of polynomials is not the same as its
representation of numbers to some base;  the former has the zero power
leading (leftmost), whereas number representation has the highest power
leading.  My remark applies ok for the number representation but not
for polynomial coefficients.  In the latter case,  extra leading zeros 
add to

the power of the polynomial,  so their effect on a divisor is to DECREASE
the power of the result, the quotient.  I  haven't yet had time to correct
"div" to allow for this.

Also, I realise I'd misused "quotient" when I meant "divisor" in earlier
postings!

Not so cheerily,

Mike

On 20/02/2022 18:05, 'Michael Day' via Programming wrote:
I suppose dyad |. !0 is better than dyad }.  by keeping the result in 
place.


Anyway,   although I agree that it seems attractive to ignore those 
zeros,

your get-around doesn't seem to apply!!! - unless I'm missing something.

I embedded an echo:
...
    if. 0={.y do. j=. j-i=. 0 i.~ 0=y
echo '0={.y';x;y
...

I encountered an error in this mickey mouse test:
   1 0 0 0 0 0 0 0 0 1 pDiv 0 0 0 1 0 1
┌─┬───┬───┐
│0={.y│1 0 0 0 0 0 0 0 0 1│0 0 0 1 0 1 0 0 0 0│
└─┴───┴───┘
┌─┬───┬───┐
│0={.y│0 0 0 0 0 0 0 1 0 0│0 0 0 1 0 1 0 0 0 0│
└─┴───┴───┘
|domain error: pDiv
|   q=.q,j    #0
but maybe these arguments aren't like those for pDiv in the Rosetta 
Code task.


This trick for my div is analogous to allowing for leading decimal zeros
in 1234 % 0.0001 in "ordinary" long division.  I wonder if it's what you
intended.

NB. x % y
div =: 3 : 0    NB. similar result to Ken's dbho
:
q =. ''
NB. allow for leading zeros in quotient
if. 0 = {. y do.
   j =. 0 i.~ 0 = y
   y =. j }. y
   x =. x, 0#~ >: j
end.
yx=. y,:x
assert. 2 <: n =. 2 + x -&#

Re: [Jprogramming] polynomial division

2022-02-20 Thread 'Michael Day' via Programming
I suppose dyad |. !0 is better than dyad }.  by keeping the result in 
place.


Anyway,   although I agree that it seems attractive to ignore those zeros,
your get-around doesn't seem to apply!!! - unless I'm missing something.

I embedded an echo:
...
    if. 0={.y do. j=. j-i=. 0 i.~ 0=y
echo '0={.y';x;y
...

I encountered an error in this mickey mouse test:
   1 0 0 0 0 0 0 0 0 1 pDiv 0 0 0 1 0 1
┌─┬───┬───┐
│0={.y│1 0 0 0 0 0 0 0 0 1│0 0 0 1 0 1 0 0 0 0│
└─┴───┴───┘
┌─┬───┬───┐
│0={.y│0 0 0 0 0 0 0 1 0 0│0 0 0 1 0 1 0 0 0 0│
└─┴───┴───┘
|domain error: pDiv
|   q=.q,j    #0
but maybe these arguments aren't like those for pDiv in the Rosetta Code 
task.


This trick for my div is analogous to allowing for leading decimal zeros
in 1234 % 0.0001 in "ordinary" long division.  I wonder if it's what you
intended.

NB. x % y
div =: 3 : 0    NB. similar result to Ken's dbho
:
q =. ''
NB. allow for leading zeros in quotient
if. 0 = {. y do.
   j =. 0 i.~ 0 = y
   y =. j }. y
   x =. x, 0#~ >: j
end.
yx=. y,:x
assert. 2 <: n =. 2 + x 

Re: [Jprogramming] polynomial division

2022-02-20 Thread 'Michael Day' via Programming

Pas grand' chose -  the writer evidently meant to enter

   E =. 1 5 10 10 4 7
   ]q =. E dbho c
1 3 3 1
   ]r =. E - c t q
0 0 0 0 2 3

- or perhaps with capital Q & R rather than q & r -
... but it's clear enough with a bit of insight!

Cheers,

Mike

On 20/02/2022 16:15, Raul Miller wrote:

For some reason, when I was searching for jsoftware.com content on
polynomial division, the search did not turn up Pascal Jasmin's
article. It looks like Jasmin was focusing on speeding up extended
precision arithmetic, but I'll have to spend some time studying what
he wrote there.

Meanwhile, I'm not sure what you're asking for with respect to e and E
-- the division essay has an E already in the context of the dbho
example, doesn't it?

(I'm focusing on something else right now, and maybe overlooking
something obvious. If that's the case, please bear with me (and maybe
tell me what glaringly obvious thing it is that I'm ignoring).)

Thanks,




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] polynomial division

2022-02-20 Thread 'Michael Day' via Programming

I wrote binc as a monad,  just as a quick way of conjuring up
sets of binomial coefficients:

   binc 5
1 5 10 10 5 1

   3 binc 5 NB. does work, but not as intended!
1 3 3 1 0 0
NB. as does its commute:
   5 binc 3
1 5 10 10
... but again, not as I intended.

div is what does the division;  div a,b just
does (binc a) div binc b


I wasn't particularly interested in the performance of binc,
as Raul was seeking a division algortithm,  and binc was
just easier than typing 1 5 10 10 5 1 or whatever.

I do agree that your definition improves on mine when it
matters,  eg
   ts'binc 500x'
0.0392271 460640
   ts'1, */\ 500x (- % >:@]) i.500x' NB. x=y for my examples
0.001463 504032

I suppose it's now worth investigating the performance of
div cf dbho and divlo cf dblo excluding the overhead of binc:

   'a b' =: binc 50 20
   a (dbho-:div) b
1
   ts'a div b'
1.21e_5 5952
   ts'a dbho b'
2.63e_5 6496
   a (dblo-:divlo) b
1
   ts'a divlo b'
1.06e_5 6976
   ts'a dblo b'
1.75e_5 6496

Thanks for pointing out the overheads imposed by binc,

Mike

On 20/02/2022 16:01, Hauke Rehr wrote:

On my machine, I get

   100 timespacex '1000x binc 500x'
0.101916 957376
   100 timespacex '1, */\ 1000x (- % >:@]) i.500x'
0.00247977 680320


Am 20.02.22 um 13:30 schrieb 'Michael Day' via Programming:

    ts'1000x div 500x'
2.1598005 4815264





--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] polynomial division

2022-02-20 Thread 'Michael Day' via Programming

Bear in mind my later comments about performance on this laptop.
Either extended arithmetic or other tricks to deal with high exponents
are necessary in some cases.  And, of course, I didn't deal with edge
effects.  I've dealt with one such,  introducing assert.  , ie
   assert. 2 <: n =. 2 + x 

Re: [Jprogramming] polynomial division

2022-02-20 Thread 'Michael Day' via Programming

Just checked on the laptop running J903:

Performance not too bad for largish orders,  even with extended type, 
albeit only

binomial coefficients:
   ts'1000 diva 20'  NB. presumably overflow in binc
|NaN error: diva
|   d=.(ly{.x)    -&}.r*y
   ts'1000x diva 20x'
0.2399954 1570560
   ts'1000x diva 500x'
1.9407032 3000544
   ts'1000x div 20x'
0.7021009 3948608
   ts'1000x div 500x'
2.1598005 4815264

... and dbho still suffers a domain error for somewhat smaller inputs, 
such as here:

   ts'50 dbho 20'
|domain error: dbho
|   (d{.x)    %.(2#d=.<./$M){.M=.y+/ .*y bq x

I forgot to demonstrate that the remainders work as hoped:

   E =. 1 5 10 10 7 4
   E {{ x - y mul x div y }} 1 2 1
0 0 0 0 2 3
   divlo
div&.:|.
   (|.E) {{ x - y mul x divlo y }} 1 2 1
3 2 0 0 0 0

Mike

On 20/02/2022 11:31, 'Mike Day' via Programming wrote:

This approach,  from my A-level Maths perhaps,  seems far too simple compared 
to that of the article,  but works, on this iPad running J701 (no, it can’t run 
Ian’s J902!),  including when dbho or dblo throws a domain error for, eg, 
dividing order 50 by order 30.  I haven’t tried in J903 on the laptop yet.

BTW,  I couldn’t understand why the article shows a remainder,
]q=. e dbho c 1 3 3 1
]r=.e-c t q 0 0 0 0 2 3
But I realised there’s a missing definition, eg E =. 1 5 10 10 7 4, with e 
replaced by E in the next 2 lines.

Anyway,

NB. binomial coefficients for (1+z)^y
binc =:  !~i.@>:

NB. x % y
div =: 3 : 0NB. similar result to Ken's dbho
:
q =. ''
yx=. y,:x
n =. 2 + x 

Re: [Jprogramming] Advent of Code Day 23

2022-02-15 Thread 'Michael Day' via Programming
[I sent this yesterday (Monday) evening to Chat,  but it hasn't appeared 
in my inbox or in the Chat Archive, so
I tried again today - same non-result.  My trivial test msg appeared in 
Programming but not in Chat just now.
So: Apologies for sending rather stale stuff to the Programming Forum 
and also if we end up with two or

three copies!]

Following Raul's suggestion in the Programming Forum,  copied just 
below, I've been trying to tidy up
my code to make it somewhat more presentable,  but there's quite a lot 
of it;  what with utility functions,
and comments on performance,  the script "aoc2123new.ijs" is nearly 600 
lines long.  So I've put it up on

my Google Drive for a while,  with this link:
https://drive.google.com/file/d/1-zhVqU6IREiMuSHPGVQkRbiFQM9rVvxZ/view?usp=sharing
I _think_ it's self-contained,  but might easily have overlooked something.

The main function is "part2" and most of the work is done in "doamp", 
acronym for

DO All Moves with optional Predecessors.

When trying this link, when logged out, my browser says - "preview not 
available" but makes it available

for download.

Rather surprisingly,  my fairly naive approach is faster than Raul's for 
both parts of the day 23

problem;  less surprisingly,  it appears to take considerably more space.

ALthough the main function is called part2,  it can solve both parts!   
Here are some extracts from

runtime diagnostics.

Sent in fixed width font!
NB. My part2 method for part1 data now runs in ~ 7.5 sec and max number 
of working states = 22553

NB.    timer'part2 13; data'
NB. ┌─┬─┐
NB. │1│1│
NB. └─┴─┘
NB. ┌─┬──┐
NB. │2│28│   NB. step number & number of states
NB. └─┴──┘
...
NB. ┌─┬─┐
NB. │7│22553│
NB. └─┴─┘
...
NB. ┌──┬┐
NB. │12│8818│
NB. └──┴┘
NB. ┌──┬─┐
NB. │ found target at cost │13520│
NB. └──┴─┘
NB. ┌──┬┐
NB. │13│1992│
NB. └──┴┘
NB. ┌─┬─┐
NB. │best found = │13520│
NB. └─┴─┘
NB. ┌─┬┐
NB. │7.6790009││
NB. └─┴┘

NB. Raul's method on part1 - run at similar time,  so runtime 
environment should be similar

NB.    timer'a23 q'[q=:>LF cut data
NB. ┌─┬┐
NB. │26.148003││
NB. └─┴┘
NB.    {.costs
NB. 13520

NB. space used much better for Raul ...
NB. 1 (7!:2@])  'part2 13; data'
...
NB. ┌─┬─┐
NB. │best found = │13522│
NB. └─┴─┘
NB. 52867104

NB.   1 (7!:2@]) 'a23 mikesdata'  NB. space for Raul's fn in part 1
NB. 2528384

NB. My part2 method for part2 data now runs in ~ 12 sec and max number 
of working states = 34338

NB.    timer'part2b 28; data2'
NB. ┌─┬─┐
NB. │1│1│
NB. └─┴─┘
...
NB. ┌─┬─┐
NB. │7│34338│
NB. └─┴─┘
...
NB. ┌──┬┐
NB. │27│1021│
NB. └──┴┘
NB. ┌──┬─┐
NB. │ found target at cost │48708│
NB. └──┴─┘
NB. ┌──┬───┐
NB. │28│708│
NB. └──┴───┘
NB. ┌─┬─┐
NB. │best found = │48708│
NB. └─┴─┘
NB. ┌──┬┐
NB. │12.186││
NB. └──┴┘

NB. Raul's method, b23, for my part 2 data - run at similar time, so 
runtime environment should be similar

NB.    timer'b23 mikesdata'
NB. ┌───┬┐
NB. │3 50.538002││
NB. └───┴┘
NB.    {.costs
NB. 48708
NB.    #costs
NB. 106541

NB. space used much better for Raul ...
NB. 1 (7!:2@])  'part2 28; data2'
...
NB. ┌──┬───┐
NB. │28│708│
NB. └──┴───┘
NB. ┌─┬─┐
NB. │best found = │48708│
NB. └─┴─┘
NB. 61575008
NB.    1 (7!:2@]) 'b23 mikesdata'
NB. 9098880

Sorry not to present more information in this note,  but the topic is 
rather stale,  so

apologies are perhaps also due for raking over its ashes!

Thanks,

Mike

On 02/02/2022 14:18, Raul Miller wrote:

My solution there was also quite verbose.

Golfing an implementation might be a worthwhile exercise.

Thanks,



On 02/02/2022 14:15, 'Michael Day' via Programming wrote:

More chat on this old thread.

Finished at last!  50 stars for something or other...
It took quite a lot of tweaking to build in the restrictions to the 
"amphipods' " movements that I'd
mentioned in my msg of 23Jan, below. I'd overlooked the paragraph 
(originally without J's NB. as
Raul pointed out. The NB.s arise from the way I process the results of 
text-capture from a browser

in order to embed them in a J script.)

The problem remained difficult for me probably because I didn't find a 
decent data structure.
FWIW,  each "state" consisted of one item of cost with 7 hall cells + 
8 room cells for part 1,  or
with  7 + 16 room cells for part 2.  It might well be better to have 7 
hall cells + 4 room objects,
or even, possibly,  7 + 4 donors rooms + 4 sink rooms,  but I haven't 
explored these ideas.


The original approach considered single cell moves only,  ie those 
between adjacent pairs of
room cells,  between any outermost room cell and its two neighbouring 
hal

[Jprogramming] test

2022-02-15 Thread 'Michael Day' via Programming

Please ignore

--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Advent of Code Day 23

2022-02-02 Thread 'Michael Day' via Programming

More chat on this old thread.

Finished at last!  50 stars for something or other...
It took quite a lot of tweaking to build in the restrictions to the 
"amphipods' " movements that I'd
mentioned in my msg of 23Jan, below. I'd overlooked the paragraph 
(originally without J's NB. as
Raul pointed out. The NB.s arise from the way I process the results of 
text-capture from a browser

in order to embed them in a J script.)

The problem remained difficult for me probably because I didn't find a 
decent data structure.
FWIW,  each "state" consisted of one item of cost with 7 hall cells + 8 
room cells for part 1,  or
with  7 + 16 room cells for part 2.  It might well be better to have 7 
hall cells + 4 room objects,
or even, possibly,  7 + 4 donors rooms + 4 sink rooms,  but I haven't 
explored these ideas.


The original approach considered single cell moves only,  ie those 
between adjacent pairs of
room cells,  between any outermost room cell and its two neighbouring 
hall cells, and between
pairs of hall cells;  distances traversed were either one or two units,  
the latter where the

transient hall cell immediately outside a room was crossed.

After my epiphany,  I dispensed with hall-hall movements altogether.  
However,  it was still
tricky to limit hall-room and room-room movements according to the 
current occupancy of

the rooms.

The code is far too verbose and loopy to be worth posting!

I'll now have a look at Raul Miller's solution,  way below in this 
post,  and see what I missed.


And then back to Project Euler to see if any current problems are 
approachable!


Thanks for your patience,

Mike

On 23/01/2022 19:02, 'Michael Day' via Programming wrote:

Chat really - sorry!

An update on my progress on this so-far elusive problem for me, part2 
at least.


I _nearly_ got the right answer - tweaking the code resulted in being 
able to reach
a termination of the tree-search - too high! - another tweak - too 
low! further

tweaks - explosion of search space.

Then I noticed: 

   NB. I MISSED THIS POINT!
   NB. Once an amphipod stops moving in the hallway, it will stay in 
that spot until it can move into a room. (That
NB. is, once any amphipod starts moving, any other amphipods currently 
in the hallway are locked in place and

NB. will not move again until they can move fully into a room.)

I'd completely overlooked this restriction - my amphipods could all 
move in the hallway ...


Back to the J-board.

I'm avoiding looking at Raul's solution,  still hoping to find one for 
myself!



READ THE PAPER BEFORE TACKLING THE QUESTIONS!



Cheers,


Mike



On 13/01/2022 01:19, Raul Miller wrote:

https://adventofcode.com/2021/day/23

For day 23, we needed to solve a lazy shrimp problem.

We had a room and hallway setup (view in monospace font):

sample=:];._2 {{)n
#
#...#
###B#C#B#D###
   #A#D#C#A#
   #
}}

Ignore spaces and '#' (wall) characters. The important locations are
marked with . or letters ABCD.

Actually, also we partially ignore the '.' characters which align
vertically here with a letter -- those locations are significant but
must always be left open.

The horizontal section of dots was the 'hallway' and the sections
initially containing letters were 'rooms'.

The task involved moving each of the letters (the shrimp) into the
rooms so that the shrimp would be arranged in alphabetical order, left
to right with these constraints (stated slightly differently in the
puzzle):

(1) Each shrimp could only move twice
(2) each move must change the shrimp's horizontal position
(3) no shrimp could pass through another shrimp
(4) shrimp cannot break through the walls

also each move cost of distance * 10^'ABCD' i. shrimpId (we use
manhattan distance here, because of rule 4).

So the task was to to do all this while minimizing the total energy
cost expended by the shrimp.

For part B, the task description was the same except that the rooms
were extended with this for the middle of each room (with these
additional shrimp):

   #D#C#B#A#
   #D#B#A#C#

My initial approach here was to solve the puzzle by hand and write
some code to tally the costs. That got me part A, but part B was too
complicated for me to see the solution. It was not until a few days
ago that I managed to solve part B (but I did use my initial solution
to help debug my part B implementation (running the solver against the
part A data set)).

To actually solve this, I wound up using an A* algorithm. For part B
this still took about half an hour (and part A took significantly
longer, ironically).

A* is a highly serial approach, but has the advantage of eliminating
significant parts of some search spaces. Instead of doing a breadth
first or depth first search (which could be parallelized), A* uses a
queue of partial results which are sorted in lowest cost order.

I also maintained a "lowest cost" array for each visited state, and
when revisiting such a state I only procee

Re: [Jprogramming] Advent of Code Day 23

2022-01-23 Thread 'Michael Day' via Programming

Chat really - sorry!

An update on my progress on this so-far elusive problem for me, part2 at 
least.


I _nearly_ got the right answer - tweaking the code resulted in being 
able to reach
a termination of the tree-search - too high! - another tweak - too low! 
further

tweaks - explosion of search space.

Then I noticed: NB. I MISSED THIS POINT!

NB. Once an amphipod stops moving in the hallway, it will stay in that 
spot until it can move into a room. (That


NB. is, once any amphipod starts moving, any other amphipods currently 
in the hallway are locked in place and


NB. will not move again until they can move fully into a room.)


I'd completely overlooked this restriction - my amphipods could all move 
in the hallway ...



Back to the J-board.


I'm avoiding looking at Raul's solution,  still hoping to find one for 
myself!



READ THE PAPER BEFORE TACKLING THE QUESTIONS!



Cheers,


Mike



On 13/01/2022 01:19, Raul Miller wrote:

https://adventofcode.com/2021/day/23

For day 23, we needed to solve a lazy shrimp problem.

We had a room and hallway setup (view in monospace font):

sample=:];._2 {{)n
#
#...#
###B#C#B#D###
   #A#D#C#A#
   #
}}

Ignore spaces and '#' (wall) characters. The important locations are
marked with . or letters ABCD.

Actually, also we partially ignore the '.' characters which align
vertically here with a letter -- those locations are significant but
must always be left open.

The horizontal section of dots was the 'hallway' and the sections
initially containing letters were 'rooms'.

The task involved moving each of the letters (the shrimp) into the
rooms so that the shrimp would be arranged in alphabetical order, left
to right with these constraints (stated slightly differently in the
puzzle):

(1) Each shrimp could only move twice
(2) each move must change the shrimp's horizontal position
(3) no shrimp could pass through another shrimp
(4) shrimp cannot break through the walls

also each move cost of distance * 10^'ABCD' i. shrimpId (we use
manhattan distance here, because of rule 4).

So the task was to to do all this while minimizing the total energy
cost expended by the shrimp.

For part B, the task description was the same except that the rooms
were extended with this for the middle of each room (with these
additional shrimp):

   #D#C#B#A#
   #D#B#A#C#

My initial approach here was to solve the puzzle by hand and write
some code to tally the costs. That got me part A, but part B was too
complicated for me to see the solution. It was not until a few days
ago that I managed to solve part B (but I did use my initial solution
to help debug my part B implementation (running the solver against the
part A data set)).

To actually solve this, I wound up using an A* algorithm. For part B
this still took about half an hour (and part A took significantly
longer, ironically).

A* is a highly serial approach, but has the advantage of eliminating
significant parts of some search spaces. Instead of doing a breadth
first or depth first search (which could be parallelized), A* uses a
queue of partial results which are sorted in lowest cost order.

I also maintained a "lowest cost" array for each visited state, and
when revisiting such a state I only proceed if my new cost is lower
than my old cost.

Also,

(a) I precalculated for each shrimp, a characterization of its two
moves (a coordinate pair, with a 0 marking the undetermined part of
each move), and

(b) I assigned the total cost of a shrimp's moves to the move into the
hallway (this meant that the second move was always cheaper than any
first move, which reflects the issue that blocking the hallway would
tend to drive up the costs of other moves).

Other than that, my code is nothing special -- actually, it's rather
verbose. But because a complete test of the code is time consuming and
I did not have any further use for it, I've left it in its crude "just
got it working" state. I apologize for the lack of readability and
lack of relevant abstraction here, but I'm feeling lazy.

(That said, the code echos every intermediate state as it's being
processed, and would probably run faster if I removed that.)

The first part -- a23 -- sets up a batch of globals to be used by the solver:

a23=: {{
bounds=: $y
roomsN=: _4]\I.,y e.'ABCD'
hallN =: I.,(y='.')>"1 +./y e.'ABCD'
doorsN=: ({.roomsN) - {:$y NB. room positions in hallN
boardC=: ((#hallN)#'.'),(,y) ([-.-.)'ABCD'
locationsN=: ($y)#:hallN,,roomsN
assert. locationsN 

Re: [Jprogramming] Advent of Code Day 25

2022-01-16 Thread 'Michael Day' via Programming

Also pretty crude,  in one self-contained routine,  "move" .
It was fast and slim enough for its purpose!

   $data
137 139
   ts'move data'
0.0623268 1.69075e6
   timer'move data'
+-+---+
|0.0669937|412|
+-+---+

move =: 3 : 0 NB. long-winded but never mind
_ move y  NB. default to running until no moves available
:
'm n' =. mn =. $ c   =. y -."1 ' '
ixc   =. i. mn NB. work on indices
enbs  =. ,1 |."1 ixc   NB. ravel all east neighbours
snbs  =. ,1 |.   ixc   NB.   and all south
ie    =. I. e  =. ,c = '>' NB. ie holds all east indices
is    =. I. s  =. ,c = 'v' NB. and is all south ...
iall  =. ie, is    NB. list of all occupied slots
old   =. /:~iall   NB. for checking end condition
ct    =. 1 NB. counter - could have used x
while. 0 <: x =. <: x do.
   emvok =. iall -.@e.~ newie =. ie { enbs   NB. check occupancy of all 
of easts' neighbours
   ie    =. (ie#~ -.emvok) , newie#~ emvok   NB. crude derivation of 
the new east positions

   iall  =. ie, is   NB. reset list of all posns

NB.   similar steps for south facing set
   smvok =. iall -.@e.~ newis =. is { snbs
   is    =. (is#~ -.smvok) , newis#~ smvok
   iall  =. /:~ ie, is   NB. only needs sort for 
quick comparison with old


   if. iall -: old do. break. end.

   ct    =. >: ct  NB.  ready for next loop
   old   =. iall
end.
NB. c =. mn $ 'v' is } '>' ie } , mn$'.' NB. not needed, but 
reformat from indices to graphic

ct NB. return the count
)

For part 2,  I was a bit miffed to be told I needed another star,  the 
one I missed for day 23 part 2.

<<  NB. my NB.s  ...
NB. The experimental antenna control console lights up again:
NB. Energy source detected.
NB. Integrating energy source from device "sleigh keys"...done.
NB. Installing device drivers...done.
NB. Recalibrating experimental antenna...done.
NB. Boost strength due to matching signal phase: 1 star
NB. Only 49 stars to go.
NB. You don't have enough stars to boost the signal, though. You need 1 
more.

>>

Ah well.  Cheers,

Mike

On 15/01/2022 18:24, Raul Miller wrote:

https://adventofcode.com/2021/day/25

This is the end of the advent of code series for last year. It was a
quick wrap up.

Here, the puzzle was about waiting for sea cucumbers to get out of the
way so you could land your submarine and launch santa's sleigh (which
makes about as much sense as santa, but whatever...).

sample=:];._2 {{)n
v...>>.vv>
.vv>>.vv..

.>v>...v
v>>.>.v.

v>v.vv.v..

.>>..v...

.vv..>.>v.
v.v..>>v.v
v..v.>
}}

For this, I just built a quick step function, ran it until it stopped
and counted the steps:

stepEast=: {{
   '>' stepHalf y
}}

stepSouth=: {{
   |:'v' stepHalf|:y
}}

stepHalf=: {{
   b=. }:"1 (x,'.') E."1 y,.{."1 y
   I=. I.,b
   I2=. I.,_1 |."1 b
   ($y)$ '.' I} x I2} ,y
}}

step=: {{
   N=:N+1
   chk=. #/.~,'.>v',,y
   r=.stepSouth r0=.stepEast y
   assert. chk-:#/.~,'.>v',,r0
   assert. chk-:#/.~,'.>v',,r
}}

a25=: {{
   N=:0
   step^:_ y
   N
}}

Crude, of course, but perhaps appropriately silly?

Anyways... that wraps it up. The second part of the puzzle was to
finish up all the other days and then remotely start the sleigh.

FYI,




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Advent of Code Day 24

2022-01-16 Thread 'Michael Day' via Programming
OK - your approach is far more efficient than mine!  I suspect you did 
what I had in mind, but

couldn't quite get that mind to produce.

I see that you (Raul) didn't bother with truncating divide towards 
zero.  In testing,  I fell foul of this,

and used
   divt =: {{ s * y <.@%~ | x   [ s =. * x }}
... but I think you're ok in the actual "program" as div only has 
positive input as far as I can see!


I've eventually turned my type-a-line-at-a-time procedure into a 
J-function,  with this result

in elapsed time:

   timer' 10#.(>./,:<./) program 14 '
   done forwards creating q
   done backwards creating r
   ++-+
   |32.4|9292891491 91811211611981|
   ++-+

A glance at Windows' Task Manager revealed usage of 3~ GB ,  while space 
(7!:2@])

showed 6.7!

(I'm still pleased with the performance of my solution to day 22, though!)

The slow forward search produces q,  a boxed array of all possible 
outcomes (Z values), at each of

the 14 steps:
   ({.~5<.#)each 3 {.q NB. everything aligns in fixed font
+-+-+---+
|0|5 6 7 8 9|142 168 194 220 246|
+-+-+---+
   3{.each _3 {.q
+--+--+--+
|64953057 76834433 88715809|64953048 76834424 88715800|64953058 76834434 
88715810|

+--+--+--+

In the quite slow backward sweep, from 14 to 1,  using q,  and the fact 
that 0 is the only required
value of the final set of q, we derive r,  a boxed array of possible W Z 
pairs:


   ({.~5<.#) each _5 {.}:r    NB. fixed font!  r has an extra empty 
element

+--++--+-++
|1 9110|1 236863|9 9110|8 350|1 13|
|1 9136|1 237539|9 9136|9 351|    |
|2 9110|2 236864|  | |    |
|2 9136|2 237540|  | |    |
|3 9110|3 236865|  | |    |
+--++--+-++

   ({.~5<.#) each 5 {.r
+---++-+--+-+
|9 0|1 13|8 350|1 9115|1 350|
|   |2 13|8 351|1 9141|1 351|
|   |    |9 350|2 9116|2 350|
|   |    |9 351|2 9142|2 351|
|   |    | |  |3 350|
+---++-+--+-+

Not quite done - we need to get those combinations of Ws at each stage 
which achieve Z=0 at
the last stage.  It works forward again.  Here,  it would examine W 
pairs 9 1 and 9 2 to find both
can produce values in 350 351,  then those triples 9 1 8, 9 1 9, ... 9 2 
9 compatible with 9115 ... 9142

and so on.  That step runs quite fast and in smallish space.

   ts' 10#.(>./,:<./) (,&< r) program 14 '   NB. running with r 
provided as input;  q not needed

q & r already done
q & r already done
1.25349 2.3815e6

Here's my J-version of the alu for one input-step:
   dodata18r1 =: 3 : 0
0 dodata18r1 y
:
'p q r' =. x    NB. W X Y aren't re-used
'W Z'   =. |: 2 {."1 y  NB. Z is possibly the output of a previous run
X =. W ~: q + 26 | Z    NB. q e. [_14 15] ... _14 _12 _10 _7 _4 _2 _1 10 
11 12 13 15

    NB. X is 0 or 1
Z =. Z divt p   NB. p is 1 or 26  ... 1 <==> q > 0, 26 <==> q < 0
Z + X * r + W + Z * 25  NB. r e. [2 13]   ...   2   3   4  6  7  9 11 12 13
)

I couldn't see quite what it was doing,  though the business with 26 
does strongly hint

at something to do with the Roman alphabet.

That's not too bad,  but "program" is pretty ugly stuff.  I won't share 
that code unless

begged to do so!

Cheers,

Mike




On 15/01/2022 18:10, Raul Miller wrote:

I've got this solved now,

Eugene Nonko put me on the right path here.

The trick, from my perspective, was to convert the machine code into
executable J.  And, to ensure that I could use J's dimensionality to
manage multiple tests at the same time.

Specifically, I parameterized the three "block specific" values as C,
B and A (I initially used D for digits, but later spelled that out).

parse=: {{
   blks=: _18]\];._2 input
   C=: ". 6}."1]4 {"_1 blks
   B=: ". 6}."1]5 {"_1 blks
   A=: ". 6}."1]_3{"_1 blks
}}

digits=:14#<1+i.9

BLOCK=: {{
   W=: x{::digits
   X7=: W~:/(x{B)+26|y
   if.X7 -:&$ y do.
 ((W+x{A)*X7)+(1+25*X7)*<.y%x{C
   else.
 ((W+x{A)*X7)+(1+25*X7)*"_1 _<.y%x{C
   end.
}}

Here, x indicated the digit number (0 for the leftmost digit, 13 for
the right most digit), and y indicated the result from the previous
block (0 initially).

The if statement was because I could not figure out how to build a
rank statement that worked consistently for all of my example cases.
I'm not sure if this was due to my limited imagination, or if it's an
artifact of J's rank conjunction. Maybe I'll circle back on that
later...

With this in place, the ALU became:

ALU=: BLOCK/@((i.-14),0)

Except, of course, my laptop is not powerful enough to handle this
expression because there's too many possible digits.

But it's rather quick to run through all the possibilities to
constrain the search space:

plausible=: {{
   hist=:#need 

Re: [Jprogramming] Advent of Code Day 24

2022-01-15 Thread 'Michael Day' via Programming
... and it's one of those "days" that part 2 is ridiculously easy cf 
part 1 !!!


Mike

On 15/01/2022 21:15, 'Michael Day' via Programming wrote:
Yes, that's my guess.  I called them p q & r,  and found that p = 1 or 
26 as q is positive or negative.


So: having got one machine to run 14 times on different values of p q 
r and the previous Z, I worked back
from Z = 0 output on the 14th machine,  saving which W & Zs gave rise 
to 0,  then using those Zs on the

13th machine 

But that gave me potentially a lot of Zs - I haven't counted - so I 
then worked forward from the first machine
finding only 1452 14-ples giving rise to a final zero.  Very messy - I 
didn't really code it - but it worked!


Haven't got round to part 2 yet.

Mike

On 15/01/2022 18:12, Raul Miller wrote:

Actually, another caution here: it might be that other people's puzzle
inputs used a different block structure from my block structure.

Probably not -- it's probably the case that only my A, B and C values
differed for different people. But .. that's just "probably" because I
haven't looked at other people's puzzle input.

FYI,






--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Advent of Code Day 24

2022-01-15 Thread 'Michael Day' via Programming
Yes, that's my guess.  I called them p q & r,  and found that p = 1 or 
26 as q is positive or negative.


So: having got one machine to run 14 times on different values of p q r 
and the previous Z, I worked back
from Z = 0 output on the 14th machine,  saving which W & Zs gave rise to 
0,  then using those Zs on the

13th machine 

But that gave me potentially a lot of Zs - I haven't counted - so I then 
worked forward from the first machine
finding only 1452 14-ples giving rise to a final zero.  Very messy - I 
didn't really code it - but it worked!


Haven't got round to part 2 yet.

Mike

On 15/01/2022 18:12, Raul Miller wrote:

Actually, another caution here: it might be that other people's puzzle
inputs used a different block structure from my block structure.

Probably not -- it's probably the case that only my A, B and C values
differed for different people. But .. that's just "probably" because I
haven't looked at other people's puzzle input.

FYI,



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Advent of Code Day 24

2022-01-14 Thread 'Michael Day' via Programming
Apologies to Eugene Nonko - I'd overlooked your remarks about the great 
similarity between the

14 segments.  Plagiarism rules!

Mike

On 13/01/2022 23:34, Eugene Nonko wrote:

I did solve it, but I didn't use J for that one.

I wrote a translator in Perl that converted their assembly into C. C,
because it's easier to read, plus I thought that some brute forcing might
be required and compiled C will run faster than interpreting their assembly.

While studying that generated C code I discovered that there are 14 very
similar segments, each segment belonging to one of two types. Segments of
one type increased the value of z and segments of another type decreased
the value of z given some condition. That allowed me to reduce the size of
search space from 9^14 (too large) to 9^7 (very manageable).

-- Eugene

On Thu, Jan 13, 2022 at 2:17 PM Raul Miller  wrote:


https://adventofcode.com/2021/day/24

I have not completed the day 24 puzzle.

The day 24 puzzle has a sequence of instructions representing a
calculation to verify a model number (and conceptually enable features
based on that model number -- though part A of the puzzle does not
provide any details about that).

The processing unit performs integer calculations, and has four
registers: W, X, Y and Z.

There are six instructions, one which inputs a digit of the model
number, an add instruction, a multiply instruction, an integer
division instruction, a modulo instruction and an equals instruction.

The input instruction always inputs to register W (and is the only
instruction used to update W). The div instruction always divides by 1
or 26. The modulo instruction is always used to find a remainder
modulo 26 (and always only operates on positive values, or 0 for the
numerator). The multiply instruction seems to always multiply by 0 or
powers of 26. (To load a value into a register, the register is first
multiplied by 0 and then has another value added to it.)

A certain amount of simplifications are possible using math identities
and range constraints. But I do not have much more that's useful to
say until I've found a way of solving the puzzle.

Here's a snapshot of where I'm at, trying to work through these issues
(looks sloppy with a proportionally spaced font):

...
digit13NB. W234=: W216 inp 13   [ 1 thru 9
0  NB. X235=: X223 mul 0[ 0
add Z228 Y232  NB. X236=: X235 add Z233 [ 9 thru 5520918021
mod 26|Z233 26 NB. X237=: X236 mod 26   [ 0 thru 25
mul <.Z210%26 X223 NB. Z238=: Z233 div 26   [ 0 thru 212343000
add X237 _4NB. X239=: X237 add -4   [ _4 thru 21
eql X239 digit13   NB. X240=: X239 eql W234 [ 0 thru 1
eql X240 0 NB. X241=: X240 eql 0[ 0 thru 1
0  NB. Y242=: Y232 mul 0[ 0
25 NB. Y243=: Y242 add 25   [ 25
mul 25 X241NB. Y244=: Y243 mul X241 [ 0 thru 25
add Y244 1 NB. Y245=: Y244 add 1[ 1 thru 26
mul <.Z228%26 Y245 NB. Z246=: Z238 mul Y245 [ 0 thru 5520918000
0  NB. Y247=: Y245 mul 0[ 0
digit13NB. Y248=: Y247 add W234 [ 1 thru 9
add digit13 7  NB. Y249=: Y248 add 7[ 8 thru 16
mul Y249 X241  NB. Y250=: Y249 mul X241 [ 0 thru 16
add Z246 Y250  NB. Z251=: Z246 add Y250 [ 0 thru 5520918016

I am currently working on some tree unification mechanisms (maximum
common subtree elimination to let me better inspect the partially
resolved calculations).

I believe Eugene Nonko has solved this one, though I do not know if he
found J useful in his approach.

FYI,

--
Raul
--
For information about J forums see http://www.jsoftware.com/forums.htm


--
For information about J forums see http://www.jsoftware.com/forums.htm



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Advent of Code Day 24

2022-01-14 Thread 'Michael Day' via Programming
We haven't seen part 2 yet,  of course... there could be another sting 
in the tail,

judging by the number of part 2 finishers in the stats!

Mike

On 14/01/2022 14:01, Raul Miller wrote:

On Fri, Jan 14, 2022 at 4:15 AM 'Mike Day' via Programming
 wrote:

My data has, of course, 14 inp ops; to my surprise these were ops 0
18 36 ...  Tabulating the data as 14 boxes of 18 ops, the ops and
first arguments were identical in each box; I think this applies to
all those second arguments which were registers.  The only
differences were between corresponding integer constants.

Hmm... yes.

#~._18 <@((<<<4 5 _3)&{)\ ];._2 input
1

This will allow me to scrap a lot of useless code.

Thanks,




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Advent of Code Day 22

2022-01-13 Thread 'Michael Day' via Programming
This seems not to have appeared in the forum,  so I'm sending again. 
Apologies if it turns out to be a duplicate.


I've now modified reboot2a - it's now reboot2b (!) - to accumulate 
volumes of repeated intersection cuboids.
It performs significantly better than reboot2a,  whose time & space I 
reported earlier,  in the msg below this one:



    ts'reboot2b data'    NB. ~6x faster, ~5x smaller

0.229044 1.25469e6


ts'reboot2a data'

1.87207 6.1e6


Perhaps the code is worth sharing given its better performance;  I think 
it's self-contained apart from


the reference to the data filename.  It's reasonably aligned given a 
fixed-width font:



NB. start of script

load 'strings'
load'files'

readsteps =: ". 
@:(-.&'xyz=')@:(rplc&('-';'_'))@:(rplc&('..';','))@:(rplc&('off';'0'))@:(rplc&('on';'1')) 
every


NB. The input format with on/off x X y Y z Z is a pain - on reflection,  
it might have been better to

NB.   reorder to on/off x y z X Y Z ,  but I didn't .

data =: readsteps dtb each rawdata =: LF cut raw =: fread 
'~user/aoc2122.txt'

rawdata =: >rawdata

NB. The input is a numeric array with 7 columns output by readsteps
reboot2b =: 3 : 0
ops    =. y
NB. Initialise with first cuboid and its volume
cubs   =. ,: }. {.ops  NB. I assume first step is an "on" - no 
sense otherwise

vols   =. ,volop1 {.ops
size   =: 1    NB. count of number of intersection cuboids
'onoffs ops' =. (}.@:({."1);}."1) ops
for_op. }. ops do. NB. work on next operation
   'onoff onoffs' =. ({.;}.)onoffs
   ok =. op cubs NB. boolean array of 
existing cuboids intersecting with current one
   newcubs    =. op  ok#cubs    NB. For those that do,  
find those intersections, also cuboids
   newvols    =. -(*ok#vols)*volop1 newcubs    NB. assign opposite sign 
to next generation of cuboids
   if. onoff do.   NB. Only need to add the 
current cuboid if it's "on"

  newcubs    =. op, newcubs
  newvols    =. newvols,~ volop1 op
   end.
   cubs   =. cubs, newcubs NB. add new cuboids to 
the saved list

   vols   =. cubs +//. vols, newvols   NB. }
   cubs   =. ~. cubs   NB. }These two lines 
accumulate the volumes of identical cuboids
   NB. } ... This saves 
time and space


   size =: size >. # vols  NB. diagnostic
end.
CUBSB =: cubs  NB. diagnostic
+/vols NB. answer
)

NB. volumes of an m x 6 or m x 7 array of coords {on or off} xX yY zZ
volop1 =: 3 : '(_2 */@:>:@(-~/\) ])"1  ] _6{."1 y'

NB.   Function returns boolean answering: does cuboid x intersect with 
list of cuboids y,

NB.  x & y in {on/off} xX yY zZ format
doescuboidisx =: 3 : 0
:
pqr =. x{~ -6 4 2 NB. negative indices allow the on/off boolean to 
be present or absent

PQR =. x{~ -5 3 1
A   =. pqr >."1 y{~"1 ] -6 4 2
B   =. PQR <."1 y{~"1 ] -5 3 1
A */"1 @: <: B
)

NB.   Reasonably efficient function to return diagonal bounds of 
intersection

NB. of cuboids x & y which are in {on/off} xX yY zZ format
cuboidisx6 =: 3 : 0
:

pqr =. x{~ -6 4 2 NB. negative indices allow the on/off boolean to be 
present or absent

PQR =. x{~ -5 3 1
A   =. pqr >."1 y{~"1 ] -6 4 2
B   =. PQR <."1 y{~"1 ] -5 3 1
0 3 1 4 2 5{"1 A,.B
)

NB. end of script

My earlier remarks about the signs of intersections of different levels 
or generations still apply,
but it wasn't necessary to break up a contributing cuboid into 3 
sub-cuboids;  we only need to

keep the intersections which are always cuboids.

I'm still clueless on day 23, part 2.  I'm going to have to ignore 
Raul's next post on that one!


Mike

On 12/01/2022 14:02, 'Michael Day' via Programming wrote:
OK, sorry about the alarm just now.  I'd misunderstood how to apply 
parse.


FWIW,  I ran b22 and my "reboota" on "sample" which I'd called 
"bigexsteps" (big example steps)
and on my bespoke data set,  called "data" for some reason. "reboot2a" 
is a much slimmer version
of "reboot2".  reboot2 performs similarly to b22,  while reboot2a 
outperforms both.


NB. "timer" just reports the uncorrected runtime.

   timer'b22 bigexsteps'    NB. I've removed the top and bottom lines 
of boxing here

│0.2990036│39769202357779│

   timer'<.reboot2 bigexsteps'
│0.43900299│39769202357779│

   timer'reboot2a bigexsteps'
│0.11200714│39769202357779│

   ts
6!:2 , 7!:2@]

   ts'reboot2a bigexsteps'
0.1109503 3138464

   ts'reboot2 bigexsteps'
0.412317 3038368

   ts'b22 bigexsteps'
0.3132198 19483040

   ts'reboot2a data'
1.8453615 612

   timer'reboot2 data'    NB. 69... seconds - too slow for ts
│1 9.0530014│1.2372642e15│

   ts'b22 dat

Re: [Jprogramming] Advent of Code Day 22

2022-01-12 Thread 'Michael Day' via Programming
I've now modified reboot2a - it's now reboot2b (!) - to accumulate 
volumes of repeated intersection cuboids.
It performs significantly better than reboot2a,  whose time & space I 
reported earlier,  in the msg below this one:



    ts'reboot2b data'    NB. ~6x faster, ~5x smaller

0.229044 1.25469e6


ts'reboot2a data'

1.87207 6.1e6


Perhaps the code is worth sharing given its better performance;  I think 
it's self-contained apart from


the reference to the data filename.  It's reasonably aligned given a 
fixed-width font:



NB. start of script

load 'strings'
load'files'

readsteps =: ". 
@:(-.&'xyz=')@:(rplc&('-';'_'))@:(rplc&('..';','))@:(rplc&('off';'0'))@:(rplc&('on';'1')) 
every


NB. The input format with on/off x X y Y z Z is a pain - on reflection,  
it might have been better to

NB.   reorder to on/off x y z X Y Z ,  but I didn't .

data =: readsteps dtb each rawdata =: LF cut raw =: fread 
'~user/aoc2122.txt'

rawdata =: >rawdata

NB. The input is a numeric array with 7 columns output by readsteps
reboot2b =: 3 : 0
ops    =. y
NB. Initialise with first cuboid and its volume
cubs   =. ,: }. {.ops  NB. I assume first step is an "on" - no 
sense otherwise

vols   =. ,volop1 {.ops
size   =: 1    NB. count of number of intersection cuboids
'onoffs ops' =. (}.@:({."1);}."1) ops
for_op. }. ops do. NB. work on next operation
   'onoff onoffs' =. ({.;}.)onoffs
   ok =. op cubs NB. boolean array of 
existing cuboids intersecting with current one
   newcubs    =. op  ok#cubs    NB. For those that do,  
find those intersections, also cuboids
   newvols    =. -(*ok#vols)*volop1 newcubs    NB. assign opposite sign 
to next generation of cuboids
   if. onoff do.   NB. Only need to add the 
current cuboid if it's "on"

  newcubs    =. op, newcubs
  newvols    =. newvols,~ volop1 op
   end.
   cubs   =. cubs, newcubs NB. add new cuboids to 
the saved list

   vols   =. cubs +//. vols, newvols   NB. }
   cubs   =. ~. cubs   NB. }These two lines 
accumulate the volumes of identical cuboids
   NB. } ... This saves 
time and space


   size =: size >. # vols  NB. diagnostic
end.
CUBSB =: cubs  NB. diagnostic
+/vols NB. answer
)

NB. volumes of an m x 6 or m x 7 array of coords {on or off} xX yY zZ
volop1 =: 3 : '(_2 */@:>:@(-~/\) ])"1  ] _6{."1 y'

NB.   Function returns boolean answering: does cuboid x intersect with 
list of cuboids y,

NB.  x & y in {on/off} xX yY zZ format
doescuboidisx =: 3 : 0
:
pqr =. x{~ -6 4 2 NB. negative indices allow the on/off boolean to 
be present or absent

PQR =. x{~ -5 3 1
A   =. pqr >."1 y{~"1 ] -6 4 2
B   =. PQR <."1 y{~"1 ] -5 3 1
A */"1 @: <: B
)

NB.   Reasonably efficient function to return diagonal bounds of 
intersection

NB. of cuboids x & y which are in {on/off} xX yY zZ format
cuboidisx6 =: 3 : 0
:

pqr =. x{~ -6 4 2 NB. negative indices allow the on/off boolean to be 
present or absent

PQR =. x{~ -5 3 1
A   =. pqr >."1 y{~"1 ] -6 4 2
B   =. PQR <."1 y{~"1 ] -5 3 1
0 3 1 4 2 5{"1 A,.B
)

NB. end of script

My earlier remarks about the signs of intersections of different levels 
or generations still apply,
but it wasn't necessary to break up a contributing cuboid into 3 
sub-cuboids;  we only need to

keep the intersections which are always cuboids.

I'm still clueless on day 23, part 2.  I'm going to have to ignore 
Raul's next post on that one!


Mike

On 12/01/2022 14:02, 'Michael Day' via Programming wrote:
OK, sorry about the alarm just now.  I'd misunderstood how to apply 
parse.


FWIW,  I ran b22 and my "reboota" on "sample" which I'd called 
"bigexsteps" (big example steps)
and on my bespoke data set,  called "data" for some reason. "reboot2a" 
is a much slimmer version
of "reboot2".  reboot2 performs similarly to b22,  while reboot2a 
outperforms both.


NB. "timer" just reports the uncorrected runtime.

   timer'b22 bigexsteps'    NB. I've removed the top and bottom lines 
of boxing here

│0.2990036│39769202357779│

   timer'<.reboot2 bigexsteps'
│0.43900299│39769202357779│

   timer'reboot2a bigexsteps'
│0.11200714│39769202357779│

   ts
6!:2 , 7!:2@]

   ts'reboot2a bigexsteps'
0.1109503 3138464

   ts'reboot2 bigexsteps'
0.412317 3038368

   ts'b22 bigexsteps'
0.3132198 19483040

   ts'reboot2a data'
1.8453615 612

   timer'reboot2 data'    NB. 69... seconds - too slow for ts
│1 9.0530014│1.2372642e15│

   ts'b22 data'
|attention interrupt: b22  NB. I gave up waiting
|   b22 data

   timer'b22 data'   NB. 62.6..

Re: [Jprogramming] Advent of Code Day 22

2022-01-12 Thread 'Michael Day' via Programming

OK, sorry about the alarm just now.  I'd misunderstood how to apply parse.

FWIW,  I ran b22 and my "reboota" on "sample" which I'd called 
"bigexsteps" (big example steps)
and on my bespoke data set,  called "data" for some reason. "reboot2a" 
is a much slimmer version
of "reboot2".  reboot2 performs similarly to b22,  while reboot2a 
outperforms both.


NB. "timer" just reports the uncorrected runtime.

   timer'b22 bigexsteps'    NB. I've removed the top and bottom lines 
of boxing here

│0.2990036│39769202357779│

   timer'<.reboot2 bigexsteps'
│0.43900299│39769202357779│

   timer'reboot2a bigexsteps'
│0.11200714│39769202357779│

   ts
6!:2 , 7!:2@]

   ts'reboot2a bigexsteps'
0.1109503 3138464

   ts'reboot2 bigexsteps'
0.412317 3038368

   ts'b22 bigexsteps'
0.3132198 19483040

   ts'reboot2a data'
1.8453615 612

   timer'reboot2 data'    NB. 69... seconds - too slow for ts
│1 9.0530014│1.2372642e15│

   ts'b22 data'
|attention interrupt: b22  NB. I gave up waiting
|   b22 data

   timer'b22 data'   NB. 62.6... seconds
│1 2.6440048│1237264238382479│

I've just spotted that the 43325 intermediate cuboids produced for my 
data have only 6954
unique members,  which suggests I could have worked with counts and ~.  
, perhaps reducing

the time and space further.

Cheers,

Mike


On 11/01/2022 22:21, Raul Miller wrote:

https://adventofcode.com/2021/day/22

The day 22 puzzle was about "rebooting the reactor".

Here, we have a sequence of steps which consist of turning on, or off,
a rectangular cuboid in our coordinate system. In this puzzle each
x,y,z coordinate value was referred to as a cube.

s=: sample=:{{)n
on x=-20..26,y=-36..17,z=-47..7
on x=-20..33,y=-21..23,z=-26..28
on x=-22..28,y=-29..23,z=-38..16
on x=-46..7,y=-6..46,z=-50..-1
on x=-49..1,y=-3..46,z=-24..28
on x=2..47,y=-22..22,z=-23..27
on x=-27..23,y=-28..26,z=-21..29
on x=-39..5,y=-6..47,z=-3..44
on x=-30..21,y=-8..43,z=-13..34
on x=-22..26,y=-27..20,z=-29..19
off x=-48..-32,y=26..41,z=-47..-37
on x=-12..35,y=6..50,z=-50..-2
off x=-48..-32,y=-32..-16,z=-15..-5
on x=-18..26,y=-33..15,z=-7..46
off x=-40..-22,y=-38..-28,z=23..41
on x=-16..35,y=-41..10,z=-47..6
off x=-32..-23,y=11..30,z=-14..3
on x=-49..-5,y=-3..45,z=-29..18
off x=18..30,y=-20..-8,z=-3..13
on x=-41..9,y=-7..43,z=-33..15
on x=-54112..-39298,y=-85059..-49293,z=-27449..7877
on x=967..23432,y=45373..81175,z=27513..53682
}}

At the start of this process, every cube in the reactor is off.

Our part A puzzle asked us how many cubes would be on with values _50
.. 50 for x, y and z.

Simple enough:

use=: parse;._2

parse=:{{
   f=. 'on'-:2{.y
   good=. y e.'-',":i.10
   t=. f,__ ". good #inv good # y
   assert. 7=#t-._ __
   assert. 1e9 >>./t
   assert. _1e9 <<./t
}}

thru=: [ ~.@, <. + i.@(+*)@-~

a22=:{{
Y=. _51 >. 51 <. use y
r=. 101 101 101 $0
for_op. Y do.
  'f x0 x1 y0 y1 z0 z1'=. op
  I=. >,{(x0 thru x1);(y0 thru y1);z0 thru z1
  I=. 50+(#~ 51 -.@e."1 |) I
  r=. f I} r
   end.
   +/,r
}}

Here, I clipped coordinate values to the range _51 .. 51, found all
values inside the possibly clipped coordinates, stripped out any
references to cubes with a coordinate magnitude of 51 and set or reset
a bit for each remaining cube reference. Simple, straightforward, and
totally inadequate for part B.

Part B removes the constraint on range, and with the puzzle data
requires us to count a number of cubes in the vicinity of 1e15.

For part B, my approach was to track cuboid regions that were 'on',
and split them into smaller cuboids when this intersected with an
'off' cuboid. Conceptually, this might result in up to 26 new cuboids
(for example on -30..30,-30..30,-30..30 followed by off
-10..10,-10..10,-10..10). But, usually, we had partial overlaps which
created fewer fragments.

I could not think of a quick way of identifying arbitrary overlaps
when computing the sum I needed for the result here, so I decided I
should also split cuboids when 'on' regions overlapped.

Anyways, this meant I was storing the locations of the corners of the
cubes, and lead me to this implementation:

b22=:{{
   Y=. use y
   r=. i.0 3 2
   for_op. Y do.
 'f x0 x1 y0 y1 z0 z1'=. op
  t=. r I."1"2 (x0,x1),(y0,y1),:z0,z1
  F=.i.0
  ok=. (0 0 e."2 t)+.2 2 e."2 t
  if. 0 e. ok do.
splits=.((-.ok)#r) split((<:x0),x1),((<:y0),y1),:(<:z0),z1
assert. 3=#$splits
assert. 3 2-:}.$splits
r=.(ok#r),splits
  end.
  if. f do.
r=.r,((<:x0),x1),((<:y0),y1),:(<:z0),z1
  end.
   end.
   cubesum r
}}

NB. sum the volumes of all cuboids
cubesum=: {{
   +/*/"1-~/"1 x:y
}}

NB. split cubes in x based on cube y
split=: {{
   ;x <@split2"2 y
}}

NB. split a cube by splitting coordinates
NB. discard split cubes where all coordinates are discarded
split2=: {{
   (([: +./"1 {."1) # }."1) >>,{x <@ahand"1 y
}}

NB. coordinate range x into pieces which exclude y
NB. retain the part of y within x
NB. prefix each segment with 1 (keep) or 0 

Re: [Jprogramming] Advent of Code Day 22

2022-01-12 Thread 'Michael Day' via Programming

Whoa!  I've just tried
   use sample
which did work ok.

Mea Culpa

Mike

On 12/01/2022 13:24, 'Michael Day' via Programming wrote:
I thought I'd try running this code,  but it failed on parse.  Must 
have been my data, I thought,

so I tried parse sample,  which is defined in the following script.

   parse sample
|assertion failure
|   7=#t-._ __

I'm running J903-a,  same as Raul, I think,  under Windows 11, which 
is different,  but shouldn't

be relevant:

   JVERSION
Engine: j903/j64avx2/windows
Release-a: commercial/2021-12-16T15:15:09
Library: 9.03.08
Qt IDE: 1.9.5/5.15.2(5.15.2)
Platform: Win 64
Installer: J903 install
InstallPath: c:/d/j903
Contact: www.jsoftware.com

It's at the end of my own script for day 22,  so I doubt any of my 
definitions get in the way.


Weird

Mike




On 11/01/2022 22:21, Raul Miller wrote:

https://adventofcode.com/2021/day/22

The day 22 puzzle was about "rebooting the reactor".

Here, we have a sequence of steps which consist of turning on, or off,
a rectangular cuboid in our coordinate system. In this puzzle each
x,y,z coordinate value was referred to as a cube.

s=: sample=:{{)n
on x=-20..26,y=-36..17,z=-47..7
on x=-20..33,y=-21..23,z=-26..28
on x=-22..28,y=-29..23,z=-38..16
on x=-46..7,y=-6..46,z=-50..-1
on x=-49..1,y=-3..46,z=-24..28
on x=2..47,y=-22..22,z=-23..27
on x=-27..23,y=-28..26,z=-21..29
on x=-39..5,y=-6..47,z=-3..44
on x=-30..21,y=-8..43,z=-13..34
on x=-22..26,y=-27..20,z=-29..19
off x=-48..-32,y=26..41,z=-47..-37
on x=-12..35,y=6..50,z=-50..-2
off x=-48..-32,y=-32..-16,z=-15..-5
on x=-18..26,y=-33..15,z=-7..46
off x=-40..-22,y=-38..-28,z=23..41
on x=-16..35,y=-41..10,z=-47..6
off x=-32..-23,y=11..30,z=-14..3
on x=-49..-5,y=-3..45,z=-29..18
off x=18..30,y=-20..-8,z=-3..13
on x=-41..9,y=-7..43,z=-33..15
on x=-54112..-39298,y=-85059..-49293,z=-27449..7877
on x=967..23432,y=45373..81175,z=27513..53682
}}

At the start of this process, every cube in the reactor is off.

Our part A puzzle asked us how many cubes would be on with values _50
.. 50 for x, y and z.

Simple enough:

use=: parse;._2

parse=:{{
   f=. 'on'-:2{.y
   good=. y e.'-',":i.10
   t=. f,__ ". good #inv good # y
   assert. 7=#t-._ __
   assert. 1e9 >>./t
   assert. _1e9 <<./t
}}

thru=: [ ~.@, <. + i.@(+*)@-~

a22=:{{
    Y=. _51 >. 51 <. use y
    r=. 101 101 101 $0
    for_op. Y do.
  'f x0 x1 y0 y1 z0 z1'=. op
  I=. >,{(x0 thru x1);(y0 thru y1);z0 thru z1
  I=. 50+(#~ 51 -.@e."1 |) I
  r=. f I} r
   end.
   +/,r
}}

Here, I clipped coordinate values to the range _51 .. 51, found all
values inside the possibly clipped coordinates, stripped out any
references to cubes with a coordinate magnitude of 51 and set or reset
a bit for each remaining cube reference. Simple, straightforward, and
totally inadequate for part B.

Part B removes the constraint on range, and with the puzzle data
requires us to count a number of cubes in the vicinity of 1e15.

For part B, my approach was to track cuboid regions that were 'on',
and split them into smaller cuboids when this intersected with an
'off' cuboid. Conceptually, this might result in up to 26 new cuboids
(for example on -30..30,-30..30,-30..30 followed by off
-10..10,-10..10,-10..10). But, usually, we had partial overlaps which
created fewer fragments.

I could not think of a quick way of identifying arbitrary overlaps
when computing the sum I needed for the result here, so I decided I
should also split cuboids when 'on' regions overlapped.

Anyways, this meant I was storing the locations of the corners of the
cubes, and lead me to this implementation:

b22=:{{
   Y=. use y
   r=. i.0 3 2
   for_op. Y do.
 'f x0 x1 y0 y1 z0 z1'=. op
  t=. r I."1"2 (x0,x1),(y0,y1),:z0,z1
  F=.i.0
  ok=. (0 0 e."2 t)+.2 2 e."2 t
  if. 0 e. ok do.
    splits=.((-.ok)#r) split((<:x0),x1),((<:y0),y1),:(<:z0),z1
assert. 3=#$splits
assert. 3 2-:}.$splits
    r=.(ok#r),splits
  end.
  if. f do.
    r=.r,((<:x0),x1),((<:y0),y1),:(<:z0),z1
  end.
   end.
   cubesum r
}}

NB. sum the volumes of all cuboids
cubesum=: {{
   +/*/"1-~/"1 x:y
}}

NB. split cubes in x based on cube y
split=: {{
   ;x <@split2"2 y
}}

NB. split a cube by splitting coordinates
NB. discard split cubes where all coordinates are discarded
split2=: {{
   (([: +./"1 {."1) # }."1) >>,{x <@ahand"1 y
}}

NB. coordinate range x into pieces which exclude y
NB. retain the part of y within x
NB. prefix each segment with 1 (keep) or 0 (discard)
ahand=:{{
   'LO HI'=. x
   'lo hi'=. y
   assert. hi >: LO
   assert. HI >: lo
   lo=. lo >. LO
   hi=. h i<. HI
   ((lo~:LO),LO,lo);(0,lo,hi);(hi~:HI),hi,HI
}}

I do not remember what 'ahand' meant.

Is there a better way?

If I had assigned to each statement a "sequence order" such that
statements with a higher order would override statements with

Re: [Jprogramming] Advent of Code Day 22

2022-01-12 Thread 'Michael Day' via Programming
I thought I'd try running this code,  but it failed on parse.  Must have 
been my data, I thought,

so I tried parse sample,  which is defined in the following script.

   parse sample
|assertion failure
|   7=#t-._ __

I'm running J903-a,  same as Raul, I think,  under Windows 11, which is 
different,  but shouldn't

be relevant:

   JVERSION
Engine: j903/j64avx2/windows
Release-a: commercial/2021-12-16T15:15:09
Library: 9.03.08
Qt IDE: 1.9.5/5.15.2(5.15.2)
Platform: Win 64
Installer: J903 install
InstallPath: c:/d/j903
Contact: www.jsoftware.com

It's at the end of my own script for day 22,  so I doubt any of my 
definitions get in the way.


Weird

Mike




On 11/01/2022 22:21, Raul Miller wrote:

https://adventofcode.com/2021/day/22

The day 22 puzzle was about "rebooting the reactor".

Here, we have a sequence of steps which consist of turning on, or off,
a rectangular cuboid in our coordinate system. In this puzzle each
x,y,z coordinate value was referred to as a cube.

s=: sample=:{{)n
on x=-20..26,y=-36..17,z=-47..7
on x=-20..33,y=-21..23,z=-26..28
on x=-22..28,y=-29..23,z=-38..16
on x=-46..7,y=-6..46,z=-50..-1
on x=-49..1,y=-3..46,z=-24..28
on x=2..47,y=-22..22,z=-23..27
on x=-27..23,y=-28..26,z=-21..29
on x=-39..5,y=-6..47,z=-3..44
on x=-30..21,y=-8..43,z=-13..34
on x=-22..26,y=-27..20,z=-29..19
off x=-48..-32,y=26..41,z=-47..-37
on x=-12..35,y=6..50,z=-50..-2
off x=-48..-32,y=-32..-16,z=-15..-5
on x=-18..26,y=-33..15,z=-7..46
off x=-40..-22,y=-38..-28,z=23..41
on x=-16..35,y=-41..10,z=-47..6
off x=-32..-23,y=11..30,z=-14..3
on x=-49..-5,y=-3..45,z=-29..18
off x=18..30,y=-20..-8,z=-3..13
on x=-41..9,y=-7..43,z=-33..15
on x=-54112..-39298,y=-85059..-49293,z=-27449..7877
on x=967..23432,y=45373..81175,z=27513..53682
}}

At the start of this process, every cube in the reactor is off.

Our part A puzzle asked us how many cubes would be on with values _50
.. 50 for x, y and z.

Simple enough:

use=: parse;._2

parse=:{{
   f=. 'on'-:2{.y
   good=. y e.'-',":i.10
   t=. f,__ ". good #inv good # y
   assert. 7=#t-._ __
   assert. 1e9 >>./t
   assert. _1e9 <<./t
}}

thru=: [ ~.@, <. + i.@(+*)@-~

a22=:{{
Y=. _51 >. 51 <. use y
r=. 101 101 101 $0
for_op. Y do.
  'f x0 x1 y0 y1 z0 z1'=. op
  I=. >,{(x0 thru x1);(y0 thru y1);z0 thru z1
  I=. 50+(#~ 51 -.@e."1 |) I
  r=. f I} r
   end.
   +/,r
}}

Here, I clipped coordinate values to the range _51 .. 51, found all
values inside the possibly clipped coordinates, stripped out any
references to cubes with a coordinate magnitude of 51 and set or reset
a bit for each remaining cube reference. Simple, straightforward, and
totally inadequate for part B.

Part B removes the constraint on range, and with the puzzle data
requires us to count a number of cubes in the vicinity of 1e15.

For part B, my approach was to track cuboid regions that were 'on',
and split them into smaller cuboids when this intersected with an
'off' cuboid. Conceptually, this might result in up to 26 new cuboids
(for example on -30..30,-30..30,-30..30 followed by off
-10..10,-10..10,-10..10). But, usually, we had partial overlaps which
created fewer fragments.

I could not think of a quick way of identifying arbitrary overlaps
when computing the sum I needed for the result here, so I decided I
should also split cuboids when 'on' regions overlapped.

Anyways, this meant I was storing the locations of the corners of the
cubes, and lead me to this implementation:

b22=:{{
   Y=. use y
   r=. i.0 3 2
   for_op. Y do.
 'f x0 x1 y0 y1 z0 z1'=. op
  t=. r I."1"2 (x0,x1),(y0,y1),:z0,z1
  F=.i.0
  ok=. (0 0 e."2 t)+.2 2 e."2 t
  if. 0 e. ok do.
splits=.((-.ok)#r) split((<:x0),x1),((<:y0),y1),:(<:z0),z1
assert. 3=#$splits
assert. 3 2-:}.$splits
r=.(ok#r),splits
  end.
  if. f do.
r=.r,((<:x0),x1),((<:y0),y1),:(<:z0),z1
  end.
   end.
   cubesum r
}}

NB. sum the volumes of all cuboids
cubesum=: {{
   +/*/"1-~/"1 x:y
}}

NB. split cubes in x based on cube y
split=: {{
   ;x <@split2"2 y
}}

NB. split a cube by splitting coordinates
NB. discard split cubes where all coordinates are discarded
split2=: {{
   (([: +./"1 {."1) # }."1) >>,{x <@ahand"1 y
}}

NB. coordinate range x into pieces which exclude y
NB. retain the part of y within x
NB. prefix each segment with 1 (keep) or 0 (discard)
ahand=:{{
   'LO HI'=. x
   'lo hi'=. y
   assert. hi >: LO
   assert. HI >: lo
   lo=. lo >. LO
   hi=. h i<. HI
   ((lo~:LO),LO,lo);(0,lo,hi);(hi~:HI),hi,HI
}}

I do not remember what 'ahand' meant.

Is there a better way?

If I had assigned to each statement a "sequence order" such that
statements with a higher order would override statements with a lower
order, and constructed a conflict map for each statement, I might have
been able to sum expanding subregions 'directly' based on a
topological sort (or perhaps using some variant on graph traversal)
which put minimum complexity items first. I say this because of the
hint Mike Day 

Re: [Jprogramming] Parsing {{ }}

2022-01-11 Thread 'Michael Day' via Programming
Thanks, Bob - yes,  I do know.  Ian gave up hoping to keep J901 
compatible with my iOS 11,  later iOS 12.
My iPad is too old to support the later versions of iOS which support 
his J901 app. Liz (my email
address's other half!)  does have it on her iPad,  but I don't want to 
take over her tablet!


(Sorry - my first post had "J902" in Ian's J app;  should have been J901.)

So - I'll keep on not taking the tablets.

Cheers,

Mike

On 11/01/2022 16:23, 'robert therriault' via Programming wrote:

Hi Mike,

You may not know, but there is a new J app that Ian Clark has developed called 
J901 (although it is running a version of J903 I believe) that supports {{ }}

You can find it in the app store for the iPad or the iPhone. The interface is 
slightly different, but it is really good.

Cheers, bob


On Jan 11, 2022, at 07:34, 'Mike Day' via Programming 
 wrote:

Oh well.  I thought you might have test-bedded these forms in J before moving 
to C, Henry, in which case there might have been a readymade J script!

As for Raul’s suggestion,  that’s fine,  but, in as far as I have copied across 
to J701,  just typing the verb’s name in the session reveals the n : 0 ... ) 
form.  Essentially,  this leads to amending the J903 script,  which rather 
defeats the purpose.  I haven’t use nested ddefs.

Anyway,  I’ve got a little way into writing a basic parser which will suffice.

Thanks,

Mike

Sent from my iPad


On 11 Jan 2022, at 14:42, Henry Rich  wrote:

There is nothing I know of that does what {{ }} does.  But Raul's idea is pretty 
close.  As he notes, it fails for nested {{ }} (there is much code that expects 
the result of 5!:5 <'explicitname' to have the form m : string, but nested {{ 
}} seemed OK).

Henry Rich


On 1/11/2022 9:19 AM, Raul Miller wrote:
If you avoid nested {{ }} blocks, 5!:5 would do this.

In other words, this works:

   mean=: {{ (+/ % #) y}}
   5!:5<'mean'
3 : '(+/ % #) y'

But this would be useless for your purposes:

   mean=: {{ {{x + y}} {{u/}} {{x % y}} {{#y}} }}
   5!:5<'mean'
3 : '{{ x + y }}  {{ u/ }}  {{ x % y }}  {{ #y }}  '

FYI,


--
Raul

On Tue, Jan 11, 2022 at 4:25 AM 'Mike Day' via Programming
 wrote:

For Henry I expect: as I share code between J903 on the laptop and J701 on this 
iPad,  I’ve been avoiding the use of {{ }} objects.  (My iPad can’t support 
Ian’s new J902.)

But I was just wondering about adding a routine to the J701 start.ijs script to 
parse a J903 script translating direct definitions to their earlier 
equivalents.  And then I thought there might already be native J code to do 
this.

So: do I need to invent this wheel?

Thanks,

Mike

Sent from my iPad
--
For information about J forums see http://www.jsoftware.com/forums.htm

--
For information about J forums see http://www.jsoftware.com/forums.htm


--
This email has been checked for viruses by AVG.
https://www.avg.com

--
For information about J forums see http://www.jsoftware.com/forums.htm

--
For information about J forums see http://www.jsoftware.com/forums.htm

--
For information about J forums see http://www.jsoftware.com/forums.htm



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Advent of Code Day 21

2022-01-11 Thread 'Michael Day' via Programming

I think it's easier to post my code than to try answering your question.
I've run successfully this in a new session, so I think it's 
self-contained.


Apologies for the verbose code - it's as I wrote it,  and I haven't 
attempted

to polish it for presentation here.  The function "part2" , not shown here,
was the one I wrote before I remembered there were three throws for
each turn!   I would have preferred to deal with both players in a double-
go,  but gave up.  I do of course realise that there's a lot of 
reduplicated

code for player 2 - it would have been neater to move the code to an
ecternal function,  but I didn't!

Here it is - I hope it's not too opaque.

m10 =: 10&|&.<:   NB. modulo function for origin 1

die3   =:    ~. /:~,(1 2 3 +/])^:2 ]1 2 3
ctdie3 =:    #/.~/:~,(1 2 3 +/])^:2 ]1 2 3

part2a =: 3 : 0
21 part2a y
:
cts =. 1   $ 1
'pos1 pos2' =. 2 1 $ y
'scr1 scr2' =. 2 1 $ 0
tgt  =. x
wins =. 0 0
turns=. 0
ndie3=. # die3
while. #cts do.
   NB. player 1
   turns =. >: turns
   pos1  =. m10 , pos1 +/ die3
   cts   =. ,cts <.@*/ ctdie3
   scr1  =. pos1 + ndie3 # scr1
   pscr  =. pos1,. scr1,. ndie3#pos2,. scr2
   cts   =. pscr +//. cts
   'pos1 scr1 pos2 scr2' =. |: pscr =. ~. pscr
   if. +/ win1=. tgt <: scr1 do.
  i1   =. I. win1
  wins =. wins + 2 {. +/ i1{cts
echo 'new 1 wins at turn '; turns; wins
  cts  =. cts#~ -. win1
  pscr =. pscr#~-. win1
  'pos1 scr1 pos2 scr2' =. |: ~. pscr
   end.
   NB. player 2
   turns =. >: turns
   pos2  =. m10 , pos2 +/ die3
   cts   =. ,cts <.@*/ ctdie3
   scr2  =. pos2 + ndie3 # scr2
   pscr  =. (pos2,. scr2),.~ ndie3#pos1,. scr1
   cts   =. pscr +//. cts
   'pos1 scr1 pos2 scr2' =. |: pscr =. ~. pscr
   if. +/ win2=. tgt <: scr2 do.
  i2   =. I. win2
  wins =. wins + _2 {. +/ i2{cts
echo 'new 2 wins at turn '; turns; wins
  cts  =. cts#~ -. win2
  pscr =. pscr#~-. win2
  'pos1 scr1 pos2 scr2' =. |: ~. pscr
   end.
end.
turns; wins
)

Cheers,

Mike

On 11/01/2022 00:17, Raul Miller wrote:

Your 10&|&.<: is probably more comprehensible than my 11 |&.<:

But for part B, how did you handle the smearing of scores that
resulted from those new positions and counts?

Thanks,




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Advent of Code Day 19

2022-01-10 Thread 'Michael Day' via Programming

Thanks for this and for the previously undefined "cross" in another post.
I now see why I got 48 rotations rather than 24 - I hadn't taken on board
that all scanners used the "same" coord system,  which others have 
interpreted

as all using the same parity.

You mentioned looking for 67 or 68 of the same beacon distances.  My 
criterion
was >: 66,  iirc,  since 12 matching distinct points would have 66 = 
11.12%2 pairs of

non-zero distances.

My routine ("newexam" - exam for "examine",  and new because the old one 
didn't work)
was slightly faster than yours with the earlier "relori";  changing to 
this revised one,
just below,  halves the time of a19,  and slightly reduces the space 
used.  Both of your

versions use somewhat less space:

ts =:   6!:2 , 7!:2@]   NB.time & space

   100 ts'#~.newexam scdata'   NB. MD
0.054425904 303264
   100 ts'a19 scdata'   NB. RM - earlier vn of relori
0.063075894 271488
   100 ts'a19 scdata'   NB. RM - revised vn of relori
0.036779334 245376

Mike

On 09/01/2022 10:45, Raul Miller wrote:

Here's a better 'relori', in my opinion:

NB. y: scans from two scanners
relori=: {{
   sigs=: signature each y
   upsigs=: 0-.~(~. #~ 2 = #/.~) ;~.@,each sigs
   masks=: (*  wrote:

https://adventofcode.com/2021/day/19

Like a variety of my work on previous days, my code here is rather
bulky. Did I mention that Advent of Code was something of a bad habit
for me?

Anyways, here, not only is the code bulky, even the sample data is bulky.

Basically, for this puzzle, we were given a bunch of coordinates
beacons reported by a small set of scanners. These coordinates
contained three "flaws":

(1) They used a coordinate system which was centered on the scanner --
not a universal coordinate system.

(2) Each scanner had limited range, so no single scan had locations
for all beacons.

(3) Each scanner had an undetermined orientation.

Luckily for us, each probe "originally" had the same coordinate
system, and each probe's rotations were multiples of 90 degrees along
each axis. So there were only 24 possible orientations for each
scanner.

And, sample data looked like this:

sample=:{{)n
--- scanner 0 ---
404,-588,-901
528,-643,409
-838,591,734
390,-675,-793
-537,-823,-458
-485,-357,347
-345,-311,381
-661,-816,-575
-876,649,763
-618,-824,-621
553,345,-567
474,580,667
-447,-329,318
-584,868,-557
544,-627,-890
564,392,-477
455,729,728
-892,524,684
-689,845,-530
423,-701,434
7,-33,-71
630,319,-379
443,580,662
-789,900,-551
459,-707,401

--- scanner 1 ---
686,422,578
605,423,415
515,917,-361
-336,658,858
95,138,22
-476,619,847
-340,-569,-846
567,-361,727
-460,603,-452
669,-402,600
729,430,532
-500,-761,534
-322,571,750
-466,-666,-811
-429,-592,574
-355,545,-477
703,-491,-529
-328,-685,520
413,935,-424
-391,539,-444
586,-435,557
-364,-763,-893
807,-499,-711
755,-354,-619
553,889,-390

--- scanner 2 ---
649,640,665
682,-795,504
-784,533,-524
-644,584,-595
-588,-843,648
-30,6,44
-674,560,763
500,723,-460
609,671,-379
-555,-800,653
-675,-892,-343
697,-426,-610
578,704,681
493,664,-388
-671,-858,530
-667,343,800
571,-461,-707
-138,-166,112
-889,563,-600
646,-828,498
640,759,510
-630,509,768
-681,-892,-333
673,-379,-804
-742,-814,-386
577,-820,562

--- scanner 3 ---
-589,542,597
605,-692,669
-500,565,-823
-660,373,557
-458,-679,-417
-488,449,543
-626,468,-788
338,-750,-386
528,-832,-391
562,-778,733
-938,-730,414
543,643,-506
-524,371,-870
407,773,750
-104,29,83
378,-903,-323
-778,-728,485
426,699,580
-438,-605,-362
-469,-447,-387
509,732,623
647,635,-688
-868,-804,481
614,-800,639
595,780,-596

--- scanner 4 ---
727,592,562
-293,-554,779
441,611,-461
-714,465,-776
-743,427,-804
-660,-479,-426
832,-632,460
927,-485,-438
408,393,-506
466,436,-512
110,16,151
-258,-428,682
-393,719,612
-211,-452,876
808,-476,-593
-575,615,604
-485,667,467
-680,325,-822
-627,-443,-432
872,-547,-609
833,512,582
807,604,487
839,-516,451
891,-625,532
-652,-548,-490
30,-46,-14
}}

There will be a quiz later.  (Ok, maybe not...)

So, first thing we need here is a mechanism to parse this into
something J can handle. And, it's not obvious here, but the number of
beacons reported by each scanner was not the same. This means we need
to put the scans in boxes so they are not padded.

I decided I also wanted my parsing routine (which I named 'get') to be
idempotent. This would let me use parsed or unparsed data on the
command line -- if it was parsed already, 'get' would leave it alone.

get=: {{
if. -.'literal'-:datatype y do. y return. end.
s=. getscan;._2 rplc&(',';' ';(LF,'---');LF,'!---') y,'!'
{:"1 s   assert. (i.#s) -: ;{."1 s
}}

digits=: ".@([ -. -.)&(~.":i.10)

getscan=: {{
   (id=. digits 0{::lines); coords=. __&".@>@}. lines=. (<;._2 y)-.a:
}}

I could have made get and getscan a little simpler, by ignoring the
reported scan number. But I was working on this puzzle late at night
and it was easy for me to make mistakes.

The next problem was to piece scans together to form 

Re: [Jprogramming] Advent of Code Day 19

2022-01-09 Thread 'Michael Day' via Programming


Chat really,  but I think it still belongs here.

I've just had another look at the performance stats for day 19. The numbers
solving parts 1 & 2 are 15420 and 236, respectively., at the time of 
typing.
Weird - once you've done part 1,  there's hardly anything further to do 
in part 2 !

Perhaps it was so obvious that nobody bothered.

Still wondering how "cross" is defined.

Meanwhile,  I've only just got unstuck on day 23 part 1 - horribly 
inefficient,  but it
eventually worked  - only to discover that all the bespoke hard-wired 
code fitting
that peculiar layout is rendered pretty useless as they've changed it 
for part 2.
Hopefully,  there might be fewer degrees of freedom since the hall still 
has only 11
positions,  but there'll be many more moves to a solution.  Part 1 
already needed 31
"moves" (either shifting one or two cells) and over 1.5 million 
states.   (I didn't spot

any heuristic for filtering.)

I'll go back to the Listener Crossword, piano and or TV for the rest of 
this evening!


Cheers,

Mike

On 09/01/2022 10:45, Raul Miller wrote:

Here's a better 'relori', in my opinion:

NB. y: scans from two scanners
relori=: {{
   sigs=: signature each y
   upsigs=: 0-.~(~. #~ 2 = #/.~) ;~.@,each sigs
   masks=: (*  wrote:

https://adventofcode.com/2021/day/19

Like a variety of my work on previous days, my code here is rather
bulky. Did I mention that Advent of Code was something of a bad habit
for me?

Anyways, here, not only is the code bulky, even the sample data is bulky.

Basically, for this puzzle, we were given a bunch of coordinates
beacons reported by a small set of scanners. These coordinates
contained three "flaws":

(1) They used a coordinate system which was centered on the scanner --
not a universal coordinate system.

(2) Each scanner had limited range, so no single scan had locations
for all beacons.

(3) Each scanner had an undetermined orientation.

Luckily for us, each probe "originally" had the same coordinate
system, and each probe's rotations were multiples of 90 degrees along
each axis. So there were only 24 possible orientations for each
scanner.

And, sample data looked like this:

sample=:{{)n
--- scanner 0 ---
404,-588,-901
528,-643,409
-838,591,734
390,-675,-793
-537,-823,-458
-485,-357,347
-345,-311,381
-661,-816,-575
-876,649,763
-618,-824,-621
553,345,-567
474,580,667
-447,-329,318
-584,868,-557
544,-627,-890
564,392,-477
455,729,728
-892,524,684
-689,845,-530
423,-701,434
7,-33,-71
630,319,-379
443,580,662
-789,900,-551
459,-707,401

--- scanner 1 ---
686,422,578
605,423,415
515,917,-361
-336,658,858
95,138,22
-476,619,847
-340,-569,-846
567,-361,727
-460,603,-452
669,-402,600
729,430,532
-500,-761,534
-322,571,750
-466,-666,-811
-429,-592,574
-355,545,-477
703,-491,-529
-328,-685,520
413,935,-424
-391,539,-444
586,-435,557
-364,-763,-893
807,-499,-711
755,-354,-619
553,889,-390

--- scanner 2 ---
649,640,665
682,-795,504
-784,533,-524
-644,584,-595
-588,-843,648
-30,6,44
-674,560,763
500,723,-460
609,671,-379
-555,-800,653
-675,-892,-343
697,-426,-610
578,704,681
493,664,-388
-671,-858,530
-667,343,800
571,-461,-707
-138,-166,112
-889,563,-600
646,-828,498
640,759,510
-630,509,768
-681,-892,-333
673,-379,-804
-742,-814,-386
577,-820,562

--- scanner 3 ---
-589,542,597
605,-692,669
-500,565,-823
-660,373,557
-458,-679,-417
-488,449,543
-626,468,-788
338,-750,-386
528,-832,-391
562,-778,733
-938,-730,414
543,643,-506
-524,371,-870
407,773,750
-104,29,83
378,-903,-323
-778,-728,485
426,699,580
-438,-605,-362
-469,-447,-387
509,732,623
647,635,-688
-868,-804,481
614,-800,639
595,780,-596

--- scanner 4 ---
727,592,562
-293,-554,779
441,611,-461
-714,465,-776
-743,427,-804
-660,-479,-426
832,-632,460
927,-485,-438
408,393,-506
466,436,-512
110,16,151
-258,-428,682
-393,719,612
-211,-452,876
808,-476,-593
-575,615,604
-485,667,467
-680,325,-822
-627,-443,-432
872,-547,-609
833,512,582
807,604,487
839,-516,451
891,-625,532
-652,-548,-490
30,-46,-14
}}

There will be a quiz later.  (Ok, maybe not...)

So, first thing we need here is a mechanism to parse this into
something J can handle. And, it's not obvious here, but the number of
beacons reported by each scanner was not the same. This means we need
to put the scans in boxes so they are not padded.

I decided I also wanted my parsing routine (which I named 'get') to be
idempotent. This would let me use parsed or unparsed data on the
command line -- if it was parsed already, 'get' would leave it alone.

get=: {{
if. -.'literal'-:datatype y do. y return. end.
s=. getscan;._2 rplc&(',';' ';(LF,'---');LF,'!---') y,'!'
{:"1 s   assert. (i.#s) -: ;{."1 s
}}

digits=: ".@([ -. -.)&(~.":i.10)

getscan=: {{
   (id=. digits 0{::lines); coords=. __&".@>@}. lines=. (<;._2 y)-.a:
}}

I could have made get and getscan a little simpler, by ignoring the
reported scan number. But I was working on this puzzle late at night
and it was easy for me to make mistakes.

The next problem was to piece scans together to form 

Re: [Jprogramming] Advent of Code Day 19

2022-01-09 Thread 'Michael Day' via Programming
Raul,  would you mind defining cross?  I've tried */ and (+/  .  *) but 
neither seem to

work for me,  and I'm not sure what you mean.

As I said a few days ago,  I gave up wondering why I'd found 48 
rotations when they
asked for 24,  couldn't grasp what the meant by facing" and resorted to 
matrix divide

with rounding to yield the orientation matrix in each case.

Still stuck on day23 part 1!!!

Cheers,

Mike

On 09/01/2022 02:14, Raul Miller wrote:

https://adventofcode.com/2021/day/19

Like a variety of my work on previous days, my code here is rather
bulky. Did I mention that Advent of Code was something of a bad habit
for me?

Anyways, here, not only is the code bulky, even the sample data is bulky.

Basically, for this puzzle, we were given a bunch of coordinates
beacons reported by a small set of scanners. These coordinates
contained three "flaws":

(1) They used a coordinate system which was centered on the scanner --
not a universal coordinate system.

(2) Each scanner had limited range, so no single scan had locations
for all beacons.

(3) Each scanner had an undetermined orientation.

Luckily for us, each probe "originally" had the same coordinate
system, and each probe's rotations were multiples of 90 degrees along
each axis. So there were only 24 possible orientations for each
scanner.

And, sample data looked like this:

sample=:{{)n
--- scanner 0 ---
404,-588,-901
528,-643,409
-838,591,734
390,-675,-793
-537,-823,-458
-485,-357,347
-345,-311,381
-661,-816,-575
-876,649,763
-618,-824,-621
553,345,-567
474,580,667
-447,-329,318
-584,868,-557
544,-627,-890
564,392,-477
455,729,728
-892,524,684
-689,845,-530
423,-701,434
7,-33,-71
630,319,-379
443,580,662
-789,900,-551
459,-707,401

--- scanner 1 ---
686,422,578
605,423,415
515,917,-361
-336,658,858
95,138,22
-476,619,847
-340,-569,-846
567,-361,727
-460,603,-452
669,-402,600
729,430,532
-500,-761,534
-322,571,750
-466,-666,-811
-429,-592,574
-355,545,-477
703,-491,-529
-328,-685,520
413,935,-424
-391,539,-444
586,-435,557
-364,-763,-893
807,-499,-711
755,-354,-619
553,889,-390

--- scanner 2 ---
649,640,665
682,-795,504
-784,533,-524
-644,584,-595
-588,-843,648
-30,6,44
-674,560,763
500,723,-460
609,671,-379
-555,-800,653
-675,-892,-343
697,-426,-610
578,704,681
493,664,-388
-671,-858,530
-667,343,800
571,-461,-707
-138,-166,112
-889,563,-600
646,-828,498
640,759,510
-630,509,768
-681,-892,-333
673,-379,-804
-742,-814,-386
577,-820,562

--- scanner 3 ---
-589,542,597
605,-692,669
-500,565,-823
-660,373,557
-458,-679,-417
-488,449,543
-626,468,-788
338,-750,-386
528,-832,-391
562,-778,733
-938,-730,414
543,643,-506
-524,371,-870
407,773,750
-104,29,83
378,-903,-323
-778,-728,485
426,699,580
-438,-605,-362
-469,-447,-387
509,732,623
647,635,-688
-868,-804,481
614,-800,639
595,780,-596

--- scanner 4 ---
727,592,562
-293,-554,779
441,611,-461
-714,465,-776
-743,427,-804
-660,-479,-426
832,-632,460
927,-485,-438
408,393,-506
466,436,-512
110,16,151
-258,-428,682
-393,719,612
-211,-452,876
808,-476,-593
-575,615,604
-485,667,467
-680,325,-822
-627,-443,-432
872,-547,-609
833,512,582
807,604,487
839,-516,451
891,-625,532
-652,-548,-490
30,-46,-14
}}

There will be a quiz later.  (Ok, maybe not...)

So, first thing we need here is a mechanism to parse this into
something J can handle. And, it's not obvious here, but the number of
beacons reported by each scanner was not the same. This means we need
to put the scans in boxes so they are not padded.

I decided I also wanted my parsing routine (which I named 'get') to be
idempotent. This would let me use parsed or unparsed data on the
command line -- if it was parsed already, 'get' would leave it alone.

get=: {{
if. -.'literal'-:datatype y do. y return. end.
s=. getscan;._2 rplc&(',';' ';(LF,'---');LF,'!---') y,'!'
{:"1 s   assert. (i.#s) -: ;{."1 s
}}

digits=: ".@([ -. -.)&(~.":i.10)

getscan=: {{
   (id=. digits 0{::lines); coords=. __&".@>@}. lines=. (<;._2 y)-.a:
}}

I could have made get and getscan a little simpler, by ignoring the
reported scan number. But I was working on this puzzle late at night
and it was easy for me to make mistakes.

The next problem was to piece scans together to form the complete list
of beacons (using the coordinate system of the scanner #0).

There's a variety of approaches which could have been used here. Mine was this:

(a) I would measure the distance between each pair of *beacons*
reported by each scanner. The distance between any beacon pair was
guaranteed to be fixed for every scanner which included both of those
beacons.

(b) For each pair of *scanners*, I would find and count the beacon
distance lists which they had in common. Scanners which were closer
together should have more beacons in common with each other than
scanners which were farther apart.

Looking at the data, I saw that most scanners had at least one other
scanner which reported 67 or 68 of the same beacon distances, the next
most frequent commonality was 17 or 18 of the same 

Re: [Jprogramming] AOC Day 22 - was Re: Advent of Code Day 14

2022-01-06 Thread 'Michael Day' via Programming
I have gone back and improved the code a bit for day 22 part 2 - well,  
quite a lot.


Part 2 is now solved in ~1 second in ~ 6.5 MB ! (It was 30-60x slower 
and perhaps

1500x more space-consuming.)

Will comment more when Raul presents his comments next week.

Mike


On 06/01/2022 09:19, 'Mike Day' via Programming wrote:

ca 1/3 & 1/8 on time & space - quite an improvement!  Well done!

Mike

Sent from my iPad


On 6 Jan 2022, at 05:42, Raul Miller  wrote:

Mine isn't a whole lot better than that, but I guess it's a little better.

   timespacex 'b22 input'
24.2392 1.15927e9

FYI,

--
Raul

On Wed, Jan 5, 2022 at 7:08 PM 'Michael Day' via Programming
 wrote:

I don't think there are any spoilers here.

Well,  I have at last managed to do part 2 of day 22,  one of those
"days" when part 2 is considerably harder
than part 1.  (I've found day 22 the hardest so far:  day 21 part2's
Dirac Die was tricky,  because I'd forgotten every go
had 3 throws,  but not really hard;  day 19 was quite hard,  needing
working out how to reconcile "scanners";
I spent ages on day 18's snailfish having gone down a cul-de-sac with a
nested array approach!)

It managed to run within a RAM of ~ 14GB usable at the expense of taking
70 seconds!  My data-structure
wasn't ideal to say the least,  though the initial set of 420 "ops"
generated only ~ 43000 small objects.
The space actually used appears fo be ~9GB:

 7!:2@] 'reboot2 data'

8721760


There must be a better way,  but at least this slow-coach method didn't
need a super-computer!

I might inspect the efficiency,  but probably not - it's taken too long
to find a working solution!

Looking forward to Raul's posting next week!

Cheers,

Mike


On 04/01/2022 13:49, 'Mike Day' via Programming wrote:
As I recall, a killer question until one realises there’s no need to preserve 
the order;  then it’s just a matter of maintaining counts, as you observe.

I’m currently wondering how to acquire the tera- or peta-bytes of storage to 
deal with day 22 part 2.  Part 1 is easy, of course.  No spoilers,  though.  I 
haven’t given up yet!

Cheers,

Mike

Sent from my iPad


On 4 Jan 2022, at 03:06, Raul Miller  wrote:

https://adventofcode.com/2021/day/14

For day 14, we were supposed to run a "polymerization sequence" for N
steps, and then find the difference in the quantity between the most
common and least common elements of the sequence.

For part A, we were supposed to run 10 steps. For part B, we were
supposed to run 40 steps.

The sample data looked like this:


.. [truncated]

--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
--
For information about J forums see http://www.jsoftware.com/forums.htm

--
For information about J forums see http://www.jsoftware.com/forums.htm

--
For information about J forums see http://www.jsoftware.com/forums.htm


--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Advent of Code Day 16

2022-01-06 Thread 'Michael Day' via Programming

So your parse is akin to my unpack.

I was going to say that my "operator" and "literal" were both dyadic 
too,  but checked,
and now find I'm wrong.  But "unpack" itself is indeed dyadic;  irs 
input is initially 0 _ ,
holding the required part 1 total,  and the number of sub-packets where 
relevant.


I didn't know about apply, 128!:2 . Live and learn!

I find that both our unpacks run in ~ 0.005 seconds,   but mine uses 
~ten times as
much space,  a comparison much as in day 22, discussed earlier. Maybe 
that's because
you have globals,  pos,  packet,  whereas I'm recursively applying 
operator and unpack

to "tail"  which is of course a partial packet.

Mike

On 06/01/2022 11:42, Raul Miller wrote:

Mine is recursive: parse calls operator, and operator calls parse.

That's why I added a trace mechanism (an echo statement showing the
string I used to represent what would happen to the value, along with
the value itself, for each packet) -- so that I could visualize what
was happening.

By the way, re-reading this, I see that my naming convention might
have been confusing -- 'operator' was a dyadic verb. I passed in a
string showing the operation which would be applied to the result.
Also, I could have instead used 128!:2 to implement the operation
itself. So I should also have added a "this could have been done
better" disclaimer.

Thanks,




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


[Jprogramming] AOC Day 22 - was Re: Advent of Code Day 14

2022-01-05 Thread 'Michael Day' via Programming

I don't think there are any spoilers here.

Well,  I have at last managed to do part 2 of day 22,  one of those 
"days" when part 2 is considerably harder
than part 1.  (I've found day 22 the hardest so far:  day 21 part2's 
Dirac Die was tricky,  because I'd forgotten every go
had 3 throws,  but not really hard;  day 19 was quite hard,  needing 
working out how to reconcile "scanners";
I spent ages on day 18's snailfish having gone down a cul-de-sac with a 
nested array approach!)


It managed to run within a RAM of ~ 14GB usable at the expense of taking 
70 seconds!  My data-structure
wasn't ideal to say the least,  though the initial set of 420 "ops" 
generated only ~ 43000 small objects.

The space actually used appears fo be ~9GB:

    7!:2@] 'reboot2 data'

8721760


There must be a better way,  but at least this slow-coach method didn't 
need a super-computer!


I might inspect the efficiency,  but probably not - it's taken too long 
to find a working solution!


Looking forward to Raul's posting next week!

Cheers,

Mike

On 04/01/2022 13:49, 'Mike Day' via Programming wrote:

As I recall, a killer question until one realises there’s no need to preserve 
the order;  then it’s just a matter of maintaining counts, as you observe.

I’m currently wondering how to acquire the tera- or peta-bytes of storage to 
deal with day 22 part 2.  Part 1 is easy, of course.  No spoilers,  though.  I 
haven’t given up yet!

Cheers,

Mike

Sent from my iPad


On 4 Jan 2022, at 03:06, Raul Miller  wrote:

https://adventofcode.com/2021/day/14

For day 14, we were supposed to run a "polymerization sequence" for N
steps, and then find the difference in the quantity between the most
common and least common elements of the sequence.

For part A, we were supposed to run 10 steps. For part B, we were
supposed to run 40 steps.

The sample data looked like this:


.. [truncated]

--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Advent of Code Day 11

2022-01-01 Thread 'Michael Day' via Programming
Yes,  the second part was again pretty trivial,  at least when, as in 
J,  you can

use the power operation.

I seem to have solved it on my iPad, running iOS 12.5.5,  which is too 
obsolete to
support Ian Clark's new J902 version,  so it's stuck in J701,  so not up 
to {{ }} and

lots more.

I can never remember the tessellation idiom when I need it,  so I 
ravelled the
octopuses,  there are exactly 100,  and set up a global array of 
neighbours.

Here are some:

   7 {. nbrs  NB. I've removed the horizontal box chars, as alignment fails
|1 10 11|0 2 10 11 12|1 3 11 12 13|2 4 12 13 14|3 5 13 14 15|4 6 14 15 
16|5 7 15 16 17|


   (20 + i.4) { nbrs
|10 11 21 30 31|10 11 12 20 22 30 31 32|11 12 13 21 23 31 32 33|12 13 14 
22 24 32 33 34|


I won't bore you with their derivation,  but I suppose this is the main 
difference between my
approach and Raul's - I don't need a "propagate" function,  at the 
expense of a global boxed

list of coordinates.

Here's the step function much as I wrote it - the name was all my own 
work! - there was no

need to soup it up for speed or space given the small size of the problem.

step =: 3 : 0
if. */ 0 = y do.
   y
   return.
end.
d   =. >: y    NB. Initial increment to "energy"
done=. ''
while. 10 e. d do.
   j10 =. I. 10 = d   NB. indices of flashers
   i10 =. j10 -.~ ; j10 { nbrs NB. indices of their neighbours
   done=. ~. done, j10
   c10  =. #/.~ i10  NB. count up flashes seen by those nbrs
   i10 =. ~. i10
   d10 =. 10 <. c10 + i10 { d
   d   =. d10 i10 } d    NB. could be cleaner!
   d   =. 0  done } d
end.
d
)

I didn't wrap the application of step for part 1.  Here's the example 
result:


   $ex   NB. the data is ravelled...
100
   +/0=,step^:(i.11) ex
204

As I said,  part 2 is trivial for J-users:
   <:#step^:a: ex   NB. on the sample data again
195


On 01/01/2022 00:17, Raul Miller wrote:

https://adventofcode.com/2021/day/11

The story for the day 11 puzzle is that we have 100 octopuses (10
rows, 10 columns) which are flashing, each with an intensity level
which is a single digit number:

sample=:".@>;._2{{)n
5483143223
2745854711
5264556173
6141336146
6357385478
4167524645
2176841721
6882881134
4846848554
5283751526
}}

The 'flashing' algorithm being applied here is:

(1) increment every octopus's intensity by 1.
(2) every octopus flashes when its intensity increases past 9.
(3) every flash increases the intensity of the eight adjacent
octopuses by 1. Adjacent, here, means horizontally adjacent or
vertically adjacent or diagonally adjacent.
(4) Iterate steps 2 and 3 until no more octopuses increase their
intensity past 9.
(5) Every octopus which flashed has its intensity set to zero.

This algorithm is a single "step" in a time sequence.

The problem for part A was to count the total number of flashes in the
first 100 steps.

My initial implementation was rather messy. Here's a cleaned up version:

First, I needed a way of propagating those 1s from adjacent flashes.
Note that we can simplify here, because we do not care about the exact
intensity of an octopus which has already flashed.

propagate=: [:+/"1 (1,:3 3) ,;._3 pad
pad=: 0,0,.0,~0,.~]

With that, I could build my step function:

step=: {{
   mask=.1"0 y
   next=. 1+y
   while. 1 e.,extra=. 9


--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Advent of Code Day 10

2021-12-31 Thread 'Michael Day' via Programming

Neater!

Cheers,

Mike

On 31/12/2021 19:19, Raul Miller wrote:

That is a different approach.

I had avoided even thinking about that approach, because of speed
concerns. But, testing a simple implementation on the large aoc
"puzzle input", I see that this approach completes in less than 17
milliseconds, Plus it makes reasoning about the problem really simple.

Here's my implementation of your approach:

pairs=: '()','[]','{}',:'<>'
reduce=: rplc&(pairs;"1'')

timespacex 'reduce^:_;._2 input'
0.016612 29920

And, playing with this (extending a working example until I got to the
point I wanted), part 1 looks like this:

red=: reduce^:_;._2 sample
'L R'=:|:pairs
R
)]}>

bad=: red <./@i."1 R
cost=: 3 57 1197 25137 0 {~ R i. bad {"_1 red,.' '
+/cost
26397

And, the second part becomes:

require'stats'
median 5 p.~ 5|1+L i."1 (0=cost)#red
288957

I wish I had thought of that!

Thanks,




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Advent of Code Day 10

2021-12-31 Thread 'Michael Day' via Programming

Sorry - always forget something - bkts ???

    bkts =: 4 2 $'()[]{}<>'

I hope the rest is self-contained,  but apologies for the ungraceful
character non-alignment.  I'd avoided graphic boxing characters and
had sent in fixed-width font where it mattered!

Mike



On 31/12/2021 15:58, 'Michael Day' via Programming wrote:
I _think_ I used a somewhat different approach.  I'll only deal with 
part 1 as

part 2 doesn't add much complexity.

This approach is simple -  remove adjacent pairs of opening and closing
brackets of the same kind until there are none.  The function is called
reduce:

I've added echo lines only for this email.

reduce =: 3 : 0
a    =. 1 _1 ,2 _2,3 _3,:4 _4
nums =. +/+/"2 a *"2 3 bkts =/ y -.' '
NB. this would have been much better! :
NB. nums =. (,a){~ (,bkts) i.' '-.~{.ex
while. +/ msk =. +/(E.& nums)"1 a do.
  msk =. -. msk + 0, }: msk NB. matching adjacent pair gives 0 0
  nums=. msk#nums
end.
if. 0 > <./ nums do.  NB. "corrupted"
   r =. +/ 3 57 1197 25137 {~ <: |{.(#~ <&0  ) nums
echo 'corrupted'; r
else. NB. "incomplete"
echo 'ignore';   ,|.(}."1 bkts){~<: nums
   r =. 0
end.
r
)

We know if a line is corrupted if we can't reduce it any more AND it 
still contains

some close brackets.

I called the example data "ex" - I held it as a 2-d character array.

Here it goes,  with the echo's firing:

   +/reduce"1 ex
+--++
|ignore|}}]])})]|
+--++
+--+--+
|ignore|)}>]})|
+--+--+
+-++
|corrupted|1197|
+-++
+--+-+
|ignore|}}>}>|
+--+-+
+-+-+
|corrupted|3|
+-+-+
+-+--+
|corrupted|57|
+-+--+
+--+-+
|ignore|]]}}]}]}>|
+--+-+
+-+-+
|corrupted|3|
+-+-+
+-+-+
|corrupted|25137|
+-+-+
+--++
|ignore|])}>|
+--++
26397

Cheers,

Mike



On 31/12/2021 02:41, Raul Miller wrote:

https://adventofcode.com/2021/day/10

For day 10's puzzle, the first part was determining whether
collections of braces and brackets were properly formed.  The
allowable pairs were '()', '[]', '{}', and '<>', and the sample data
looked like this:

sample=:{{)n
[({(<(())[]>[[{[]{<()<>>
[(()[<>])]({[<{<<[]>>(
{([(<{}[<>[]}>{[]{[(<()>
{<>}<{<{<>}{[]{[]{}
[[<[([]))<([[{}[[()]]]
[{[{({}]{}}([{[{{{}}([]
{<[[]]>}<{[{[{[]{()[[[]
[<(<(<(<{}))><([]([]()
<{([([[(<>()){}]>(<<{{
<{([{{}}[<[[[<>{}]]]>[]]
}}

Specifically, for the first part, we were to find the first illegal
character on each line, each of which were assigned a score, and sum
those scores.

   So the result line for that part would look something like this:

    +/ 3 57 1197 25137 {~ ')]}>' i. bad

So I built a brute force lexical analyzer which returned empty for
legal lines and the first bad character and its index for illegal
lines:

scanline=:{{
   next=.''
   for_ch. y do.
  select. ch
    case.'(' do. next=. next,')'
    case.'[' do. next=. next,']'
    case.'{' do. next=. next,'}'
    case.'<' do. next=. next,'>'
    case.')';']';'}';'>' do.
  if. ch={: next do.
    next=.}: next
  else.
    ch;ch_index return.
  end.
    case. do. echo 'unexpected';ch;ch_index throw.
  end.
   end.
   ''
}}

The basic approach here is to have an intermediate result which is a
stack of the expected terminating characters and to report on failed
matches.

I left the character index in the result to help me debug my code if I
had done something horribly wrong.

Since I was returning boxed characters from that routine for the error
cases, I decided my lookup should normalize both the left and right
arguments to i. to be boxed strings:

aoc10a=:{{
   err=. {."1>(<@scanline;._2 y)-.a:
   +/((;:')]}>')i.&:(,each) err){3 57 1197 25137
}}

For part b, we instead were to report on the lines without illegal
characters and score based on the missing terminating
brackets/braces/...

Here, the scoring was 1 + the index into ')]}>', multiplied by 5 ^
index into that particular string.

So I took the above code and tweaked it to return the unfinished
stacks on "good lines":

scan2=:{{
   next=.''
   for_ch. y do.
  select. ch
    case.'(' do. next=. next,')'
    case.'[' do. next=. next,']'
    case.'{' do. next=. next,'}'
    case.'<' do. next=. next,'>'
    case.')';']';'}';'>' do.
  if. ch={: next do.
    next=.}: next
  else.
    '' return.
  end.
    case. do. echo 'unexpected';ch;ch_index throw.
  end.
   end.
   |.next
}}

My initial implementation of the scoring mechanism was a bit messy,
but there's no point burdening

Re: [Jprogramming] Advent of Code Day 10

2021-12-31 Thread 'Michael Day' via Programming
I _think_ I used a somewhat different approach.  I'll only deal with 
part 1 as

part 2 doesn't add much complexity.

This approach is simple -  remove adjacent pairs of opening and closing
brackets of the same kind until there are none.  The function is called
reduce:

I've added echo lines only for this email.

reduce =: 3 : 0
a    =. 1 _1 ,2 _2,3 _3,:4 _4
nums =. +/+/"2 a *"2 3 bkts =/ y -.' '
NB. this would have been much better! :
NB. nums =. (,a){~ (,bkts) i.' '-.~{.ex
while. +/ msk =. +/(E.& nums)"1 a do.
  msk =. -. msk + 0, }: msk NB. matching adjacent pair gives 0 0
  nums=. msk#nums
end.
if. 0 > <./ nums do.  NB. "corrupted"
   r =. +/ 3 57 1197 25137 {~ <: |{.(#~ <&0  ) nums
echo 'corrupted'; r
else. NB. "incomplete"
echo 'ignore';   ,|.(}."1 bkts){~<: nums
   r =. 0
end.
r
)

We know if a line is corrupted if we can't reduce it any more AND it 
still contains

some close brackets.

I called the example data "ex" - I held it as a 2-d character array.

Here it goes,  with the echo's firing:

   +/reduce"1 ex
+--++
|ignore|}}]])})]|
+--++
+--+--+
|ignore|)}>]})|
+--+--+
+-++
|corrupted|1197|
+-++
+--+-+
|ignore|}}>}>|
+--+-+
+-+-+
|corrupted|3|
+-+-+
+-+--+
|corrupted|57|
+-+--+
+--+-+
|ignore|]]}}]}]}>|
+--+-+
+-+-+
|corrupted|3|
+-+-+
+-+-+
|corrupted|25137|
+-+-+
+--++
|ignore|])}>|
+--++
26397

Cheers,

Mike



On 31/12/2021 02:41, Raul Miller wrote:

https://adventofcode.com/2021/day/10

For day 10's puzzle, the first part was determining whether
collections of braces and brackets were properly formed.  The
allowable pairs were '()', '[]', '{}', and '<>', and the sample data
looked like this:

sample=:{{)n
[({(<(())[]>[[{[]{<()<>>
[(()[<>])]({[<{<<[]>>(
{([(<{}[<>[]}>{[]{[(<()>
{<>}<{<{<>}{[]{[]{}
[[<[([]))<([[{}[[()]]]
[{[{({}]{}}([{[{{{}}([]
{<[[]]>}<{[{[{[]{()[[[]
[<(<(<(<{}))><([]([]()
<{([([[(<>()){}]>(<<{{
<{([{{}}[<[[[<>{}]]]>[]]
}}

Specifically, for the first part, we were to find the first illegal
character on each line, each of which were assigned a score, and sum
those scores.

   So the result line for that part would look something like this:

+/ 3 57 1197 25137 {~ ')]}>' i. bad

So I built a brute force lexical analyzer which returned empty for
legal lines and the first bad character and its index for illegal
lines:

scanline=:{{
   next=.''
   for_ch. y do.
  select. ch
case.'(' do. next=. next,')'
case.'[' do. next=. next,']'
case.'{' do. next=. next,'}'
case.'<' do. next=. next,'>'
case.')';']';'}';'>' do.
  if. ch={: next do.
next=.}: next
  else.
ch;ch_index return.
  end.
case. do. echo 'unexpected';ch;ch_index throw.
  end.
   end.
   ''
}}

The basic approach here is to have an intermediate result which is a
stack of the expected terminating characters and to report on failed
matches.

I left the character index in the result to help me debug my code if I
had done something horribly wrong.

Since I was returning boxed characters from that routine for the error
cases, I decided my lookup should normalize both the left and right
arguments to i. to be boxed strings:

aoc10a=:{{
   err=. {."1>(<@scanline;._2 y)-.a:
   +/((;:')]}>')i.&:(,each) err){3 57 1197 25137
}}

For part b, we instead were to report on the lines without illegal
characters and score based on the missing terminating
brackets/braces/...

Here, the scoring was 1 + the index into ')]}>', multiplied by 5 ^
index into that particular string.

So I took the above code and tweaked it to return the unfinished
stacks on "good lines":

scan2=:{{
   next=.''
   for_ch. y do.
  select. ch
case.'(' do. next=. next,')'
case.'[' do. next=. next,']'
case.'{' do. next=. next,'}'
case.'<' do. next=. next,'>'
case.')';']';'}';'>' do.
  if. ch={: next do.
next=.}: next
  else.
'' return.
  end.
case. do. echo 'unexpected';ch;ch_index throw.
  end.
   end.
   |.next
}}

My initial implementation of the scoring mechanism was a bit messy,
but there's no point burdening you with that. Instead:

score=:5 #. 1 + ')]}>' i. ]

Though I could have used

score=:5 p.~ 1 + ')]}>' i. |.

To actually complete the second part, we needed to find the median score:

aoc10b=:{{
   compl=. (<@scan2;._2 y)-.a:
   ({~ <.@-:@#)/:~ score every compl
}}

And that was it for day 10.




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Advent of Code Day 6

2021-12-27 Thread 'Michael Day' via Programming
Yes, a nice insight,  I suppose,  but only nice,  and by no means 
necessary!

Many Project Euler problems require this sort of thing in the tool-box!
Also,  some sort of counting of cases is often nearly essential for PE.

One of my finite arithmetic routines,  written pre-{{ ... }}
NB. Matrix x to high power y modulo m
NB. (adapted from Roger Hui,  perhaps...)
mMpower =: 1 : 0
:
M  =. = i.# M0 =. x
b  =. #:y
mm =. <.@:(m| +/ . *)
while.#b do.
  if. {:b do. M =. M0 mm M end.
  M0 =. mm~ M0   NB. square it
  b  =. }:b
end.
M
)

Set the modulus to 0 here:

   count 3 4 3 2 1
0 1 1 2 1 0 0 0 0
   +/(count 3 4 3 2 1) +/ . * (mat1(0 mMpower) 80)   NB. mat1 as Raul's 
9x9 matrix

5934
   +/(count 3 4 3 2 1) +/ . * (mat1(0 mMpower) 256)
26984457539

Advent of Code problems are, mostly,  nothing like as demanding of
computer resources as PE.  The time improvement is pretty irrelevant
here:

   ts'+/(+/ . *)^:256 ct' [ ct =: count 3 4 3 1 2
5.5e_5 3008

   ts'+/ct +/ . * mat1(0 mMpower) 256'
2.17e_5 8512

(Once we've counted the different classes of fish,  it's also pretty 
irrelevant

how many are in the 300 samples.)

But it's good to practise for when we DO need the technique.

Cheers,

Mike


On 27/12/2021 14:39, Raul Miller wrote:

That's a really good insight.

Conceptually, this would be
1 (<0 6)}(=/1|.])i.9
0 0 0 0 0 0 1 0 1
1 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0
0 0 0 0 1 0 0 0 0
0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 1 0

But we want to multiply on the right (for ^:) instead of on the left.
So, instead
M=: |:1 (<0 6)}(=/1|.])i.9
or
M=: 1 (<6 0)}(=/~1|.])i.9

+/M+/ .*^:256 <:#/.~(i.9),3,4,3,1,2
26984457539

Or, squaring M, 8 times:
+/(+/ .*~^:8 M)+/ .*<:#/.~(i.9),3,4,3,1,2
26984457539

Actually, the squaring technique would have allowed us to left
multiply our representation of the updates:

+/(<:#/.~(i.9),3,4,3,1,2)+/ .*+/ .*~^:8]1(<0 6)}(=/1|.])i.9
26984457539

Pretty concepts.

Thanks,




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Advent of Code day 2 + comment on day 18

2021-12-22 Thread 'Michael Day' via Programming

Thanks, Raul

I've checked what "use" does with an example.  I won't study its 
details,  though,  not wanting
to crib.  I will say though that the output is similar to my interim 
results in processing the data.
My mistake appears to have been to keep the verbose format and try to 
reproduce it,  ie with
lots of indexing locations of brackets and so on and generally getting 
in a muddle.   As usual,

the key seems to be to find a decent data structure.

Nice to know it can be done,  and can be understood! Congratulations!

Cheers,

Mike

On 22/12/2021 21:27, Raul Miller wrote:

use=: {{
depth=. +/\-/'[]'=/y
sel=. _1|.' .'E.' .'{~mask=.-.y e. '[,]'
vals=.".mask #inv mask#y
assert. (+/sel)=#vals
(sel#depth),:vals
}}



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Advent of Code day 2 + comment on day 18

2021-12-22 Thread 'Michael Day' via Programming
Apologies - more chat than programming,  but: fwiw,  for part 1,  I just 
defined simple
one-liner functions "forward" etc which worked ok.  For part 2, they 
needed redefining,  and,

yes, I used direct defs;  nothing as sophisticated as fold!

I've done days 1-17,  mostly straightforward,  some very fiddly.

But I'm stuck at 18,  which is v complicated in its explanation.  I 
started with boxes in J,
but found navigation hard - I haven't used nested structures much in J - 
so resorted to
working on the untranslated rows,  using ;: to separate the symbols & 
numbers,  but
couldn't get all the examples to reproduce the stated results!    So 
I've wasted yet more time
learning - or relearning - how to deal with nested arrays in Dyalog APL 
and remembering how
to use John Scholes' dfns.  Managed to "reduce" the "addition" of the 
first pair of snailnumbers,
but reducing the "addition" of the third line defeats me.  I suppose I'm 
sometimes inserting

some result at the wrong depth.

I've spent so much time on that that I'll probably give up the rest!

Cheers,

Mike


On 22/12/2021 14:59, Raul Miller wrote:

(responding to 
http://jsoftware.com/pipermail/programming/2021-December/059436.html#)

I am not sure that I thought this example out well enough for it to be
good on an examples page.

For instance, after thinking about it for just a few minutes, I realized that

b2fold=: 0 0 0&(}.F..{{
   'dH0 dA0 N'=. x
   'A H D'=. y
   dA=: N*dA0
   dH=: N*dH0
   dD=: A*dH
   y+dA,dH,dD
}})

b2=: {{*/b2fold y}}

would have been clearer.

(Originally I was using ]F.. and commenting that I needed to drop the
first item of the result. But isn't it clearer to include that drop
mechanism with the fold implementation?)

But (and this is worse): this particular example lacks utility, which
means that it's not going to be very interesting for anyone.

Other opportunities will arise, though. And I think that your concept
of linked example pages is a good one and worth following up on.

Thanks,




--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] JHS update

2021-11-29 Thread 'Michael Day' via Programming

Devon's note reminds me to mention that I'm using the Avast Secure Browser
Mike

On 30/11/2021 00:11, 'Michael Day' via Programming wrote:

Thanks Eric.

I've noticed your msg,  just before bedtime,  so, briefly,  here's 
what happened when
I tried firing up tour>overview,  after running Package Manager from 
Jqt to install all

selected updates:

overview tour

*** event handler error
ev_overview_click 0
|assertion failure: spf
|   fexist r['must exist'
jdo   jev_jijx_ 0
jtype click
jmid  overview
jsid
jdata
jwid  jijx

Here's the JVERSION info:

Engine: j903/j64avx2/windows
Beta-v: commercial/2021-11-16T21:47:12
Library: 9.03.07
Qt IDE: 1.9.4/5.15.2(5.15.2)
Platform: Win 64
Installer: J903 install
InstallPath: c:/d/j903-beta
Contact: www.jsoftware.com

And so to bed,

Cheers,

Mike


On 29/11/2021 21:51, Eric Iverson wrote:

JHS update available.

jijx menu>tour>overview is a new lab that is an overview for new 
users that

covers basic mechanics of J programming with the JHS front end.

App facilities for apps without requiring any javascript programming 
have

been improved. See:
    rundemo_jhs_ 16
--
For information about J forums see http://www.jsoftware.com/forums.htm






--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
For information about J forums see http://www.jsoftware.com/forums.htm


  1   2   3   >