[Jprogramming] ReL Counting Rectangles

2014-10-07 Thread Linda Alvord
I tried this in simple J. It should work in elementary school (as long as it is correct) f=: 13 :'(>:i.x) */>:i.y' g=: 13 :'(i.x<.y)<:/i.x>.y' all=: 13 :'+/,((x<.y) g x>.y) * (x<. y) f x >.y' 2 f 3 1 2 3 2 4 6 3 f 2 1 2 2 4 3 6 3 f 3 1 2 3 2 4 6 3 6 9 2 g 3 1 1

Re: [Jprogramming] Project Euler 85, Python and J

2014-10-07 Thread Tikkanz
Here is another version of countRects countRects=: */@(2 ! >:) On Wed, Oct 8, 2014 at 9:07 AM, Tikkanz wrote: > Sorry, yes that is a leap. > (x * (x + 1)) * 0.5 is the number of ways to choose two horizontal lines > to make 2 sides of the rectangle. > (y * (y + 1)) * 0.5 is the number of ways to

Re: [Jprogramming] Project Euler 85, Python and J

2014-10-07 Thread Tikkanz
Sorry, yes that is a leap. (x * (x + 1)) * 0.5 is the number of ways to choose two horizontal lines to make 2 sides of the rectangle. (y * (y + 1)) * 0.5 is the number of ways to choose two vertical lines to make the other 2 sides of the rectangle ((x * (x + 1)) * 0.5) * ((y * (y + 1)) * 0.5) is th

Re: [Jprogramming] Project Euler 85, Python and J

2014-10-07 Thread Devon McCormick
I got this: countRects 77 36x 198 where I got the "77 36" from this: ({~ idxClosest@:(countRects"1)) getSizes >: i.200 77 36 On Tue, Oct 7, 2014 at 12:15 PM, 'Pascal Jasmin' via Programming < programm...@jsoftware.com> wrote: > countRects a cool solution that just works without my com

Re: [Jprogramming] Project Euler 85, Python and J

2014-10-07 Thread 'Pascal Jasmin' via Programming
countRects a cool solution that just works without my complete understanding of it either. I'm not convinced of the getSizes range being used though: this is pretty close to 2M 4 %~ */@(, >:) 3 816x 216 So I think a "triangulation" algorithm would be more general than the getSizes fil

Re: [Jprogramming] Project Euler 85, Python and J

2014-10-07 Thread Devon McCormick
To answer Jon's last question, if "nr" is my matrix of results from "countRects", then this gives me the index of the lowest (closest to 2e6) in the raveled matrix: (3 : '(] i. <./) ,y') 2e6(-|)nr 499 If we think of the indexes of a table as being a base ($table) number, we can decode the vecto

Re: [Jprogramming] Project Euler 85, Python and J

2014-10-07 Thread Devon McCormick
Hi - "countRects" seems like a bit of a leap. I think I understand "4 %~" because you're overcounting by 4 rotations, but I don't comprehend the magic behind "*/@(,>:)". I see that "(,>:)" concatenates the shape to its increment, e.g. 2 3 3 4 for the input 2 3, but what's the rationale behind th

Re: [Jprogramming] conversions (3!:4) between platforms/android

2014-10-07 Thread Don Guinn
I don't know if my phone is 32 or 64 bit. But J is 32 bit. On Oct 7, 2014 8:32 AM, "Don Guinn" wrote: > I took your numbers and did > >256#.0 0 1 72 224 139 75 119 > 1412516498295 > > on my laptop and phone and got the same answer. But it was an integer on > my laptop and floating on my phone

Re: [Jprogramming] conversions (3!:4) between platforms/android

2014-10-07 Thread Joe Bogner
Don - that works great. Thank you _8 (] (256 #. ]) (a. i. ]))\ bin or times=: _8 (256 #. a. i. ])\ bin On Tue, Oct 7, 2014 at 10:32 AM, Don Guinn wrote: > I took your numbers and did > >256#.0 0 1 72 224 139 75 119 > 1412516498295 > > on my laptop and phone and got the same answer.

Re: [Jprogramming] conversions (3!:4) between platforms/android

2014-10-07 Thread Don Guinn
I took your numbers and did 256#.0 0 1 72 224 139 75 119 1412516498295 on my laptop and phone and got the same answer. But it was an integer on my laptop and floating on my phone. Might have to flip things around if you have enian problems. On Tue, Oct 7, 2014 at 8:23 AM, Joe Bogner wrote:

Re: [Jprogramming] conversions (3!:4) between platforms/android

2014-10-07 Thread Joe Bogner
Thanks Don. It looks like a long on java is 64 bits, 8 bytes, even on a 32 bit architecture. I'm uncertain of the right path forward. I could change the java app to log a 4 byte timestamp, or I can figure out a way to convert the 8 byte to an integer on J32. The simplest change would be to have s

Re: [Jprogramming] conversions (3!:4) between platforms/android

2014-10-07 Thread Don Guinn
I checked IF64 on my phone and its value was zero. Help says that _3(3!:4) only is valid for J64 On Tue, Oct 7, 2014 at 6:00 AM, Joe Bogner wrote: > I have a android app that is logging sensor data to a text file using > java's DataInputStream.writeLong[1]. It is logging a timestamp each > time

[Jprogramming] conversions (3!:4) between platforms/android

2014-10-07 Thread Joe Bogner
I have a android app that is logging sensor data to a text file using java's DataInputStream.writeLong[1]. It is logging a timestamp each time it gets a step (pedometer). The timestamp comes from getTime() [2] I can read the file on Windows bin=:fread 'c:/joe/j/steps.txt' times=: |. _3 (3!:4) |.

Re: [Jprogramming] Project Euler 85, Python and J

2014-10-07 Thread Tikkanz
Note that 200 x 200 is a bit of an overkill given 3x2 = 2x3 The following choses the lower triangular of a matrix of the different sized rectangles to investigate. getSizes=: ,@(>:/~) # [: ,/ ,"0/~ getSizes >: i. 5 Given the sides of a rectangle you can count the number of rectangles as follows: c