last day (94 days later) » 

7:29 PM
Ninja'd you to another Julia answer.
I'm starting to like the language.
 
I'm glad you like it! But also ;-;
 
To be fair, you had four days.
 
Haha :P
Which challenge?
 
GoL
 
I wasn't going to participate in that one anyway; I don't really understand GoL.
 
7:33 PM
Neither did I. This is the first time I did something GoLly.
 
That answer is awesome btw
 
:)
 
Why do you do arrays using the row array syntax? (i.e. [x y] rather than [x,y])
I think the object constructed using a comma is more efficient
If I'm not mistaken, [x y] actually constructs a 2-dimensional array (Array{T,2} where T = eltype(array)) whereas [x,y] constructs a 1-dimensional array.
^ this is true
 
I didn't even know there was a difference...
Um, I restarted the REPL and my answer doesn't work anymore. How is that possible?
Ah, crap. generic function with 3 methods means I overloaded f, right?
Needed more .... Now I understand why you cannot redefine generic functions as anonymous functions and vice versa.
@AlexA. Switched to comma. I still need spaces in 2D arrays though, right?
 
7:57 PM
@Dennis That depends. It'll tell you that you have more methods if you have multiple function arguments
@Dennis You may have had things defined that it was reading that it shouldn't have been
In a fresh REPL it says that f has one method
 
No, it was the overloaded f. I got away without the ... since it actually called previous definition when recursing.
 
Btw it works for me in a fresh REPL. The last test case is pretty slow though.
 
Yeah, I posted a fix 11 minutes ago. The previous version shouldn't work.
 
o
@Dennis Forgot to respond to this. Yes.
 
Does Julia automatically memoize function calls?
 
8:07 PM
I think so.
wafflemao
 
Try executing the large test case twice.
 
Oh damn. Instantaneous
 
Yup.
This is also very fast:
h(x)=(r=[];while x∉r push!(r,x);x=sum(j->circshift(x,[j÷3,j%3]-1),0:8)-x|x.==3end;(r[k=end]==x)k-1)
@AlexA. hahahaha
 
@Dennis r=[r;x] is shorter than push!
You also have a space after the comma
 
That gives a DimensionMismatch.
 
8:10 PM
Oh
Ohhh I see why
Yeah
Is divrem(j,3) shorter than [j÷3,j%3]?
Nope
Even though ÷ is 2 bytes
 
@AlexA. I don't. :P The whole array notation business is pretty obscure to me.
divrem wouldn't work anyway, since it returns a Tuple and I can't subtract 1.
 
oh right
You'd need [divrem(j,3)...] which is absurd
@Dennis What's the type of x as you're doing this?
It's a multidimensional array, right?
r=[] initializes r as Array{Any,1}
So trying to vcat a multidimensional array onto it is no bueno, but you can push! an array into it because its eltype is Any
@Dennis Since this isn't recursive you don't need to name it, which saves a byte or two.
two
Also, nice trick when golfing in Julia: You can score your submission by wrapping it in sizeof("")
You just need to escape quotes and $
 
Still way longer than the recursive solution though...
But the speed difference is impressive.
 
8:33 PM
Which is faster?
 
The iterative solution finishes instantly.
 
By iterative do you mean recursive?
 
No, the while loop.
 
Oh
I realized I misspoke in my explanation of why r=[r;x] doesn't work. It's been elevened corrected. Does it make sense?
The syntax [array; array] is actually doing vcat(array, array)
 
Sort of. I'm still fuzzy on the differences between spaces, commas and teary eyes...
 
8:36 PM
haha
 
And severely annoyed by the fact that [x] doesn't wrap x in an array.
 
It doesn't? Huh. I guess I've never tried that.
 
If x is an array [x]==x give a deprecation warning and true.
 
huh
> oldstyle_vcat_warning
Right
You used to be able to do [x,y] where x and y are arrays
That used to be vcat but now it's [x;y]
It's one of those readability things
I don't know what it thinks you're trying to vcat with [x] though
And the recommendation of collect is equally mysterious
 
The weird thing is that it works if you prefix Any. All this array type business is very confusing.
 
8:44 PM
Yeah, because if it's Any then you're just listing elements in an array literal rather than vcating
 
Should we create a Julia room? We discuss things rather frequently, and it's not always a fit for CGC.
 
I wonder if there's a Julia room in Chat.SO
brb looking
There is not
Oh but we talk about golfing so it would make sense for PPCG to be its parent
Okay I'll make room

 Julia

Discussion about the Julia language and golfing in it — julial...
 
\o/
 
Julia is objectively the best language ever to exist.
3
 
It is realle great and does all things.
Should we migrate this conversation so we can continue it there?
 
8:52 PM
waffles are nice
 
Disappointingly, this is longer than what I had before:
f(x,r...)=x∈r?(r[k=end]==x)k-1:f((g=x->sum(i->circshift(x',i),-1:1))(g(x))-x|x.==3,r...,x)
 
@Dennis That's some mysterious code you have there
 
g(x)=sum(i->circshift(x',i),-1:1)
f(x,r...)=x∈r?(r[k=end]==x)k-1:f(g(g(x))-x|x.==3,r...,x)
That's better.
 
Would it be shorter to define g as a function argument?
Actually I think it'd be the same
 
9:00 PM
Too bad there's no Cartesian product. 2D ranges would also help.
 
Yeah. :/ Something like R's expand.grid would be nice.
Oh
[(i,j)for i=1:n,j=1:m] would do it
julia> [(i,j)for i=1:4,j=1:5]
4x5 Array{Tuple{Int64,Int64},2}:
 (1,1)  (1,2)  (1,3)  (1,4)  (1,5)
 (2,1)  (2,2)  (2,3)  (2,4)  (2,5)
 (3,1)  (3,2)  (3,3)  (3,4)  (3,5)
 (4,1)  (4,2)  (4,3)  (4,4)  (4,5)
 
That's a lot longer than the div-rem approach though.
 
Yes
Damn I love the , syntax for nested for loops
 
Wait, so if x is 2D, x[1] gets the first entry rather than the first row?
 
Yes
x[1,:] gets the first row
 
9:12 PM
Ah, OK. There goes my idea f shifting the arrays by hand.
 
haha
Since arrays are stored in column-major order, x[2] is the same as x[2,1]
 
6/10 very confusing
 
Is it?
I almost sort of which x[2] didn't work since it is kind of weird, but ¯\_(ツ)_/¯
 
g(x,c=circshift)=c(x,1)+c(x,-1)+x is even worse...
 
What do you mean worse? Longer?
 
9:17 PM
Yes, since I'll have to transpose outside g.
Looks like I'm staying at 88 bytes.
 
88 bytes is pretty good!
Hell of a lot better than I could have come up with
 
85 was better. :P
 
It also didn't work though, right?
 
._.
 
¯\_(:P)_/¯
One of these days I'll get back to working on [REDACTED] as well as the three other Julia packages I have in the works.
 
9:37 PM
[REDACTED] sound really interesting. Any ETA on a first glimpse?
 
Haha. Probably not for a while, unfortunately.
I should probably take a step back and think about the design
 
10:26 PM
@Dennis Do you have any suggestions for this?
 
11:18 PM
@AlexA. Haven't been able to test it yet, but matchall(r"[\w-]+",s) sounds promising.
 
11:30 PM
@Dennis Very nice! Down to 105. :)
Thanks!
 
@AlexA. r"-?\w+" saves another byte.
 
I don't understand what -? is doing
OH
For negative numbers
duh
 
Also, you can use literal linefeeds. No need for \n.
 
Oh yeah
 
And c[] is the same as c[1].
 
11:44 PM
Wait, seriously?
 
Uh huh.
 
Good god why would they do that
 
¯\_(ツ)_/¯
 
I'm almost tempted to report that as a bug on GitHub
IMO it should be a syntax error
 
Make Julia verbose again!
 
11:47 PM
Haha
I mean objectively from a language design point of view, that makes no sense
 
I'd rather have them alias c[] to c[end]. :P
 

  last day (94 days later) »