« first day (1314 days earlier)      last day (1333 days later) » 

12:43 AM
Is some able to explain the differing results of the following three expressions:
3{⍺}/1 2 3 4
1 2
3{⍵}/1 2 3 4
3 4
3{⍺,⍵}/1 2 3 4
┌─────┬─────┐
│ 1 2 3 │ 2 3 4 │
└─────┴─────┘
 
@code_report 3 f/ 1 2 3 4 where f is a function gives (1 f 2 f 3)(2 f 3 f 4), because x f/ y is "windowed reduction" where y's windows of size x are extracted and each of the windows is reduced by f.
The results should be self-explanatory.
 
@Bubbler thanks for the response. So if I wanted to have a reduction operator that looked at the three element at the same time, that isn't possible. I would have to do something like f¨3,/1 2 3 4
 
1:00 AM
@code_report Yes, that would give (f 1 2 3)(f 2 3 4).
 
1:13 AM
Anyone have a more idiomatic way to solve this "find peaks" problem?
f ← {({∧/⍵[1 3]≤⍵[2]}¨3,/⍵)/¯1↓1↓⍵} ⍝ solution 1
g ← {(((2>/x),0)∧0,2</⍵)/⍵} ⍝ solution 2
x
1 2 3 1 1 4 2 1 0 5 2
f x
3 4 5
 
@code_report Your g is pretty good IMO.
 
2:00 AM
@code_report Btw, what is the exact condition of that problem? Is it to extract the elements strictly greater (>) than its neighbors or is it ?
 
@Bubbler Strictly greater than
 
Something like this might be possible: f←{(¯2=2-/×2-/⍵)/1↓¯1↓⍵}
 
Yep, that would work as well. Still seems like there should be a simpler way to do it :/
 
2:32 AM
Not really, it's a sufficiently complex problem.
 
 
5 hours later…
7:35 AM
@ngn Fixed. Thanks.
 
codegolf.stackexchange.com/questions/25885/… Any places where I can save a few bytes?
I took a while to rearrange stuff in this one
 
8:13 AM
@Razetime (1○p)1○p
@Razetime (2○p)↑⍤⍮(1○p) should work as 2↑⍤⍮⍥(○p)1
@Razetime (2×○⍳s+1)÷ss÷⍨2×○⍳s+1
 
@Adám That one looks wrong
 
@Bubbler Yes, fixing now.
@Razetime … P5.draw←{P5.G.ln⍉r+r×2↑⍤⍮⍥{⍵○s÷⍨2×○⍳s+1}1}
 
2↑⍤⍮⍥{⍵○s÷⍨2×○⍳s+1}1↑2⍮⍥{⍵○s÷⍨2×○⍳s+1}1
 
Oh yes, of course.
 
⍉r+r×↑2 1○⊂s÷⍨2×○⍳s+1 seems to work
 
8:30 AM
I refactored my solution to last years phase 1 problem 7, P7 ← (⌈¯2÷⍨0⌈-∘≢¨)⌽↑⍤0 1∘↑, are there any noticeable errors?
 
8:44 AM
> or possibly a single word
 
↑r+r×2 1○ᑈs÷⍨2×○0…s
 
Nice.
 
@dzaima (not shorter in the rewrite - ….ln r+r×2 1○ᐵs÷⍨2×○0…s)
 
Oh no which one should I use lmao
 
One of dzaima's last ones.
 
8:55 AM
@Razetime well, one has a public interpreter, and the other is unfinished and only i have it.. :P
 
so obviously the unfinished one
It works!
 
@Razetime (either you're lucky that that exact challenge allows input in variables, or you specifically searched for one that does because there's not really any way for APLP5 to take input :p)
 
Is there an easier way to take the product than prod ← (≢⍤⍸⍴∘1)? If so, how?
 
I was lucky lol
 
@rak1507 Product? Like × ?
 
9:00 AM
I was going around graphical output challenges and saving the links like @Bubbler
and this one fit in pretty well!
 
Yeah @Adám like of some numbers
 
I should add an explanation
 
@rak1507 Will ×/ work for you?
 
...
Yes
it will
 
@dzaima the program is tied for first now :D
a victory for APLP5
 
9:05 AM
@Razetime except this
 
aww dammit
still a victory
 
9:34 AM
Probably a dumb question, if I have (a b c d e f) is there a way to do (a+b, c+d, e+f)? n-wise reduction isn't quite what I want, but there might be a way to do it with that
 
@rak1507 +/⍤⊢⌺(⍪2 2)⊢a b c d e f or +/3 2⍴a b c d e f
 
9:48 AM
so +/⍤⊢⌺(⍪2 2)⊢a b c d e f tacit fn can be used on any size right
 
Yes.
@Razetime So can +/⊢⍴⍨2,⍨2÷⍨≢
 
10:06 AM
I'm sure I've asked this before but is there a way to apply a function to a specific column of a 2d array?
maybe something with @ and ⍤
 
@rak1507 Separately on each element of the column, or on the column as a whole? And do you want the result in-place or extracted?
 
On the column as a whole, and in place, something like
1 2                      1 4
3 4    -> with ⌽    3 6
5 6                      5 2
ah formatting got lost
 
Use Ctrl+K to format as code block.
 
not perfect but you get the idea
 
@rak1507 0 1⊖matrix
 
10:12 AM
Ah of course, thanks!
 
In general though, ⍉f@colNum⍉matrix
 
10:43 AM
From your advice the previous day, I used the box dfn to make a function
⋄{⍬1 1box 4 4⍴⍵⊤⍨16⍴2}4283
 
@Razetime VALUE ERROR
 
⋄'box'⎕CY'dfns'
⋄{⍬1 1box 4 4⍴⍵⊤⍨16⍴2}
 
@Razetime The bot doesn't allow you to import stuff.
 
oh
so I'm getting this
 
Just use TIO.
 
10:44 AM
+ - + - - - +
| 0 | 0 0 1 |
| 0 | 0 0 0 |
| 1 | 0 1 1 |
| 1 | 0 1 1 |
+ - + - - - +
 
Right, because you have numbers instead of characters.
 
ohhhh
so i need to convert to characters and it should work correctly
 
Right, but you may need to adjust your column numbers.
 
also something's wrong with the table itself
why's it showing 4x2 when it's 4x4?
 
@Razetime You're reshaping to 4 4 after formatting. Maybe something like:
      {⍬1 1box⍕4 4⍴⍵⊤⍨16⍴2}4283
+-+------+
|0| 0 0 1|
|0| 0 0 0|
|1| 0 1 1|
|1| 0 1 1|
+-+------+
 
10:58 AM
yeah, but now the individual elements have to be boxed
 
Oh, so you do want a "recursive" display like the actual boxing, just ASCII-only?
 
yes, pretty much
basically parititioned enclose and box
{⍬ 1 1 box ⍕(4 4⍴(16⍴1⊂(⍵⊤⍨16⍴2)))}
 
@Razetime It may be easier to construct your array, use disp and then regex the right characters in.
 
using disp?
oh I'll see
 
11:34 AM
It's very annoying that 0 1⊖⊂↑(1 1) doesn't work :(
 
@rak1507 Wait, what are you trying to do? The there is a no-op.
 
I'm doing question 9 from last years phase 1, and my solution works for 2 or more points, but breaks for a single one, because of that
It would be convenient if that just was 1 1
 
@rak1507 You just want to ensure that you've got a vector of vectors?
 
Yeah I guess
 
Monadic encloses any simple argument (if possible), so ,⊆ will do the trick.
 
11:41 AM
Ah cool
 
 
1 hour later…
12:42 PM
0 1 ⊖ ⊂1 1 still doesn't work
 
@rak1507 No, but you probably mean 0 1⊖↑,⊆1 1
 
Oh that's cool, thank you
f←2÷⍨(|∘(-/)(+/∘(×/)¨(0 1)(0 ¯1)∘.⊖⊂∘↑∘,∘⊆)) I feel like I have used slightly too many ∘s haha
 
If you find yourself doing that, it may because you're applying a lot of monadic function, so a dfn might be a better format.
 
yeah
Alright thanks
 
@rak1507 Instead of working on nested arrays, try to work on flat ones. Hint: Use 2 2⍴0 1 0 ¯1.
I'm so looking forward to having array notation: [0 1 ⋄ 0 ¯1]
 
12:57 PM
{2÷⍨|-/+/¨×/¨(0 1)(0 ¯1)∘.⊖⊂↑,⊆⍵} yeah the dfn is much nicer
Also I'll have a look at what you suggest
I feel like there must be a nicer way to do ⊂↑,⊆
 
You wouldn't need the final if you stayed flat.
 
Hmmmm
Ok
 
And the remaining 3 functions each perform a distinct job:
⊆ ensure the right depth
, ensure the right shape
↑ gain rank at the cost of depth
 
That explains why I saw the use of ⊆ quite a lot and never knew what it did
 
@rak1507 It is extremely useful in practical production code. When it was still a new primitive, we tried to make problems that needed it.
 
1:09 PM
Makes sense, quite a few of these 2019 ones seem like it could be useful
Question 5 even suggests it in the hint, although I have no idea why, as I was able to solve it simply without it
Ohh
I just realised why
Never mind I haven't
 
@rak1507 What's your solution like?
 
P5←(∨/2=/'n '∘,)¨
'n '∘, is a bit of a hacky solution
 
Yeah.
 
works though
 
Only because of the specific problem. It isn't a general solution.
 
1:16 PM
I guess I could use nest and rotate
 
@rak1507 Fails on single words, btw.
 
oh so it does
That solution sucks going to do a new one
 
The basic idea is good. You just need the input-normalising preprocess.
 
P5←{∨/=⌿↑0 1∘.↓⊂⍵}¨∘⊆
 
@rak1507 Why? Your 2=/ was good. Now you're nesting again.
 
1:22 PM
Oh yeah 2= forgot about that
Ah but then I have the issue when it's only 1 character long
 
@rak1507 What do you mean? 2=/v can handle 1-element vectors.
 
I get a rank error
 
@rak1507 Are you sure you have a vector? (Hint: ,)
 
Ahh ok thanks
P5←{∨/2=/,⍵}¨∘⊆ then?
 
@rak1507 Sure, but the inner dfn is actually a good fit to become tacit.
 
1:37 PM
P5←(∨/2=/,)¨∘⊆
Alright I'm sold ⊆ is great
Don't need the ∘ too right
 
Correct. (On both accounts.)
 
Thanks for the help with the vector stuff, still a bit confusing
 
No problem at all.
 
Would be nice if APL had some sort of verbose representation mode to make it a bit clearer, especially with 0 element arrays and stuff like that
Also, one thing that is really cool about APL, is often when you refactor something into a better solution, the solution gets smaller as well, whereas in some languages when you make something more efficient you have to implement more functionality and increase the code length
 
1:55 PM
@rak1507 like ]box on -style=max ?
 
Exactly like that haha
Amazing
 
@dzaima is there a way in dzaima/bqn to do multi line fns in the REPL?
Foo ← {
SyntaxError: error matching parentheses
or a way to load a file would also work
im doing something like
/REPL -r -f myfile.bqn

but getting this error
SyntaxError: Unknown variable "foo"
 
2:12 PM
@rak1507 You can try ]boxing on -style=max in Dyalog APL to get a bit clearer view of when things are nested, or 0 elements, etc.
... as I wasn't reading and has already been suggested
then I second it, wishing I'd found it months ago
 
Maybe I should add it to my tips page?
 
@cannadayr no; a file should work the way you used it
alternatively, you could do )ex myfile.bqn in the REPL (or, alternatively, •Ex"myfile.bqn", which also works in expressions, not just the REPL)
@cannadayr ah, you're getting the error from using foo in the REPL, not from executing the file itself. this is an unfortunate consequence of how variables work - the file is executed in its own scope
 
Question 10 is pretty tricky, need to find a way to provide a default value or something, hmmmm
 
@TessellatingHeckler @rak1507 Now live.
@rak1507 Default value for what?
 
In school :/
@Adám for the key function
 
2:23 PM
@cannadayr a hacky way would be to make the last line of the file be just and then do )cs •Ex"myfile.bqn"
 
those tips are cool
definitely going to bookmark
'If you enter )off then your session log is saved before APL closes, so you can simply scroll up when you're ready to continue'
this is incredible
 
@rak1507 I wonder why we suggested the Key operator (!) for that.
 
and ctrl shift backspace
 
@dzaima actually, i think i could add a REPL-only file execution command, executing in the current scope, at the cost of •args and •path not being set
 
@Adám I mean it's easy to do without defaults, but with defaults it's tough
((2|≢¨){⊂⍵}⌸⊢)
and nest and stuff
 
2:26 PM
@rak1507 You can simply prepend two vectors in a specific order that go into the two groups.
 
ah yeah, fair enough
 
But it is much simpler to sort the vectors as required.
 
⍬ would probably work I guess, maybe
Or not
 
@rak1507 Btw, I highly recommend getting used to backticking or codeblocking code. If you don't then you'll one day use expand or power and get the wrong thing displayed.
 
```
oops
 
2:28 PM
@rak1507 Sure, that's a length-0, i.e. even-length vector.
 
Alright I will
 
Ctrl+K is a quick way to make a code block.
 
not with the apl keyboard unfortunately, I'll have to switch for a sec
test
`
test
`
```
test
````
 
No, you can't use fences.
 
I'll use ctrl+k then
 
2:30 PM
Also, you might want to use the sandbox for testing.
@rak1507 Well, there's also a button on the right →
 
@Adám reminder
 
@dzaima Not sure what you mean. It already says:
> Use Ctrl+Shift+Backspace and Ctrl+Shift+Enter to scroll backward and forwards in your input history. They can also be used as Undo and Redo in the editor.
 
huh, IIRC the shortcut wasn't bound by default to anything. either i'm misremembering or that was changed?
 
I'm pretty sure that has always been the default.
Maybe the very first tip should be how to get rid of the default Ctrl key bindings, and set up some saner ones.
 
@dzaima probably misremembering. probably thought that was too horrible of a shortcut to be used by anyone
 
2:45 PM
I'd dearly love to split prev/next from undo/redo, making the latter Ctrl+z/y.
 
@Adám ctrl+z isn't undo in the Windows IDE‽
(and is that why it's called "backward or undo" in RIDE, despite not being undo?)
 
ngn
@Bubbler vtc: requires thinking
@dzaima it's "backwards" in the session and "undo" in the editor
 
@ngn ah. but since ctrl+z still works, it's still pointless
 
ngn
@dzaima backwards compatibility :)
 
3:07 PM
@Adám "Use ⎕SE.Dyalog.Utils.repObj myArray to generate an expression for (almost) any given array." ⍥
 
3:29 PM
@dzaima No, of course not, since that's needed for !
@ngn I see what you did there ;-)
@TessellatingHeckler I'm not sure what you're getting at.
 
ngn
@Adám yeah :) but the pun is literally true: the reason ride has such a command is that good old <BK> behaves like that ("backwards" in session, "undo" in editor)
 
 
1 hour later…
4:48 PM
@dzaima this is what i ended up doing ty
 
 
2 hours later…
7:10 PM
Why is the following use of "item amend" not legal in J: 0 1 0 1} i.2 4 2? Try it online!
 
@Jonah From NuVoc, "Operand m must have the same shape as an item of y." So you can use (4 2$0 1 0 1)} i.2 4 2 but not what you wrote. Kind of silly but amend has a lot of weird design decisions.
 
BQN q: is there a way to do something like the following?:

⟨Foo⟩ ← {
    Bar ← {𝕗+𝕩}
    ⟨{(1 Bar) 𝕩}⟩
}
SyntaxError: couldn't join everything to a single expression
    ⟨{(1 Bar) 𝕩}⟩
 
@Marshall thank you.
 
@cannadayr I think the only problem is that you're writing Bar instead of _bar. Since bar contains 𝕗, it's a 1-modifier.
@Jonah 0 1 0 1 {"_1 ]1 0 2|: i.2 4 2 works but I don't have any better ideas. You could also box the 1-cells, then unbox afterwards, but that's probably slower.
 
@Marshall yeah i had got boxing to work, but for golfing it tends to be verbose, so...
 
7:23 PM
:55407956
yup thats it ty
 
@Jonah Well the BQN version is a lot more compact just because it has a better transpose, although it's missing a flat version of iota.
 
@Marshall i gotta say, bqn has already simplified some of my code in really surprising ways.
 
7:43 PM
still a wip but to see how far I could take it ive been toying w/ my univariate sample stats fns:
⟨Mean,Stdev,Skew,Kurt⟩ ← {
    Mean  ← { (+´÷≠) 𝕩}
    _foo  ← { (𝕗 +≠ 𝕩) ÷˜ +´(𝕩 - Mean 𝕩) ⋆ 𝕨    }
    _bar  ← { (𝕨 𝔽  𝕩) ÷    (2   𝔽    𝕩) ⋆ 𝕨 ÷ 2}
    Stdev ← { √ 2(¯1 _foo)      𝕩}
    Skew  ← {   3( 0 _foo) _bar 𝕩}
    Kurt  ← {   4( 0 _foo) _bar 𝕩}
    ⟨Mean,Stdev,Skew,Kurt⟩
}
still not sure what to name foo/bar
 
@Marshall Cool, I wasn't aware of BQN. I ended up finding an altogether different approach for the problem that got me thinking about item amend.
 
@Jonah So much work for that last row...
I think I've seen ngn use a scan for this kind of thing. That would be ([:|.@]/\]\)~- .
 
8:07 PM
@cannadayr Hm, bar could also be { 𝕨 (÷○(𝔽⟜𝕩) ⋆ ÷) 2 }. Still need to finish the doc on tacit programming.
 
@Marshall v nice will have to test out laterz. Taking it slowly wrapping my head around it.
so far, bqn feels like i can make smaller, more flexible factors than apl.
 
@Marshall "So much work for that last row..." Exactly. The original solution (with incorrect last row) was a tantalizing 7 bytes. Thanks for making me aware of that scan trick... I've actually never seen it before.
 
@Jonah That is how all ngn code works.
And yes, it's an ngn trick: turns out the APL answer references it.
 
@Jonah more like your original solution: ([:]|."1])~-` – however, this does not parse correctly in TIO? Really not sure what's going on.
(and pretty nifty scan trick!)
 
8:24 PM
@Marshall Is there any design reason J doesn't have an adverb to apply cyclic gerunds to the items of any list? You can use oblique /. as a hack to achieve this but it only works when applied at rank 0 (ie, you have to box and unbox).
@xash Is that snip supposed to be an entire working answer or part of one?
 
@Jonah ah, damn quoting: it uses an adverb to apply cyclic gerunds: ]'|."1, but with a backtick instead of the '. So ([:]<backtick>|."1)~- :-)
 
@Jonah Looks like it was actually added in J901! I missed it because I only have 806 installed. Check "Language addition: gerund"r" in the release notes. Here's the original thread on that idea too.
 
If u is a gerund, it specifies a sequence of verbs. The first verb is applied to the first cell, the second verb to the second cell, and so on, wrapping around if there are more cells than verbs in the gerund. code.jsoftware.com/wiki/Vocabulary/quote
Oh, might this be the reason why it doesn't work in TIO? Too old version?
 
@xash You can escape a backtick in code here with a preceding backslash. \` gives `. So you wanted ([:]`|."1])~-, I guess.
 
@Marshall Excellent! @xash Exactly.
 
8:31 PM
@Marshall Ah, cheers! And yes, exactly that. Or with one byte less: ]`|."1@(]\)~-.
 
@xash TIO accepts PRs for upgrading. I'm not sure how versioning / backwards compatability is handled. I'd like to upgrade the J there but haven't had the time to look into it.
@xash I'll update the answer with a note it only works on 901. I've wanted this feature for some time.
It also includes the F. family of verbs which can probably shave bytes of some of the sequence challenges.
 
 
2 hours later…
10:55 PM
@Jonah J 901 is on the list of pending updates (along with Dyalog APL 18.0).
 
11:12 PM
@Bubbler Thanks!
@Bubbler What is the process, those go into the requests queue .md file, and then does caird make a PR on the TIO repo?
 
@Jonah No, currently there's no one to accept PR or anything. See the starboard on the TIO chat room.
caird is simply collecting a list so that Dennis can handle them better when he returns.
 
11:28 PM
Thanks.
 

« first day (1314 days earlier)      last day (1333 days later) »