« first day (2529 days earlier)      last day (120 days later) » 

2:36 AM
@Adám this is really cool, thanks for making it!
 
 
8 hours later…
10:29 AM
@JonathanCarroll You're welcome. People have been asking for larger examples than one-liners, so that's at least one.
 
 
2 hours later…
12:59 PM
@user23170030 If you want to participate here, please email access@apl.chat
Welcome to the 100th APL Quest, 2022-10! Today's quest is Separation Anxiety:
> Write a function that:
• takes a right argument that is a character vector or scalar representing a valid non-negative integer.
• takes a left argument that is a character scalar "separator" character.
• returns a character vector that is a representation of the right argument formatted such that the separator character is found between trailing groups of 3 digits.
 
Did not do my homework. Can show my old input form the competition.
Am working now ifor something with
{⊂⍵}⌺(⍪3 3)
 
I have the very ugly {∊⍺∘,¨@(1~⍨⍸0=3|⊖⍳≢⍵),⍵}
 
That's pretty clever, imo. Nice way to avoid a leading separator.
 
the old one:
{ ⌽((⌊(1-⍨≢⍵)÷3)+≢⍵)⍴,⍺,⍨ (≢⍵) 3⍴⌽⍵}
 
I like that, but since you anyway compute the proper length, why not use that in the original reshape, instead of the way too large (≢⍵) 3⍴?
I had a somewhat similar, very traditional {⍺@{m}⍵\⍨~m←⌽0 0 0 1⍴⍨¯1+⌈4×3÷⍨≢⍵}
Did anyone go for a quite simple regex-based solution?
 
1:07 PM
I did...
{'(?<=\d)(?=(\d\d\d)+(?!\d))'⎕R ⍺⊢⍵}
 
Whoa, that doesn't seem very simple at first glance.
 
My truly ugly solution, leveraging non-boolean partition:
{x←(1,⌽2×0=3|⍳(1-⍨≢⍵))⊂⍵ ⋄ ((0=≢¨x)/x)←⍺ ⋄⊃,/x}
and my somewhat nicer, but still relatively ugly
{⊃,/⍺@(0=≢¨)(1,⌽2×0=3|⍳(1-⍨≢⍵))⊂⍵}
 
@JonathanCarroll Can you explain? I don't get it.
My regex-solution was {⌽'...(?!$)'⎕R'&'⍺⌽⍵}
 
The regex: it looks for a digit followed by 3 digits, followed by a non-digit, but since the last of those is a negative-lookahead, it starts from the end and works backwards
 
I didn't know that.
Should we do a performance comparison?
 
1:12 PM
I wanted to do that, but couldn't figure out how to pass in strings to cmpx - I suspect I'm missing something simple
 
can something usefull been done with {⊂⍵}⌺(⍪3 3)⌽ ?
If it can split it in groups of 3 than only the seperator has to be put between them
 
I had (3|3-≢⍤⊢)↓∘⌽1↓∘∊,∘(⌽⍴⍨3,⍨∘⌈3÷⍨≢)
Feels like a lot of 3's
 
<3 Hm, some of these seem to take a while to run…
      n←1e6⍴'4'
      'cmpx'⎕cy'dfns'
      RV←{∊⍺∘,¨@(1~⍨⍸0=3|⊖⍳≢⍵),⍵}
      RS←{ ⌽((⌊(1-⍨≢⍵)÷3)+≢⍵)⍴,⍺,⍨ (≢⍵) 3⍴⌽⍵}
      JC1←{'(?<=\d)(?=(\d\d\d)+(?!\d))'⎕R ⍺⊢⍵}
      JC2←{x←(1,⌽2×0=3|⍳(1-⍨≢⍵))⊂⍵ ⋄ ((0=≢¨x)/x)←⍺ ⋄⊃,/x}
      JC3←{⊃,/⍺@(0=≢¨)(1,⌽2×0=3|⍳(1-⍨≢⍵))⊂⍵}
      AB1←{⍺@{m}⍵\⍨~m←⌽0 0 0 1⍴⍨¯1+⌈4×3÷⍨≢⍵}
      AB2←{⌽'...(?!$)'⎕R'&'⍺⌽⍵}
      RG←(3|3-≢⍤⊢)↓∘⌽1↓∘∊,∘(⌽⍴⍨3,⍨∘⌈3÷⍨≢)
      s←','
      n←1e3⍴'4'
      cmpx 's '∘,¨(⎕A⎕NL¯3),¨⊂' n'
  s AB1 n → 3.9E¯6 |       0%
  s AB2 n → 1.1E¯4 |   +2800%
  s JC1 n → 2.1E¯2 | +529400% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  s JC2 n → 3.7E¯5 |    +850%
  s JC3 n → 3.5E¯5 |    +800%
  s RG n  → 5.9E¯6 |     +50%
  s RS n  → 9.8E¯6 |    +150%
  s RV n  → 7.4E¯5 |   +1800%
We should probably disqualify JC1 :-P
      ⎕ex'JC1'
      cmpx 's '∘,¨(⎕A⎕NL¯3),¨⊂' n'
  s AB1 n → 4.9E¯6 |     0% ⎕⎕
  s AB2 n → 1.1E¯4 | +2137% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  s JC2 n → 3.4E¯5 |  +585% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  s JC3 n → 3.3E¯5 |  +570% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  s RG n  → 4.1E¯6 |   -17% ⎕
  s RS n  → 8.4E¯6 |   +69% ⎕⎕⎕
  s RV n  → 6.8E¯5 | +1267% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
@rabbitgrowth Well, many 3s pay off, apparently.
 
@Richard odd things seem to happen when 0=3|≢⍵
 
Yes i noticed. Ypu mean the spaces added?
 
1:20 PM
Yay :)
 
      cmpx 's AB1 n' 's RG n'
  s AB1 n → 4.6E¯6 |   0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  s RG n  → 4.1E¯6 | -11% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
 
@Adám Getting a solution at all took me hours... performance was not on my mind
@Richard it seems to drop the first digit... {⊂⍵}⌺(⍪3 3)⌽'123456'
 
Haha, a simple fix to @Richard's solution beats us all:
      RSx←{ ⌽((⌊(1-⍨≢⍵)÷3)+≢⍵)⍴,⍺,⍨ (⌈3÷⍨≢⍵) 3⍴⌽⍵}
      cmpx 's AB1 n' 's RG n' 's RSx n'
  s AB1 n → 4.6E¯6 |   0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  s RG n  → 4.0E¯6 | -13% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  s RSx n → 3.7E¯6 | -19% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
So, the morale of today: Stay flat.
 
more like the morale of every week :)
 
True. Some extremists even think it was a mistake to allow nested arrays, as the lack of those forced people to construct (flat) array-based solutions.
 
1:24 PM
@Adám and ≢⍵ is used three times, so l←≢⍵ and using that at the other places is probably even faster
 
I'd expect it to be negligible. The length of an array is directly readable from its memory pocket.
 
:)
 
      RSx2←{ ⌽((⌊(l-1)÷3)+l)⍴,⍺,⍨ (⌈3÷⍨l←≢⍵) 3⍴⌽⍵}
      cmpx 's RSx n' 's RSx2 n'
  s RSx n  → 3.7E¯6 |  0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  s RSx2 n → 3.8E¯6 | +2% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
 
@JonathanCarroll yes, very strange!
 
It might even be that modifying the symbol table takes more time than the look-ups saved.
Anyway, I think we're done here.
 
1:27 PM
@Adám what is happening with stencil above?
See @JonathanCarroll example
 
Stencil creates a window, centred on every element in turn. So the first element needs padding on the left ot have consistent length. The left argument to the operand function contains info about this, so you can do {⊂⍺↓⍵}⌺ to avoid padding.
See you next week for the beginning of the last "season", with Elimination Sort.
 
@Adám That still appears to drop the first digit when the length is modulo 3
 
{⊂⍺↓⍵}⌺(⍪3 3)⊢'123456'
 
 
3 hours later…
4:10 PM
      f←(3|3-≢⍤⊢)↓∘⌽1↓∘∊,∘(⌽⍴⍨3,⍨∘⌈3÷⍨≢)
      g←{(3|3-≢⍵)↓⌽1↓∊⍺,(⌈3÷⍨≢⍵)3⍴⌽⍵}
      cmpx's f n' 's g n'
  s f n → 4.7E¯6 |  0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  s g n → 4.3E¯6 | -9% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
Looks like there's not much point in going tacit here; it's slower and the s are just noise
I guess {⌽(-3|3-≢⍵)↓1↓∊⍺,(⌈3÷⍨≢⍵)3⍴⌽⍵} is slightly faster because you're reversing less at the end
      h←{⌽(-3|3-≢⍵)↓1↓∊⍺,(⌈3÷⍨≢⍵)3⍴⌽⍵}
      cmpx's f n' 's g n' 's h n'
  s f n → 4.7E¯6 |   0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  s g n → 4.3E¯6 |  -9% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  s h n → 4.3E¯6 | -10% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
 
Tbw
5:10 PM
Is there any clean way to apply At with each of an array right operand and a fixed function left on a input right argument?
Best I have right now is something like {(⍵{¯1∘⌽@⍵⊢⍺}⊢)¨(defining large array)}
 

« first day (2529 days earlier)      last day (120 days later) »