Re: [Jprogramming] My first J conjuction

2015-12-03 Thread Kip Murray
And you can use a fork in the definition of a conjunction: of =: 2 : 'v@[ u v@]' 4 + of *: 5 41 On Thursday, December 3, 2015, Kip Murray wrote: > A fork is not a conjunction but it shows what you are doing: > > > 4 (*:@[ + *:@]) 5 > 41 > > > On Thursday, December 3, 2015, Lippu E

Re: [Jprogramming] My first J conjuction

2015-12-03 Thread Kip Murray
A fork is not a conjunction but it shows what you are doing: 4 (*:@[ + *:@]) 5 41 On Thursday, December 3, 2015, Lippu Esa wrote: > It is 5:17 AM in Finland and I already have two good answers. Thank you > David and Pascal! > > It seems that I haven't been using Compose either :) . But a

Re: [Jprogramming] Problem writing files

2015-12-03 Thread bill lam
I think this is a bug, it should raise a domain error if the left argument is not literal, just as the same as (i.10) 1!:2 <'testfile' |domain error | (i.10)1!:2<'testfile' 1!:2&2 is special, otherwise smoutput can not work. Just as others had suggested, it is easy to stringify your dat

Re: [Jprogramming] My first J conjuction

2015-12-03 Thread Lippu Esa
It is 5:17 AM in Finland and I already have two good answers. Thank you David and Pascal! It seems that I haven't been using Compose either :) . But at least I knew that this is the place to be. Thanks again, Esa -Original Message- From: programming-boun...@forums.jsoftware.com [mai

Re: [Jprogramming] My first J conjuction

2015-12-03 Thread 'Pascal Jasmin' via Programming
dyadic & does this already 4 +&*: 5 41 - Original Message - From: Lippu Esa To: "programm...@jsoftware.com" Sent: Thursday, December 3, 2015 10:05 PM Subject: [Jprogramming] My first J conjuction Hello everybody, I realized with some shame that I haven't written a single J conjun

Re: [Jprogramming] My first J conjuction

2015-12-03 Thread David Lambert
I expect you'll get many of the same response. Your conjunction is fine, however this particular case is so frequent there's a built in conjunction. Read "but first", x f&g y or x f&:g y the difference being rank. Add but first square: 4 +&: *: 5 41 On 12/03/2015 10:05 PM, pr

[Jprogramming] My first J conjuction

2015-12-03 Thread Lippu Esa
Hello everybody, I realized with some shame that I haven't written a single J conjunction - ever. Some adverbs, yes, but they too are newish. I have a recurring need for sentences like (f x) g f y where verb f is applied to nouns x and y and dyadic verb g is then applied to the two results. an

Re: [Jprogramming] Problem writing files

2015-12-03 Thread 'Pascal Jasmin' via Programming
(3!:1) anynoun is stringified data. anynoun -: 3!:2 (3!:1) anynoun NB. 3!:2 gets your data back. > So is there a simple way to stringify my data tables so they can be streamed > to file easily? From: Alex Giannakopoulos To: programm...@jsoftware.com Sen

Re: [Jprogramming] Problem writing files

2015-12-03 Thread Joe Bogner
On Dec 3, 2015 4:25 PM, "Alex Giannakopoulos" wrote: > > Ah, OK, Joe, I think I see what the problem is. > If I simply write a quoted string to the file it works fine. E.g. > > 1!:21 <'testfile' > > 30029424 > >'hello' 1!:2 (30029424) > However I was trying to dump non-string variables, viz. t

Re: [Jprogramming] advent of code - day 3

2015-12-03 Thread Ryan Eckbo
I like these answers using complex numbers, nicely done. On 4 Dec 2015, at 8:16, Jan-Pieter Jacobs wrote: This is mine (honestly without cheating ;) ). The notation of the complex directions can be very nicely written as subsequent powers of 0j1 : 0j1^i.4 NB. 3) Number of houses getting at lea

Re: [Jprogramming] Problem writing files

2015-12-03 Thread Alex Giannakopoulos
Ah, OK, Joe, I think I see what the problem is. If I simply write a quoted string to the file it works fine. E.g. 1!:21 <'testfile' 30029424 'hello' 1!:2 (30029424) However I was trying to dump non-string variables, viz. tables, which is what it didn't like. E.g. f1 =.1!:21 <'testfile

Re: [Jprogramming] advent of code - day 3

2015-12-03 Thread Jan-Pieter Jacobs
This is mine (honestly without cheating ;) ). The notation of the complex directions can be very nicely written as subsequent powers of 0j1 : 0j1^i.4 NB. 3) Number of houses getting at least one gift! NB. use complex numbers for directions NB. Every unique number is at least once on the list...

Re: [Jprogramming] Problem writing files

2015-12-03 Thread Joe Bogner
Alex, can you post some code that demonstrates the problem? On Thu, Dec 3, 2015 at 3:41 PM, Alex Giannakopoulos wrote: > I am using J 8.02 under 64-bit Linux (Mint) > Whenever I try to write a file, even just a simple line or two of text, I > get a file full of illegible binary. > This happens re

Re: [Jprogramming] advent of code - day 2

2015-12-03 Thread Jan-Pieter Jacobs
My solutions to the Day2 problems: Probably there's better solutions around, but well... NB. the surface of a box is the product of 2 elements of each permutation of sides NB. Needed paper surface s1a =: [: +/ (+/ + s1slack)@s1facesurf@s1parse NB. paper needed = sum of surfaces + slack s1

[Jprogramming] Problem writing files

2015-12-03 Thread Alex Giannakopoulos
I am using J 8.02 under 64-bit Linux (Mint) Whenever I try to write a file, even just a simple line or two of text, I get a file full of illegible binary. This happens regardless of whether I use the 'jfile' system, or the foreigns 1 !: 21 etc Are there any known problems in this area, or am

Re: [Jprogramming] sorting a table by nth column

2015-12-03 Thread Roger Hui
There is an interesting story about the design of the /: primitive: http://keiapl.org/anec/#sort On Thu, Dec 3, 2015 at 12:27 PM, Alex Giannakopoulos < alexg...@blueyonder.co.uk> wrote: > Thanks, that's brilliant. > Funnily enough, I'd read the relevant page on /: and had tried > something ver

Re: [Jprogramming] sorting a table by nth column

2015-12-03 Thread Alex Giannakopoulos
Thanks, that's brilliant. Funnily enough, I'd read the relevant page on /: and had tried something very similar, but for some reason, it didn't work. Can't remember exactly what. Anyway it's good to see that I wasn't too many miles off the track, appreciated! (Works identically with boxed t

Re: [Jprogramming] advent of code - day 3

2015-12-03 Thread Alex Shroyer
Heh, I value sleep more than getting my name on the leaderboard... plus I was stumped until I read Reddit user Godspiral's solution . I did enjoy how part 2 can be solved with just 3 more strategically-placed character

Re: [Jprogramming] advent of code - day 3

2015-12-03 Thread 'Pascal Jasmin' via Programming
Winner solution, (but you didn't submit it at 12:18 :P) using complex encoding for pairs should probably always be done? It makes your part 2 especially elegant. - Original Message - From: Alex Shroyer To: programm...@jsoftware.com Sent: Thursday, December 3, 2015 11:25 AM Subject:

Re: [Jprogramming] advent of code - day 2

2015-12-03 Thread Thomas Costigliola
Here's my solution to part 1. I=. /:~@:(do;._1)@:('x'&,);._2 ] 0 : 0 3x11x24 13x5x19 1x9x27 24x8x21 6x8x17 ... ) M=. 7 3 $ 1 1 0 1 0 1 0 1 1 I +/@(+/@:(*/) . ^) |:M 1588178 On Thu, Dec 3, 2015 at 6:47 AM, Ryan Eckbo wrote: > And mine: > > # part 1 > Presents=. do each ('x'&cut);._

Re: [Jprogramming] advent of code - day 3

2015-12-03 Thread Alex Shroyer
I was stuck at '^v<>'i.s , but came up with these after I peeked at someone else's solution: part1=:#~.,+/\0,0j1 0j_1 _1 1{~'^v<>'i.s part2=:#~.,+/\0,0j1 0j_1 _1 1{~'^v<>'i._2]\s On Thu, Dec 3, 2015 at 8:59 AM, Joe Bogner wrote: > Mine: > > data=:fread 'advent2015/day3.txt' > getMoves=: ((0,1)

Re: [Jprogramming] dyadic J

2015-12-03 Thread Jose Mario Quintana
Pascal wrote: "There is a addon called general/primitives that provides shadow names for everything." However, trying to provide a shadow name for $: is futile. Pascal wrote: 'A recent point of conversion of mine is that u@:v is both easier to read and edit/expand and easier to see subresults

Re: [Jprogramming] sorting a table by nth column

2015-12-03 Thread Kip Murray
C 3 2 1 7 4 1 1 8 5 2 9 8 C /: 1 { |: C 4 1 3 2 5 2 1 7 1 8 9 8 On Thursday, December 3, 2015, Roger Hui wrote: >] x=: ? 10 4 $ 100 > 33 44 35 49 > 67 95 56 50 > 35 70 83 6 > 26 73 97 11 > 29 92 71 94 > 81 13 93 64 > 47 51 35 98 > 33 59 52 90 > 62 0 64 29 > 14 30 92 98

Re: [Jprogramming] sorting a table by nth column

2015-12-03 Thread Roger Hui
] x=: ? 10 4 $ 100 33 44 35 49 67 95 56 50 35 70 83 6 26 73 97 11 29 92 71 94 81 13 93 64 47 51 35 98 33 59 52 90 62 0 64 29 14 30 92 98 x /: 1{"1 x 62 0 64 29 81 13 93 64 14 30 92 98 33 44 35 49 47 51 35 98 33 59 52 90 35 70 83 6 26 73 97 11 29 92 71 94 67 95 56 50 On Thu, Dec 3, 201

[Jprogramming] sorting a table by nth column

2015-12-03 Thread Alex Giannakopoulos
Even though I've been using J lightly for a quite while, I have not so far had cause to use boxing, especially boxed tables. Great feature, if you need it, but I'm struggling a bit to get up to speed. Say I have a two column table such as would be generated by ([;somefunction)"0 i.100 How wo

Re: [Jprogramming] printing the complete content of a, J object (no ...) ?

2015-12-03 Thread David Lambert
I convert the object to a literal vector that looks the same as j would display it, write it to a file, and examine in an editor. (emacs) The to_literal verb is supposed to create a literal of any noun suitable for writing to a file. Until=: 2 :'u^:(0-:v)^:_' rank=: #@:$ to_literal=: ([:,/,.&

[Jprogramming] adventofcode day 3

2015-12-03 Thread David Lambert
Say P is a rank 2 list of 2D coordinates 4{.P 0 0 0 1 0 2 _1 2 Let's map the flight. NB. shift moves origin making minimum coordinates independently 0 NB. use: shift COORDINATES shift=: -"1 <./ NB. grid generates an array of zeros large enough for only the positive coords NB. use: grid

Re: [Jprogramming] Jconsole : printing the complete content of a J object (no ...) ?

2015-12-03 Thread bill lam
Right, 9!:36/37 is needed but not sufficient for Jconsole, since it also depends on the scrolling capability of the terminal emulator. Чт, 03 дек 2015, Dan Bron написал(а): > akakim...@gmail.com wrote: > > Is there a way to ask Jconsole to print the complete content of a J object ? > > You can se

Re: [Jprogramming] advent of code - day 3

2015-12-03 Thread Joe Bogner
Mine: data=:fread 'advent2015/day3.txt' getMoves=: ((0,1),(0,_1),(1,0),:(_1,0)) {~ ('^v><' i. ]) addStart =: (1 2 $ 0) , ] smoutput answer1 =: # ~. +/\ addStart @: getMoves data smoutput answer2 =: # ~. _2[\ ; +/\"2 (((0,1) $~ #) addStart@,./. getMoves) data On Thu, Dec 3, 2015 at 7:00 AM,

Re: [Jprogramming] Jconsole : printing the complete content of a J object (no ...) ?

2015-12-03 Thread Dan Bron
akakim...@gmail.com wrote: > Is there a way to ask Jconsole to print the complete content of a J object ? You can set the output control parameters using 9!:37 [1]. For example, on my system: 9!:36 ‘' 0 256 0 222 J will truncate the display of any object wider than 256 chars or taller than

[Jprogramming] Jconsole : printing the complete content of a J object (no ...) ?

2015-12-03 Thread akakim...@gmail.com
Hi, Is there a way to ask Jconsole to print the complete content of a J object ? I find generally usefull the idea to trunc the content and then print ... But, i would like to be able to print it all (no truncation), even if the output is large. Thanks --

[Jprogramming] advent of code - day 3

2015-12-03 Thread Ryan Eckbo
Data=. }: freads'/tmp/input.txt' houses=: 3 : '+/\ (0 0), (4 2$0 1 1 0 0 _1 _1 0){~ ''^>v<'' i. y' # part 1 {. $ ~. houses Data # part 2 santa=. 2 | i. # Data robo=. -. santa {. $ ~. (santa&# ,&shouses robo&#) Data -- For in

Re: [Jprogramming] advent of code - day 2

2015-12-03 Thread Ryan Eckbo
And mine: # part 1 Presents=. do each ('x'&cut);._2 freads'/tmp/input.txt' sa=: 3 : '(l*w) + (2*l*w) + (2*w*h) + 2*h*l [ ''l w h''=. /:~y' +/ sa"1 Presents # part 2 ribbon=. +/@:+:@:}:@:(/:~)@:> vol=. */@:> +/ (vol + ribbon)"1 Presents Ryan On 3 Dec 2015, at 13:54, Ric Sherlock wrote: > Here'