« first day (1503 days earlier)      last day (1150 days later) » 

ngn
7:00 PM
there's no single correct translation to apl. ⍺f¨⊂⍵ and (⊂⍺)f¨⍵ could be just as valid.
@nathanrogers in k9 many things are different from other k-s, including /: and \:
 
wow # is different
 
ngn
@nathanrogers yes, in k9 list# became set intersection and list_ set difference
like "take" and "drop" for sets
 
@ngn Wait, so how does one partition?
(Unrelated: k.txt went dark.)
 
ngn
@Adám partition? in what sense?
@Adám i can open it
 
@ngn Didn't list# use to take subsequent segments of lengths?
@ngn Yes, and it is dark now, isn't it?
 
ngn
7:10 PM
@Adám ah, you probably mean "cut", that's n^
e.g. 3^"abcdef" ←→ ("abc";"def")
 
@ngn And 2 4^"abcdef" gives ("ab";"cdef")?
 
ngn
@Adám it's the same as before for me, even after ctrl-shift-r
 
@Adám i can open it too
 
Ah, it now depends on your OS theme preference.
 
ngn
@Adám last time i looked list^ was exactly like the same as the good old "cut" (list_ in k6) - taking indices, not lengths
 
7:13 PM
@ngn Oh, ok, that's just me misremembering.
@-moz-document unobservable-document() {
  @media (prefers-color-scheme: dark) {
    :root {
      /* in-content-page-{color, background} for dark theme. */
      background: #2a2a2e;
      color: rgb(249, 249, 250);
    }
  }
}
 
 1 2 5\!10
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 1 1 1 1
0 1 2 3 4 0 1 2 3 4
 
@nathanrogers That's
 
this looks like split, at least its called split in the docs
 
@nathanrogers Yes, that splits into digits of a given (mixed-)radix.
 
ngn
@nathanrogers split is "separator"\"string"
 
7:15 PM
I really dislike that difference between data types there.
 
ngn
i really like the symmetry and analogy with other uses of / and \
 
1 3^"abcdefg"
bc
defg
then ^ is cut
 
@ngn How does one split a numeric list on 1 0?
 
I think you would just do a &
(&1 0)^list
 (&1 1 0 0 1)^"abcdefgijk"
a
bcd
efgijk
 
      a
1 0 0 0 1 0 1 1 0 1 0 0 0 0 0 1 1 0 1 1
      1 0⍷a
1 0 0 0 1 0 0 1 0 1 0 0 0 0 0 0 1 0 0 0
      1 0(⍷⊂⊢)a
┌───────┬─────┬───┬─────────────┬───────┐
│1 0 0 0│1 0 1│1 0│1 0 0 0 0 0 1│1 0 1 1│
└───────┴─────┴───┴─────────────┴───────┘
@nathanrogers I don't get it. How do you do ^ ?
 
7:20 PM
I'm not sure I follow. indices ^ list
& is ⍸ so (&bitArray) ^ list
 
@nathanrogers Given my a above, how do you get the final array above?
 
ngn
@Adám why not "given my 1 0⍷a above"? you're asking 2 questions in 1: what to pass to ^ and how to compute 1 0⍷
 
@ngn Because my original task was based on the missing functionality to "split on numeric sequence" when the parallel with the existing "split on character sequence" is obvious.
 
cmc: decrement the first number in a vector
 
-∘1@1
 
7:26 PM
there's a 4
 
ngn
@Adám i see
@rak1507 in apl?
 
yes
 
I was looking for an unusual scan, but I can't seem to find one.
 
not a scan
 
@rak1507 That's short enough to brute-force.
 
7:34 PM
here's a hint: I didn't just come up with it randomly
 
ngn
@Adám but not important enough to bother actually doing it :)
 
@ngn Wait, are you content with living without solving this‽ Who are you, and what did you do to ngn?
 
the underlying idea could save ~a byte or so in some situations, maybe
 
ngn
@rak1507 ?@0 <- there! it worked
 
haha
 
ngn
7:39 PM
@Adám well, there are easier methods to learn the answer
trying lots of random things, actual logical reasoning, beating rak1507 with a rubber hose
 
I like the sound of the first 2 more than the 3rd one...
 
@ngn You could also offer to pay him. You know, capitalism… Everything has a price.
 
10000 pounds per golfing tip :D
 
ngn
@Adám rubber hoses are cheaper than developers :)
 
I know where he lives.
 
7:43 PM
oh no
 
yeah I have no idea what I'm doing. @ngn how would you do that?
you're right its really 2 questions
 
ngn
@nathanrogers as you said, a boolean mask can be converted to a list of indices with & (where)
 
right, but how would you do something like a windowed comparison?
 
@ngn That's the easy part.
 
well, that's the question you asked, how do I partition
 
ngn
7:45 PM
for 0 1⍷ maybe eachprior for this particular case, like >':
it may need some adjustment with 1_ or appending something
 
@ngn OK, but in the general case.
 
ngn
@nathanrogers "sliding window" is n'
 
(&,/0 1>':a)^a
10001
01
101
000001
101
1
close, but no stoagie
 
ngn
@nathanrogers no no, just >': without a left arg. it means "greater than each prior", i.e. "is the current item a 1 and the prior a 0" for bools
 
here's my ⍷ implementation {*/a,'{x#0}'(#y)-#'a:(!#x)_'x=\:y}
idk what I'm doing
 
ngn
7:48 PM
@Adám in the general case something like 0 1~/:2'a
 
that doesn't work in shakti
 
ngn
(sliding window of size 2 over a, and then does 0 1 match each element on the right)
 
@ngn You'd want the length of the subsequence as argument, no?
 
oh, sliding window is cleverer
 
I was trying to do the sliding window but it isn't working in shakti
 
ngn
7:48 PM
@nathanrogers yeah, i don't remember what sliding window was there
 
ngn
maybe n': ?
 
what's the word for it in k?
that's each prior
 2':a
2':a
^
!rank
 
ngn
@nathanrogers dyadicfunc': is eachprior. int': might be something else.
 
{x~/:(#x)':y}
 
ngn
7:50 PM
@nathanrogers ok, it's not :(
 
sd
I was close
 
ngn
@ktye do you know how to do sliding window in k9?
 
cmc: take elements from a vector until reaching the first duplicate item
 
@ngn mavg:{(y-(-#y)#(-x)_y:+\y)%x}
 
@rak1507 2 7 1 8 2 8 1 8 2 8 becomes 2 7 1 8?
 
7:55 PM
yes
just found a 9 which is shorter than the cool 10 I had
 
Bad test case, though.
 
ngn
@ktye that takes advantage of the associative properties of +
 
1 2 3 4 1 9 becomes 1 2 3 4
 
@rak1507 I have 8 so far.
 
ooh
 
7:56 PM
@rak1507 Simple vector?
 
yep
 
7
 
:O
 
ngn
@ktye we needed something equivalent to n,/ in apl, e.g. f[3;"abcdef"] -> ("abc";"bcd";"cde";"def")
 
That translates to 8 in Dyalog 18 with ⊢⍤/.
 
7:59 PM
@Marshall Same idea. That'd be ∧\⍤≠⍛/⍨ in extended, but you get for free in BQN.
@Marshall Yes, but then there's the ∊⊆ golfing trick for 7.
 
@ngn what is the original question?
 
I have a 4 I think
 
ngn
@ktye split a sequence of numbers on the occurences of a given sequence of numbers
 
each previous also doesn't seem to be what I want
 
@ktye My complaint about "abc"\ splitting a character list on "abc" but 1 2 3\ not doing the same for a number list.
 
ngn
8:01 PM
@ktye like "sep"\"string" but for numbers
 
,':a
(10;01;00;00;10;01;10;11;01;10;01;00;00;00;00;10;11;01;10;11)
a
10001011010000011011
 
@rak1507 ∊∧\⍤≠⊆⊢ in case that wasn't obvious by now.
@rak1507 On your CMC?
 
second index is 01? that doesn't look like the right output @ngn
 
yes
@Adám it was, and it helped me
 
ngn
@nathanrogers the current item is x, the prior item is y
 
8:03 PM
@rak1507 Ooh, I have an idea.
 
I would never have thought of it without you mentioning ⊆
my 'cool 10' was {⍵/⍨≠\≠≠⍵}, using 3 ≠s :D
 
I see it too. Very lucky you can't have a length-0 result.
 
≠≠ is interesting I wonder if it would ever be useful
 
ngn
@nathanrogers so, the pairs returned by ,': are reversed with respect to the original order
 
@Adám just use a proper k: ktye.github.io/…
 
8:05 PM
@ktye proper=7?
 
@Adám no, ktye.
 
@rak1507 ⊃≠⊆⊢
 
yep
so cool
 
(&(1_{&/0 1=x}',':a),0)^a
(1000;101;10;1000001;1011)
48 mins ago, by Adám
      a
1 0 0 0 1 0 1 1 0 1 0 0 0 0 0 1 1 0 1 1
      1 0⍷a
1 0 0 0 1 0 0 1 0 1 0 0 0 0 0 0 1 0 0 0
      1 0(⍷⊂⊢)a
┌───────┬─────┬───┬─────────────┬───────┐
│1 0 0 0│1 0 1│1 0│1 0 0 0 0 0 1│1 0 1 1│
└───────┴─────┴───┴─────────────┴───────┘
 
there was an answer for just that from geocar on hn some time ago.
 
8:06 PM
did you figure out decrementing the first number yet
 
ngn
@nathanrogers {&/0 1=x} could be {0 1~x} or even (0 1~)
 
@rak1507 No. @Marshall Any ideas on decrementing the first element of a vector in 4 chars?
 
he should read up if he wants a clue
 
@ngn I'm not sure why I need the 1_...,0
kind of annoying
 
ngn
@nathanrogers think about it: each item from the list is paired up with its predecessor, and there's an implicit "seed" before the first item
 
8:09 PM
@rak1507 Clue to that CMC?
 
@Adám No, but 1⊸↓⌾/ is a cool BQN solution for natural numbers.
 
@Adám yep
nice, ⌾
 
(&(1_(0 1~,)':a),0)^a
(1000;101;10;1000001;1011)
@ngn
 
@Marshall That is very cool.
 
ngn
@nathanrogers so, we are matching the pattern from its end. a 1 in the bitmask means the end of a match. that's why the 1_ .. ,0 - because we want a 1 to mean the beginning of a match
 
8:11 PM
I really just wanted a 2 window
:P
and with this approach, it wouldn't work for arguments greater than 2
 
ngn
@nathanrogers tell that to shakti. other ks have it.
 
there isn't even a rotate
or if there is there's no name for it
I could do an iterative take drop scheme to implement rotate
 
@nathanrogers Why not concatenate the take after the drop?
 
or just use take drop to get windows
 
ngn
@nathanrogers trivial to implement, rarely needed
 
8:14 PM
@Adám I don't know what you mean
 
@nathanrogers Implement the equivalent of APL's ↓,↑
      3(↓,↑)'abcdefgh'
defghabc
      3⌽'abcdefgh'
defghabc
      ¯3(↑,↓)'abcdefgh'
fghabcde
      ¯3⌽'abcdefgh'
fghabcde
 
well that's what I'm saying, chunking seems like a pretty common need in array programming, a rotate could do that iteratively but it has neither windows nor rotate, so I guess the alternative is just to use take and drop like you showed that's waht I said here chat.stackexchange.com/transcript/message/57277651#57277651
idk why shakti doesn't have those things. clearly he doesn't use them or think other people use them all that much
 
ngn
@nathanrogers or ideally indexing. indexing is very fast.
@nathanrogers this is how my (ngn/k) sliding window is actually implemented: S A2(win,K("{y(!x)+/:!0|1-x-#y}",x,y))
 
ifrom memory: x=\:y (eq each right) returns a list, than shift each row by the row number, now a column of all ones, means everything matched. split on that.
i think the comment was about: it's not necessary (a primitive for that) because it's obvious for an array programmer.. i don't know if i agree.
 
8:30 PM
my linalg isn't great: why is ⌹⌹3 2 ⍴ 4 5 6 erroring? (⌹3 2 ⍴ 4 5 6)+.×3 2 ⍴ 4 5 6 is the identity matrix, so 3 2 ⍴ 4 5 6 should be the inverse right? idk
maybe it's a floating point thing
it works if you do ⍉⌹⍉ (⌹under⍉)
 
ngn
@rak1507 matrix multiplication is not commutative, so there's a left inverse and a right inverse
 
@ngn (&18#1 0)^|1_|1_,/2#'!10
2 window indices
 
@ngn ah
 
well not really
I've missed the last element
 
cmc: given a vector of all unique elements find where elements are equal to their index (0 1 2 5 4 6 8 -> 1 1 1 0 1 0 0 when ⎕IO←0)
 
ngn
8:49 PM
@rak1507 too easy, ⍳⍨=⊢
 
I have a 3 :D
 
ngn
∊=⌸ ?
 
yep
oh well that one didn't last very long
 
CMC: Given a list of length 2 or longer, answer the number of applications of monadic needed to reach 1 1 0 0 0 …
 
15 atm lol
 
8:57 PM
That's some pressure.
 
ngn
if only apl had converge-iterate..
 
≠1 1 0 0 0... is not 1 1 0 0 0 so you'd need something along the lines of dfns.traj
this is a very interesting challenge
I think I have an 8 but I'm not sure that it works
 
9:14 PM
@ngn Even if given a function for , could you do this easily in K?
 
it works on some random inputs, so I think it works
how long is your solution?
 
I didn't write one. Just posted the CMC to keep you busy.
 
oh
 
ngn
@Adám it doesn't converge, so probably not as easily as using \ directly
 
oh my solution doesn't work anyway
 
9:14 PM
@ngn My point.
 
it finds a number of ≠s that work but not necessarily the minimal number
 
@rak1507 24 so far.
 
ngn
i have 17
this bug with ≠¨ is annoying
 
@ngn You can pretend that's fixed: Z←⊢⍤≠
 
ngn
17: {⍵≡2>⍳≢⍵:0⋄1+∇≠⍵}
 
9:26 PM
@ngn That's very nice and clean.
 
ngn
..and long :|
 
I don't think any method will get shorter than that, I think {(a←2≠/2↑⍵)∧2≡≢∪⍵:1⋄a:3⋄2} works which can be golfed but not short enough
 
ngn
@rak1507 didn't you say you had 8?
 
yes, it was wrong
 
0 {⍵ ≡ 1 1↑⍨≢⍵: ⍺ ⋄ (⍺+1)∇≠⍵}⍳9
 
ngn
9:29 PM
ah
 
is this not it?
oh you can cumulatively sum instead of using ⍺ I guess
 
@nathanrogers Yes, that's pretty much exactly what I had.
 
sorry I wasn't looking at chat :C
 
@nathanrogers I didn't post mine. It was
0∘{⍵≡1 1↑⍨≢⍵:⍺⋄(1+⍺)∇≠⍵}
 
9:30 PM
my 8 was 2+∘⊃2≠/⊢ which finds a number of ≠s that work but it fails on something like 1 2 1 2 where it should be 1 not 3
 
ngn
@nathanrogers you like inserting spaces everywhere even when golfing :)
 
t⍤t yes I do love my whitespace
 
ngn
i win :P
 
now figure out how to decrement the first item in a vector
 
@rak1507 {⍵+1↑⍨≢⍵}⍳9
2 2 3 4 5 6 7 8 9
?
 
9:33 PM
decrement, not increment, and in 4 chars
 
ngn
@rak1507 are you sure it's just apl and not any dzaima, "extended", etc stuff?
 
yes
 
{⍵+¯1↑⍨≢ ⍵}⍳9
0 2 3 4 5 6 7 8 9
 
that's one way to do it...
 
Hm, about 20 million possibilities.
Any dyadic operator would seem too expensive, byte-wise.
 
9:36 PM
I don't have all the golfing idioms down yet :C
I don't know where to take this one
 
this isn't a golfing idiom which is why everyone's stuck ;)
 
4 characters ?
i'll bet it uses encode
 
no
 
or some such nonsense
 
it uses something that was discussed earlier
 
9:36 PM
sign probably
 
that should be enough of a hint to get it
are you going to try narrowing it down one primitive at a time
 
Eureka!
 
did you get it
 
@rak1507 That's what I did, and it didn't take long to find it.
 
is it something like +~<? (plus not grade-up)
or minus =S
 
9:38 PM
@rak1507 Yes, but your hint from earlier didn't lead me at all. Only after I found it, did I realise how it was a hint :-)
@coltim What? That doesn't look right.
So obvious, now that I think about it. D'oh.
 
ngn
@coltim apl's "not" tolerates only 0 and 1
 
haha yep wonder if the secret bit has any golfing applications, seems like it might be useful in niche scenarios
 
Fun fact: I had eliminated all but 64 primitives by the time I found it.
 
@ngn it's like speaking only-somewhat mutually intelligible dialects, heh. I think a k answer could be {x-~<&#x}
 
@coltim Yeah, that is indeed very similar to my solution.
 
9:42 PM
I did it
 
ngn
@coltim also: @[;0;-1+]
 
@rak1507 ⌽{1=≢⍵:¯1+⍨⍵ ⋄ (⊃⍵),∇ 1↓⍵}⌽⍳9
 
lol
 
ngn
my best is 5: -⌿↑⎕1 or -∘1@0
 
⎕1?
 
9:44 PM
@nathanrogers ⎕ 1
 
ngn
@nathanrogers it's stranding the evaluated input (⎕) and 1
 
@ngn what was being discussed when I posted the cmc
 
@rak1507 What should it do on an empty vector?
 
no, I don't get it
 
@nathanrogers a←⎕ ⋄ a 1
 
9:46 PM
@Adám ⍬≡f ⍬ is fine, I don't know what else it would do
 
ngn
@rak1507 many things. splitting on numeric lists? k9's ^? ..
 
@ngn or {x-~<x?x} maybe?
 
pick one of the many things, if it works, great, if it doesn't, try another one of the many things
 
@rak1507 Right, and that works for my solution. But ngn's two solutions fail.
 
oh, that's odd
 
9:46 PM
@nathanrogers What is?
 
how that expression works
 
@nathanrogers How so?
 
ngn
@rak1507 ⍷⍨ ?
 
bingo
 
I get it, but why wouldn't you just write it some other kind of way
{-⌿↑⍵1}⍳9
0 2 3 4 5 6 7 8 9
 
ngn
9:47 PM
ah, right ⊢-⍷⍨
 
⊢-⍷⍨ but yes
 
@nathanrogers Because using instead of saves 2 bytes from the {}
 
not if you count input
 
@nathanrogers What?
 
you have to input a valid argument
 
9:49 PM
So?
 
ngn
@rak1507 clever cmc
 
thanks
 
Indeed. That was a true puzzle.
 
so that's part of the input
 
I don't get what you're getting at.
 
9:50 PM
-⌿↑⎕1 this depends on what the user types in, it isn't a standalone solution is all I'm saying
 
generally in code golf either a function or full program is acceptable, so using ⎕ for input is
 
but it depends on the users input
 
@nathanrogers {…} also depends on the argument that the user gives.
 
I can't just run -⌿↑⎕1
a user has to interact with it
 
you can't just run ⊢-⍷⍨ either
 
9:52 PM
no but it is a function
 
you have to give it an input, either by ⎕ or by passing it as an argument
 
nah, one is dependent upon mutation
one isn't
 
@nathanrogers You can look at -⌿↑⎕1 as the body of a tradfn too. The header is irrelevant and not used or counted.
Alternatively, you could pipe -⌿↑⎕1 into the interpreter and it act as an interactive program.
 
it's just convention that a function or full program are acceptable
 
ngn
if we could do a full-text search for 1↑⍨≢ and suggest ⍷⍨ - imagine the number of thankyous!
 
9:53 PM
personally I do prefer a function solution though
 
Its cool and everything, I just don't think that it is a useful lesson to be learned from golfing
 
@ngn doubt it's that common
 
@ngn It isn't the same for higher-rank arrays.
 
ngn
@rak1507 i used it only a couple of days ago - for nathan's number spiral, i think
 
well, you're welcome :)
 
9:57 PM
CMC: Given argument, but with all elements replaced by 1s. : No literals.
 
=⍨?
 
Fails on nested arrays.
 
≡¨⍨
 
Yes. Too easy.
 
9:58 PM
just a slight modification of the well known =⍨
 
@nathanrogers Fails on non-scalars.
 
Now, do it in the most interesting fashion, while sticking to 3 bytes!
@nathanrogers Fails on non-scalars.
 
      {1}((1 2)(3(4 5(6 7))))
1
seems to work
 
> 1s
 
9:59 PM
{1} 1 2 3 4 5 doesn't
 

« first day (1503 days earlier)      last day (1150 days later) »