« first day (2557 days earlier)      last day (90 days later) » 

1:00 PM
Welcome to APL Quest, 2023-4! Today's quest is Like a Version:
> Write a function that:
• takes 3-element integer vector left and right arguments each representing a major version, minor version, and build number.
• returns
> ⠀○ ¯1 if the left argument represents a version number older than the right argument
> ⠀○ ⠀0 if the left argument represents a version number equal to the right argument
> ⠀○ ⠀1 if the left argument represents a version number newer than the right argument
@user349784 Hi Segundo Neptali Orozco Sarango, if you want to participate here, please email access@apl.chat
 
I had ⊃⍤~∘0>-< and ⊃⍤~∘0×⍤-
 
⊃0~⍨∘×- for me
 
All nice.
(And you both made it on time!)
 
(very sleepily - 23:30 here)
 
All of these are essentially the same though. Any other approaches? Anyone did a bonus thing of allowing 1 2 3 'beta' etc.
 
1:04 PM
I originally had {a←×⍺-⍵⋄⊃(0≠a)/a} and was very pleased that I could figure out how to make it tacit (had to remember ~ for set-exclude)
 
I had ⊃0~⍨×⍤-, which is basically the same. Also tried to do it with grade: ≢ׯ1*</⍤⍋⍤,⍥⊂
⊃(⍋-⍒)⍤,⍥⊂ is probably nicer
 
Right, another extension is allowing arguments of unequal length, which your grade-based solution handles (in addition to betas etc.)
@rabbitgrowth I think, however, that (semi-)explicit is nicer for this: {⊃(⍋-⍒)⍺⍵}
Could also be (⊃⍋-⍒){⍺⍵} which we can then tacify as (⊃⍋-⍒),⍥⊂
 
The other approach I had was also using grade
{⍺≡⍵:0 ⋄ -/⍋⍺⍵}
 
That's nice, since you only need a single grade. There's another way to do that without the guard too.
 
ah, that wouild be nice
 
1:08 PM
Well, firstly, you could simply multiply by the (opposite) condition: {(⍺≢⍵)×-/⍋⍺⍵}
 
@Richard Ah, of course, -/. I totally overcomplicated it there
 
Can be made tacit too: ≢×-/⍤⍋⍤,⍥⊂
 
@Adám that is a hidden gard/condition:)
 
Yes, but doesn't cause branch mispredictions in the processor.
 
ok!
 
1:10 PM
However, the single-grade solution I had in mind, has no condition at all: {2-2⊃⍋⍺⍵⍺}
 
That is really clever.
 
Thanks. Does anyone feel like explaining how ×2⊥×⍤- works? :-)
@JonathanCarroll Here's a clever (imo) variant of that: (|⊃⍤/×)-
 
@Adám Converting the signed difference to a single digit
 
Sure, but that conversion is not in normal binary, since the "digits" can be ¯1 too!
 
yes, I am playing with it now :)
Each position of the 2-base is added or substracted depending on it's sign
 
1:22 PM
Works because 2*n is always one more than +/2*¯1+⍳n, so adding or subtracting 2*n is always enough to make the overall sum positive or negative?
 
Yes, you got it!
 
:)
 
A couple of people submitted this or similar in the Competition, and for judging, it took me a fair while to grok this one.
 
Three complete different approaches, very nice!
 
1:25 PM
@rabbitgrowth Ah yes. Although this one does allow for the extension to character elements and uneven lengths.
@Richard Indeed, so with that, I'll say, see you next week for 2023-5: Risky Business!
 
thanks all
 
@Adám too clever for me - I don't think I can unpack that... does this decompose as X f⍤g Y → f X g Y?
 
Yes, so the explicit form is {⊃(|⍺-⍵)/(×⍺-⍵)}
 
Looks like |⊃⍤/× is just a slightly more complicated way to write ⊃|/×, except that wouldn't work because / is weird.
 
@rabbitgrowth that's part of why I was/am confused - it's not a creating a derived function, right?
 
1:33 PM
If / were always a function, ⊃|/× would work, but / is also an operator, so ⊃|/× would get parsed as ⊃(|/)×, which is why you have to write |⊃⍤/×.
 

« first day (2557 days earlier)      last day (90 days later) »