3:57 AM
How do I turn a nested array into multi-dimensional one?

Oh my god so much lol
(note that when I say "lol" it means I'm literally laughing out loud)
This is incredible
@Dennis That's actually a really good question to which I do not have an immediate answer.
Okay
So

`hcat(A...)` seems to do the trick.

Oh really?
damn
That's way easier than what I just came up with

Potentially follwed by `'`, which is what I was going for.

I was going to do a `reshape reduce vcat`
Yours is 800% golfier
Probably a hell of a lot more efficient too
WTF WHY HAVE I BEEN DOING `reduce vcat` WHEN `vcat...` WORKS?!

4:13 AM
¯\_(ツ)_/¯

My life is a lie
@Dennis Good use case: `sum(isodd,x)` is shorter than `sum(i->i%2>0,x)`

`sum(x%2)`

Okay so my example isn't perfect
I actually didn't realize that `%` applied elementwise

It does. `sum(x&1)` would also work.

Oh nice!
Well, if I were writing production code, I would get the number of odd elements in an array using something like `count(isodd, x)` because it should be both readable and reasonably efficient.
So that's a good practical use case for `iseven`/`isodd`

4:23 AM
I guess...
I've tried overloading the `-` operator, but it doesn't seem to do anything.

??
What do you mean it doesn't do anything?

Oh, I need to specify the types... Bah.

Oh, yes.
`-(a::Type1, b::Type2) = some cool stuff`

Hm, that didn't work like I wanted it to...
```julia> -(x::Int,y::Int)=x+y
- (generic function with 204 methods)

julia> diff([1, 2, 3])
ERROR: BoundsError: attempt to access 3-element Array{Int64,1}:

in diff at linalg/generic.jl:47SYSTEM: show(lasterr) caused an error```

Good god why would you redefine subtracting integers as addition?!

4:29 AM
To abuse `diff` to do things pairwise.

Then you should overload `diff`, not `-`...

More bytes.

Overloading a function in a code golf submission is going to be pretty long regardless because you have to specify the types
If the type has a long name you can do `-{T<:YourLongTypeName}(a::T,b::T)` which is a tad shorter
Have you looked at the source for `diff`?
Looks like that's what's getting called
Since `diff` is literally just `[a[i+1]-a[i]for i=1:endof(a)-1]`, it's probably shorter to just reimplement it entirely to do what you want than trying to overload things.

Probably...

Are you still trying to do the `Char` substraction business?

4:39 AM
No, not anymore.

Oh, okay

4:59 AM
@AlexA. It worked. \o/
0

Julia, 99 bytes g=t->2t+[t[2:end,:];0t[1,:]] x->("Hard","Equal","Soft")[cmp(sum(g(g(x.>' ')')[:]∩(4,7)-5.5),0)+2] The anonymous function expects a two-dimensional Char array as argument. Verification julia> g=t->2t+[t[2:end,:];0t[1,:]] (anonymous function) julia> f=x->("Hard","Equal","Soft"...

+1
I was going to suggest `g(t)=` instead of `g=t->` but I guess it's the same length
`g(t)=` will be faster though

I'd rather define `g` inside `f` (seems cleaner), but horizontal scrolling.

Haha yeah

Oh, how come?

Lambdas are currently slow compared to "regular" functions
I guess there's a package called FastAnonymous that has an `@anon` macro that makes lambdas as fast as if the function were inlined and I think they're incorporating some of the speedups into `Base` eventually

5:05 AM
Considering how often lambda are used in `sum` and such, that sounds like a good idea.

Yep

Wait, Julia has `sign`, right?

Yes

o/

Hey!

5:06 AM
Hi!

Alex would cringe, but I wonder about `"ESHqoaufratdl"[...:3:]`

And cringed I have
How does that even what

Only problem, of course, is that `Equal` is the first one :/

The shortest I found was `x->"ESHqoaufratdl"[(sign(sum(g(g(x.>' ')')∩(4,7)-5.5))+3)%3+1:3:end]`, which is longer...

Ohhhhhhhhh I thought `...` was supposed to be a splat

5:18 AM
`s/end/13`

That's why I was confused

I meant to leave out the `end` or `13`, hence the cringe :P
Hmm I should use something else instead of `...` for Julia I guess

That works?

`<blah>` maybe
Deprecated
Hence cringe

Doesn't work at all for me
> `ERROR: syntax: missing last argument in "1:3:" range expression`

5:19 AM
It's a syntax error in 0.4.5...

0.3.11, that's probably why

ninja'd
I should get my hands on an older version.

Hmm I thought I had 0.4, nvm

You should definitely move up to 0.4
Granted, a lot of things that work fine in 0.3 are deprecated in 0.4, such as `int` as a synonym for `parse(Int,)`
And with any luck those will be dead and buried in 0.5
yesterday, by Alex A.
ಠ_ಠ

So I think I just had multiple Julias but PATH was set to 0.3.11
Anyway...

5:27 AM
`rm -rf <path/to/julia-0.3.11>`
Out with the old
>:D

Nah, will keep for testing purposes, will just change PATH

One of the fun things about answering some Julia questions on SO is that the issue would be that they were using a dev version and the issue went away when they used a stable release. :P

Fun game idea: Let's golf Alex's Julia submissions!

Haha
Surely most if not all are suboptimal

I'll start by searching for `parse(Int,...)` and replacing it with `int(...)`.

5:35 AM
10 mins ago, by Alex A.
yesterday, by Alex A.
ಠ_ಠ
Whenever I golf in Julia I just think of all deprecated features as already removed.

All is fair in love and code golf.
2

I found an old answer of mine that uses `int` and I almost want to change it to use `parse` just to see your reaction.

/me deletes as not a serious contender

eleven

Actually that's probably not even necessary, is it
... why did you store `x` again?
`readline()>"0"?while 2>1 print(1)end:print(0)`

5:56 AM
@Sp3000 I was young and naïve
I just golfed this one

Technically, `T(x)=(print(x);x>"0"&&T(x));T(readline())` would work as well.

Does `(a=~a)` need parens?
@Dennis Hah, I was wondering about that :P nice

@Sp3000 I think so but I'll check

I think you can drop about 4 pairs of parens from that

o_O
@Sp3000 Thanks! :D

6:03 AM
Why not Dennis'? :P

Oh I didn't see it
@Dennis This is nuts

Conclusion: Alex was indeed very young and naive

The ones are on newlines and it causes a stack overflow, and instead of 0 it prints false.
Nvm
It prints 0 forever too

You need to pipe in just `"0"`, no trailing newline

Oh

6:08 AM
If that bothers you, you can do `x<"1"||T(x)`

`x<"1"` should work with and without newline.
ninja'd

> when the input is 1, it must continually print 1s and only stop if the program is killed or runs out of memory
Would a stack overflow constitute running out of memory?

Hmm... good point

Not sure.
`x=int(readline());while print(x)!=1÷x end` is almost as short as the infinite recursion.

> `int`
:P

6:16 AM
Fine.
`x=readline();while print(x)!=1÷(x>"0")end`

XD did you have a backup solution in case I refused to use `int`?

Was already working on it. :P

That prints infinite zeros

No LFs plz.

orite
am stoop
Still does it

6:18 AM
How are you calling it?

`echo "0" | julia untitled.jl`

You need `echo -n`.

What does that do?

`echo` still appends a LF by default.

Oh, I didn't realize that. I guess that makes sense.

6:20 AM
`printf 0` is more portable.

I get a division error for 0

That's the point :P

I didn't actually read the code before running it >_>

Try this: `rm -rf ...`

Thank you for not sending me malware ಠ_ಠ

6:21 AM
ninja'd?

Too bad you can't char mod 2

You mean use `%` with a `Char` argument?
Like `'a'%2`?

Oh, but `%` works instead of `÷`.

I was hoping `'0'%2\1` yeah
Oh wait, float div, nvm
Silly Inf

:P
@Sp3000 You were absolutely right. Thanks!
Maybe it was an older version where you needed parens in ternaries? Idk. For some reason I thought they were required.
Maybe they never were and I just always sucked ;-;

6:30 AM
Go golf all your past ternaries :D (dunno if you have any)

Woo, just got a vote on Truth Machine and now I'm at exactly 19k rep. The consecutive zeros are so satisfying. :D
@Sp3000 To be clear, I thought that assignments inside of ternaries needed parentheses. That is apparently not the case or is no longer the case. ¯\_(TIL)_/¯
But I'm looking for them anyway to see if I have more stuff like that sitting around

How about `p->(a=0x0;[a=c==33?~a:c==60?a<<1:c==62?a>>1:c==64?a<<4|a>>4:a for c=p];Int(a))`?

O_O
That's beautiful

Also, `Int(a)` -> `1a`.

Thank you both so much for all of your golfing help tonight!! I love having Julia buds (who incidentally are both way better at golfing in Julia than I am >_>).
@Dennis Whoa, I wouldn't have thought to do that

6:46 AM
One final touch: `c==64?a<<4|a>>4:a for c=p` -> `c!=64?a:a<<4|a>>4for c=p`

Ah, it eliminates the space!
Good thinking!

@AlexA. That was an accident. I tried to shorten `a<<1` to `2a`.

¯\_(works)_/¯
Beautiful. Together we've gone from 117 down to 73. :) Granted, it was basically entirely you guys...
So I guess, together you've gone from 117 to 73. :P
I should have gone to bed about an hour or more ago but I got too caught up in the thrill of the golf.
Thanks again @Dennis and @Sp3000! <3 u both

`p->(a=0x0;[a=[a,~a,a<<1,a>>1,a<<4|a>>4][1+findlast("!<>@",c)]for c=p];1a)` is just as long.
`findlast` and 1-based indexing make this a lot less golfy than it would be...
`p->(a=0x0;[a=[~a,a<<1,a>>1,a<<4|a>>4,a][findin("!<>@\$c",c)][]for c=p];1a)` and `p->(a=0x0;[a=[[~a,a<<1,a>>1,a<<4|a>>4][findin("!<>@",c)];a][]for c=p];1a)` are also just as long...

4 hours later…
11:05 AM
Still a bit suspicious about the need for regex in subsequence, but the fact that `"a"[:2]` doesn't work hurts
Or `"a"[1:1:2]` or whatever it is that's equivalent to `"a"[:1]` in Python

11:41 AM
Re parens for assignment: I think parens are just necessary if you have multiple statements, by the looks of it

12:11 PM

4 hours later…
3:41 PM
@Sp3000 I think `f(s,a,b,i=0)=(o=join(["\$a "[i+1]!=c?c:b[i+=1]for c=s]);i<endof(a)?s:o)` works.

I really should get used to the idea I'm not using Python and `b[i+=1]` works :P
(was trying to `++` before for some reason)
What's `endof` though?

`length` minus 1 byte.

Ah.
Hmm getting rid of `o` is one byte longer because of 1-indexing :/

Yes, I've tried that as well.
1-based indexing is painful if it isn't modular...

4:22 PM
Posted, thanks :) will see if it can be golfed later, but looks hard

2 hours later…
6:50 PM
@Sp3000 Martin has clarified that we can take character arrays, so you should be able to get rid of the `join`.

7:46 PM
@Dennis at least Julia has `mod1`, but that's probably too expensive for most golfing applications where a ring buffer isn't completely necessary.

It does? o_O

it does
and might get 3-parameter `mod` with offset, which I posted as a feature request at some point

8:02 PM
Nice.

1 hour later…
9:09 PM
Argh, why doesn't Julia do some error checking before evaluating `s[j]=r`?

9:21 PM
I thought no error checking was usually a good thing for golf :P

before evaluating. If `j` contains a zero, it will start modifying `s`, then fail when it encounters the zero.

Oh.

For whatever reason, it works like I want it to if `j` is a row vector...

so it goes through j element by element and only crashes when it hits the 0? I don't see why that would be an issue unless you want to catch it and keep the unmodified s
fair warning I have no idea what challenge this is for

That's precisely what I'm doing.
0

Julia, 62 59 bytes f(s,p,r)=(i=0;try s[[i=findnext(s,c,i+1)for c=p]']=r end;s) I/O is in form of character arrays. Verification julia> f(s,p,r)=(i=0;try s[[i=findnext(s,c,i+1)for c=p]']=r end;s) f (generic function with 1 method) julia> F(s,p,r)=join(f([s...],[p...],[r...])) # string/char a...

9:34 PM
OK so why not just copy s first?
That doesn't seem like too many extra bytes

`S=s[:]` is a lot of bytes...
Anyway, transposing the column vector to yield a row vector fixed the problem.

Weird.

Yup.
That challenge has three Julia answers now. That ought to be some kind of record...

haha

Cool, blocks return stuff.
If I wanted to, I could rewrite my answer as `f(s,p,r,_=try i=0;s[[i=findnext(s,c,i+1)for c=p]']=r end)=s`. Not that it helps in any way...
Also, order of evaluation is so very, very weird.
```julia> x,i,x[i]=[1,2,3],1,4
([4,2,3],1,4)```
That one actually made sense. But this?
```julia> x,x[i],i=[1,2,3],4,1
([4,2,3],4,1)```
Ha, that weirdness actually saved a byte!