« first day (2137 days earlier)      last day (534 days later) » 

12:55 AM
Sorry for the extremely basic question, but: how do you read in a text file in gnu apl? I'm trying to do this year's advent of code in APL, but I'm stuck at the first hurdle (loading a text file of numbers).
I'm looking at this documentation: https://www.gnu.org/software/apl/apl.html#Section-2_002e26
Closest I have is:
Zh←⎕FIO[ 3] 'day1raw.txt'
Zh
which prints 7 for some reason, 7 isn't even the first character in the file.
 
 
2 hours later…
2:40 AM
@Lapwing482 fopen just returns a file descriptor integer, which you generally pass around to other libc functions. You probably want fread instead.
 
 
3 hours later…
5:51 AM
AoC Day2: data←{' '~⍨{'ABC'['XYZ'⍳⍵]}@(∊∘'XYZ')⍵}¨⊃⎕NGET 1,⍨⊂'input.txt', and Part1 +/{(3 0 6)[1+3|-/i]+⊃⌽i←'ABC'⍳⍵}¨data
Part 2: +/{(1+3|+/i)+(0 3 6)[x←⊃⌽i←'ABC'⍳⍵]}¨data
(⎕io←1)
 
 
1 hour later…
7:02 AM
@LdBeth Maybe you want to add your code to apl.wiki/aoc?
 
7:14 AM
I'm not sure if I'll go for speed running or give more meaningful programs, but I'll make an edit to aplwiki if I decide to collect my answers. (Still fighting with school's ARM assembly project tonight)
 
 
3 hours later…
10:20 AM
Here's my attempt:
⎕IO←0
m←3|'ABCXYZ'⍳1 0 1/↑⊃⎕NGET'input.txt'1
⎕←(+/(1+⊢/)+3×3|1+-⍨/)m
⎕←(+/(3×⊢/)+1+3|1-⍨+/)m
It was surprising to see how similar the solutions for the two parts turned out to be
 
 
3 hours later…
12:59 PM
Welcome to APL Quest 2017-4! Today's quest is Slice(s) of Pie(s):
> Write a function that calculates and returns the areas of 0 or more pie slices. The left argument is 0 or more angles (in degrees). The right argument is 0 or more pie diameters.
 
{360÷⍨4÷⍨⍺×○1×⍵*2}
 
Also, you can combine the two divisions into 1440÷⍨
 
○1
1 times pi
 
is a normal function, so it takes everything to its right as its argument.
 
@Adám yes, just for clarity
 
1:01 PM
○1×⍵*2 ←→ ○(1×⍵*2)
 
ah ok. Makes sence
 
How concise and efficient can we make it?
 
All the × and ÷ can be combined
 
True, but does that help?
Try going tacit.
Since there's only one monadic function, you should have that as the last step, the far left.
 
(1440 ÷⍨⊣ × ○∘1 × *∘2)
more or less, working on it
 
1:09 PM
The ○∘1 can't work like that.
Oh, I see, that's WIP code.
 
yes.
 
Hi @Silas, you like tacit stuff, right? What can you make of {360÷⍨4÷⍨⍺×○1×⍵*2}?
 
I like {(⍺÷360)×○2*⍨⍵÷2} or even {(⍺÷360)×○(⍵÷2)*2} for clarity, personally
I will have a think about tacit
 
you mean, how would I make that tacit?
 
Yeah.
@RikedyP Literally spelling out the formulas, OK.
 
1:14 PM
hehe
actually I think mine's wrong - oops
oh no it's fine
I'm misreading test cases
 
My shortest solution needs ⎕DIV←1
 
what goes wrong here?
(1440÷⍨⊣×○⊢*2)
 
your right tine is an array
which is not a valid train
 
You can fix it with a trailing
But also, your will be called dyadically.
 
how long's your shortest @Adám?
 
1:18 PM
9 with ⎕DIV←1, 10 otherwise.
 
geez
 
I had 360÷⍨×∘(○2*⍨÷∘2)
 
Right, that's basically the tacit equivalent of @RikedyP's spelling out.
 
@Adám wow
 
Just need a bit of mathematics for moving the terms around.
 
1:22 PM
@Adám does it have the literal 1440 in it?
 
Yes, both do.
 
ovs
1440÷⍨⊢××∘○ and ×∘○÷1440÷⊢ with ⎕DIV←1, 11 and 10 chars
 
Good. Now you just need to move to the far left.
 
wild
 
This you mean
(○1440÷⍨⊢××)
 
1:34 PM
Bravo. I had ○⊢××÷1440⍨
And ○⊢÷1440÷× with ⎕DIV←1
Richard, you're the winner…
See you next week for 2017-5: Slice(s) of Pie(s)!
 
Did a quick runtime: unsurprisingly, doing less maths takes less time:
  ]runtime -c "a{(⍺÷360)×○(⍵÷2)*2}b" "a(1440÷⍨⊢××∘○)b" "a{1440÷⍨⍵×⍺×○⍵}b"

  a{(⍺÷360)×○(⍵÷2)*2}b → 3.9E¯5 |   0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  a(1440÷⍨⊢××∘○)b      → 2.7E¯5 | -31% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  a{1440÷⍨⍵×⍺×○⍵}b     → 2.7E¯5 | -32% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
 
Hmm, still going but why doesn't (2*⍨)12 work?
gives missing right argument
 
it probably missed the right argument before swap is being done?
 
yeah, just confused as thought would be valid
 
1:47 PM
or ... it's an array and a function, an atop. So the function needs an argument
(2×)4 is for that reason also not valid
(2∘×)4 is however, Which is a single function by ny understanding
But there are better people to explain it
(2∘x) is even not a train i guess
 
I think (2*⍨)12 is valid in some dialects?
> Only dzaima/APL allows (A h), which it treats as A∘h.
Why doesn't Dyalog APL allow (A h) anyway? That seems pretty convenient.
 
 
4 hours later…
5:40 PM
Different approach to AoC day 2
(4 8 3 1 5 9 7 2 6)+.×w[⍋{⍺(w←≢⍵)}⌸⊃⎕nget 'input02.txt' 1;2]
works as long as every combination is used
and didn't use logic to calculate to victory points
 
@Richard interesting
 
(3 4 8 1 5 9 2 6 7)+.×w[⍋{⍺(w←≢⍵)}⌸⊃⎕nget 'input02.txt' 1;2]
and second one
but other solutions are smarter
 
I had:
i←⍉↑¯65 ¯88+↓⎕UCS⍉(↑⊃⎕NGET'd/2'1)[;0 2]
+⌿(1+3 6 0 0 3 6 6 0 3[x←3⊥⍤1⊢i])+u←⊢/i ⍝ part 1
+⌿(1+2 0 1 0 1 2 1 2 0[x])+3×u          ⍝ part 2
for ⎕IO←0
 
6:07 PM
⊥3 is nice @xpqz :)
 
6:54 PM
+/{⍵[2]+⍵⌷↑(3 6 0)(0 3 6)(6 0 3)}¨data ⍝ part 1
+/{(0 3 6[⍵[2]])+⍵⌷↑(3 1 2)(1 2 3)(2 3 1)}¨data ⍝ part 2
where data is a vector of vectors of the input, where A/X -> 1, B/Y -> 2, and C/Z -> 3
 
7:38 PM
Here's mine:

s e←↓⍉3|¯1+1 0 1/23|⎕A⍳↑⊃⎕NGET'2.txt'1
+/(1+e)+3×3|1+e-s ⍝ part 1
+/(3×e)+1+3|e+s-1 ⍝ part 2
No idea how to do code blocks in SE chat lol
 
7:56 PM
Oh, I guess I don't need that 3| if I'm doing 23| (was trying to golf a bit)
 
 
1 hour later…
9:21 PM
@voidhawk Ctrl-K does it
 

« first day (2137 days earlier)      last day (534 days later) »