Re: [Jprogramming] and, or evaluation order

2017-11-06 Thread Moon S
It could be great to have and. and or. in if. and while. conditions, like if. a~:0 and. b wrote: > ...not forgetting that *. is least common multiple for integer arguments. > > eg > >12 *. 16 > 48 > > Mike > > Please reply to mike_liz@tiscali.co.uk. > Sent from my iPad > >> On 6 Nov 2017,

Re: [Jprogramming] Tacit definition involving adverb argument

2017-01-05 Thread Moon S
t; > Nevertheless, illogical as your way is, I would rather have it your way. I > have often wanted (v0`v1`v2)} y to mean > (v0 y) (v1 y)} (v2 y), and never wanted it to mean what it does. > > However, I don't think the improvement would justify the effort and the > inco

Re: [Jprogramming] Tacit definition involving adverb argument

2017-01-05 Thread Moon S
ote: > You are using the verb (monad }). You need (dyad }). > > Henry Rich > > > On 1/5/2017 8:16 PM, Moon S wrote: >> >> Hm, and v0`v1`v2 has some quirks... >> >> v0=:_1 1&*@{. NB. head item, multiplied by _1 1 >> v1=:_2&{.

Re: [Jprogramming] Tacit definition involving adverb argument

2017-01-05 Thread Moon S
ng wrote: > (+/)`%`# 1 : ' ''`f g h'' =. m label_. (f g h) f.' > +/ % # > > > > > - Original Message - > From: Moon S > To: programming > Sent: Thursday, January 5, 2017 7:26 PM > Subject: Re: [Jprogramming] Tacit definition

Re: [Jprogramming] Tacit definition involving adverb argument

2017-01-05 Thread Moon S
> > - Original Message - > From: Moon S > To: programming > Sent: Thursday, January 5, 2017 6:36 PM > Subject: [Jprogramming] Tacit definition involving adverb argument > > Is there a tacit definition of such a verb? Is there a way to pass a > value to the adverb?

[Jprogramming] Tacit definition involving adverb argument

2017-01-05 Thread Moon S
Is there a tacit definition of such a verb? Is there a way to pass a value to the adverb? f =: 3 : '0 (<:y)} 11 22 33' f 1 0 22 33 f 2 11 0 33 PS. Also, I couldn't suspect that besides a usual definition of dyad adverb such as 1 : ('';':';'...x...m...y...') NB. explicit defs inside the

Re: [Jprogramming] debug in JQt?

2017-01-02 Thread Moon S
> > In brief, load debug with: > > > >load 'debug' > > > > and press Ctrl-K to show the debugger. > > > > On Mon, Jan 2, 2017 at 2:11 PM, Moon S wrote: > > > > > 1) JQt (8.05, j64, windows, all latest) can't debug a progr

Re: [Jprogramming] debug in JQt?

2017-01-02 Thread Moon S
TurboPascal... 1983... no, we know better :) dbstop was the key. Thank you Chris! On Tue, Jan 3, 2017 at 1:07 AM, chris burke wrote: > See the lab: Help|Studio|Labs|Debug > > In brief, load debug with: > >load 'debug' > > and press Ctrl-K to show the deb

[Jprogramming] debug in JQt?

2017-01-02 Thread Moon S
1) JQt (8.05, j64, windows, all latest) can't debug a program. I mean, run it line by line, entering or stepping over functions. At least I couldn't find how to do it. Moreover, it can't run a program: file > open > latest ... someprogram.ijs --> new edit window with green background pops up, then

[Jprogramming] AoC 2016 day 10

2016-12-11 Thread Moon S
I won't lie, first I wrote that solution in Python. It's much easier and faster. Then the program was translated to J. The biggest problem was that J didn't have dictionaries. While even K has! And sparse arrays don't support strings or boxed values. Argh. And we are at the end of year 2016! Anyway

Re: [Jprogramming] [Jsoftware] AoC 2016 day 4

2016-12-05 Thread Moon S
t; # n&>) t will do. On Sun, Dec 4, 2016 at 9:26 PM, Henry Rich wrote: > (p#n)&> applies (p#n) to each atom of t. > > (p&> # n&>) applies # to the results of p&> and n&> on the entirety of t. > > Both forms are valid J, but they do different thin

Re: [Jprogramming] [Jsoftware] AoC 2016 day 4

2016-12-04 Thread Moon S
(p&> # n&>) t NB. is ok too. So... why (p#n)&>t is not? And how to deal with this kind of problems? On Sun, Dec 4, 2016 at 8:18 PM, Moon S wrote: > OK, simple case > >t NB. three boxed strings > > ┌──┬──┬──┐ > > │22│33│44│ > > └──┴──

Re: [Jprogramming] [Jsoftware] AoC 2016 day 4

2016-12-04 Thread Moon S
20 0 0 dissect doesn't show anything for p and n in the second case; and what's "3 1(1)" for '#'? http://mas.orgfree.com/adventofcode2016/diss1.png On Sun, Dec 4, 2016 at 6:14 PM, Henry Rich wrote: > I have no time to help, other than to suggest you use d

[Jprogramming] [Jsoftware] AoC 2016 day 4

2016-12-04 Thread Moon S
I have this code: t =: cutLF CR-.~fread '04.dat' a =: a.{~97+i.26NB. 'abc...z' c =: 5{.a\:[:+/"1 a=/[:/:~_10}.'-'-.~] NB. calculate checksum string v =: c -: _1}._6&{. NB. checksums match = good string n =: [:".3{._10{.] NB. extract

Re: [Jprogramming] Width of chart window (plot,pd)

2016-09-09 Thread Moon S
bug, the size of window is not > > > > QT_DEFSIZE but the minwh, and the plot window > > > > failed to resize. > > > > > > > > Пт, 09 сен 2016, Robert Herman написал(а): > > > > > Bill > > > > > > > >

Re: [Jprogramming] Width of chart window (plot,pd)

2016-09-09 Thread Moon S
As a workaround, this works: pd 'qtc c:\tmp\plot.png 1880 360' exit 0 It creates an image file with the graphics, shows it with the default image viewer, and exits jqt. On Fri, Sep 9, 2016 at 3:21 PM, Moon S wrote: > Yes it should have been something like pd 'qt 1880

Re: [Jprogramming] Width of chart window (plot,pd)

2016-09-09 Thread Moon S
window still defaults to 400 386. Where is the QT_DEFSIZE var defined, > or how can I change it in a program? > > Thanks. > > Rob > > > > On 9 September 2016 at 17:47, bill lam wrote: > > > It should in plot/commands > output commands. > > eg,

[Jprogramming] Width of chart window (plot,pd)

2016-09-09 Thread Moon S
In JQt (8.05 Win 64) I do something like this: require'plot' pd'reset' pd (i.1000);?1000#100 pd'show' I get the chart on my screen with the client area sized 480x360 pixels. I have read wiki pages on plot, pd options and commands, but I could not find a way to make it bigger, e.g. 1880x360. Ho

Re: [Jprogramming] Performance of fork vs train

2016-06-23 Thread Moon S
andle. And we are fast enough that we can > switch to arbitrary precision integer arithmetic and still be faster > than the brute force approach: > > (3) 6!:2 'F x:i.' > 0.042063 > > I hope this helps... > > Thanks, > > -- > Raul > > On Wed,

Re: [Jprogramming] Performance of fork vs train

2016-06-23 Thread Moon S
9)' > > 0.169901 > > 6!:2 '(+/@:(*:@>:@i.))"0 (i.)' > > 13.4185 > > 6!:2 '(+/@:(*:@:>:@i.))"0 (i.)' > > 0.156401 > > 6!:2 '(+/@:(*:@>:@:i.))"0 (i.)' > > 13.49 > > > Note that there

[Jprogramming] Performance of fork vs train

2016-06-22 Thread Moon S
I was searching integer solutions (k,m) for 1^2 + 2^2 + ... + k^2 = m^2 and I found that one expression runs much faster than the other: (#~(0=1|[:%:+/@:([:*:1+i.))"0) 2+i. 24 (#~(0=1|[:%:+/@:(*:&>:&i.))"0) 2+i. 24 The first one is ~100 times faster, and moreover, the expression

[Jprogramming] Fwd: 16bHHHHHHHH...HHx - no way

2016-06-17 Thread Moon S
It seems that there's no extended hexadecimal literals in J. The decimal ones work ok. Let's convert a long integer to its hex representation '0123456789abcdef'{~16#.^:_1 (1111111x) 53973c0482de06eddf68d4531e9062c7 16b53973c0482de06eddf68d4531e9062c7 N

[Jprogramming] Blonde Code Golf - January Challenge - Alphabet Swap

2016-01-22 Thread Moon S
Here's another code golf challenge I found: http://www.blonde.net/blog/2016/01/18/blonde-code-golf-january-16 In a string, swap a-z with z-a, A-Z with Z-A. Assume that you will always get a valid string and that spaces and special characters should remain unchanged. alphaSwap('abcxyz') // -> zyx

Re: [Jprogramming] advent of code, days 36bl 25

2015-12-25 Thread Moon S
I had nearly the same for the last day. Then remembered that J has modular exponentiation optimized. And I have 64-bit J, so no need for extended numbers. 3 timex '(33554393&|@*&252533)^:(2947(<.&-:@(*:@+-3&*@[+]))3029)20151125' 5.12972 3 timex '33554393|20151125*(33554393&|@^&(2947(<.&-:@(*

Re: [Jprogramming] Magic squares

2015-12-22 Thread Moon S
±1 or ±½ of course :) Sorry didn't read all, just saw that -n/2 ... 0 ... n/2. For odd n it's i:<.-:n i:<.-:5 _2 _1 0 1 2 On Tue, Dec 22, 2015 at 8:20 PM, Moon S wrote: > > NB. Creat a rotation vector from -n/2 ... 0 ... n/2 > > Try i: -: y > > On Tue

Re: [Jprogramming] Magic squares

2015-12-22 Thread Moon S
> NB. Creat a rotation vector from -n/2 ... 0 ... n/2 Try i: -: y On Tue, Dec 22, 2015 at 7:50 PM, Richard Donovan wrote: > Thanks Thomas, works very well! > > > From: tmcguir...@gmail.com > > Date: Tue, 22 Dec 2015 12:14:31 -0500 > > To: programm...@jsoftware.com > > Subject: Re: [Jprogramming

[Jprogramming] MD5 in J

2015-12-17 Thread Moon S
I found the reason why convert/misc/md5 didn't work on the 64-bit architecture. The failures came from the rot function -- it was ok for 32-bit ints, but wrong for 64-bit. This is what works ok: rot=: 16b and sh or ] sh~ 32 -~ [ NB. (y << x) | (y >> (32 - x)) I saved it in https://github.

Re: [Jprogramming] advent 16

2015-12-16 Thread Moon S
I changed those keys to numbers... and cheated a bit with < and > t=: ;: > cutLF (':,',CR)-.~ fread {:ARGV NB. |Sue|440|pomeranians|1|samoyeds|9|children|4| c=: ;: 'children cats samoyeds pomeranians akitas vizslas goldfish trees cars perfumes' NB. categories a=: ".@>@{: + (100 * c i. {.) NB. ana

Re: [Jprogramming] advent 13

2015-12-13 Thread Moon S
; happPair=: +&({&Tbl)&< |. NB. happPair 2 3 > happ=: +/@:(2 happPair\ (, {.)) NB. happ i.8 > smoutput happMax=: >./ happ"1 (i.@! A. i.) # Tbl > > NB. part 2 > Tbl=: Tbl {.~ >: 2##Tbl > happPair=: +&({&Tbl)&< |. > happ=: +/@:(2 happPair\ (, {.

Re: [Jprogramming] advent 13

2015-12-13 Thread Moon S
So far these were simple tasks with clear algorithms, so it's interesting to play with the programs -- keep everything in verbs and be as lazy as possible (i.e. build one final function, that just gives the solution of the task being given the data; especially funny if the functions are tacit), or

Re: [Jprogramming] advent of code day 12

2015-12-12 Thread Moon S
For part1 you don't need json actually ;) part1 =: 3 : 0 NB. replace all non-digits to spaces, replace '-' to '_', do +/". a=.'abcdefghijklmnopqrstuvwxyz"'',[]{}:',CRLF +/". ('-';'_')rplc~ ' '((i.#y)#~+./a=/y)}y ) On Sat, Dec 12, 2015 at 10:47 PM, Joe Bogner wrote: > somewhat tricky as I h

Re: [Jprogramming] adventofcode 11

2015-12-11 Thread Moon S
Such a pity J is not too popular on github. Anyway, here's my solution too. In general, I don't like to use tacit defs everywhere. Procedural logic is much more clear and easier to read and understand and not always slower. NB. next good password http://adventofcode.com/day/11 ilo =: (+./)@(8 11

Re: [Jprogramming] Fold/reduce with initial value?

2015-02-03 Thread Moon S
1|.o;/|.l is a bit slower than the for (1.5s). G.P. On Tue, Feb 3, 2015 at 7:41 PM, Moon S wrote: > I see. Thank you! > Still it's a pity there's no way to tell '/' an initial value without > boxing/unboxing. > > >(1) 6!:2 '>(v~&.>)

Re: [Jprogramming] Fold/reduce with initial value?

2015-02-03 Thread Moon S
'q=:q v y'' "0 l[q=:o' 0.0038912 On Tue, Feb 3, 2015 at 7:30 PM, 'Pascal Jasmin' via Programming < programm...@jsoftware.com> wrote: > (,: 'xx')4 : 'x,''_'',":y'~ reduce 1 2 3 4 > xx_4_3_2_1

Re: [Jprogramming] Fold/reduce with initial value?

2015-02-03 Thread Moon S
: ((&.>)/)(>@:) > > 100([:-~boxscan ,~)&(<"_1) i.5 > 90 > > > 100([:(- +/"1)~ boxscan ,~)&(<"_1) i.5 2 > 55 > > > then as an adverb, > > reduce =: 1 : '([: u boxscan ,~)&(<"_1)' > >

Re: [Jprogramming] Fold/reduce with initial value?

2015-02-03 Thread Moon S
0 > > +---+ > > |_45 _44 _43 _42 _41| > > +---+ > > > > > > R.E. Boss > > > > > > > -Original Message- > > > From: programming-boun...@forums.jsoftware.com > > [mailto:programming- > > >

[Jprogramming] Fold/reduce with initial value?

2015-02-03 Thread Moon S
I have a list (l), some object (o) and a verb (v) modifying the object: l = l_0 l_1 ... l_n o_new = o_old v l_i The list items and the object have different types. I want to apply all the list items to the object: o_new = (...((o_old v l_0) v l_1) ... v l_n) NB. the order of items doesn't ma