4 ms·
I attempted to run that APL, and it didn't quite work as is on my system (Dyalog on macOS). As written, it seems to be an odd mixture of things that assume ⎕IO
by markjreed 5y ago
I attempted to run that APL, and it didn't quite work as is on my system (Dyalog on macOS). As written, it seems to be an odd mixture of things that assume ⎕IO 0 and ⎕IO 1, in that with ⎕IO←1, the bymonth assignment only gets two columns instead of three, but with ⎕IO←0, it needs to be 0=22 and 1↓cal instead of 0=23 and 2↓cal.
Similarly, the lines assignment needed to be {⍵⊂⍨0=9|⍳≢⍵}⍤1⍉bymonth.
After those changes it worked OMM, but the month names were appended directly to the end of the first Saturday's date with no space (e.g. "1 2January"). So I changed ↑months to ↑(' ',¨months) in the last line to insert a space there (there's likely a better way to do that; I'm still pretty new at APL).
I added `-h` to make sure `cal` didn't highlight today's date, which can throw things off, and eliminated intermediate vars that were only used once; this was what I wound up with (works from a clean ws in Dyalog OMM):
⎕io ← 0
lines ← {⍵⊂⍨0=9|⍳≢⍵}⍤1⍉{⍵⊂⍨0=22|⍳≢⍵}⍤1↑1↓⎕sh 'cal -hy'
months ← ~∘' '¨,⍉⊃¨lines
days ← ∊⍤1⍉{⍵/⍨(' '∨.≠¨⍵)∨∧\' '∧.=¨⍵}⍤1⍉¯1↓(23⍴1 0 0)⊂⍤1↑⊃,/,⌿2↓¨lines
⎕←53↑(¯2↓⍤1⊢days) , ↑(' ',¨months)\⍨∨/' 1 '⍷days
- rak1507 5y agoIt (should be) purely ⎕IO←0. https://tio.run/##jZK7SgNBFIb7fYrTbQKbyyYINum1srBNM27G7OLemJ1ogpdCISTBFUMQbAQJQrZLoWIp7KOcF4ln9tJ432ZmDpzz/f9/loVurTdibtDfbPDmbncPx7dNzWIu0AWosr8DunrWRjr89WH8AH0uIRjIcEDHIahOK/A85ve0g5EX@NLOBp9i/IqzS4yTZqfVPsP4GadLqp1j/GTieN7C8UL1/gAJmZCOdAIfHF8GkM/ti2AQRprr@Dz6Atn@zIinpZ5/Qix74B9FdAfOLBsURssG5LALnNzroKeJQaNxdpUmuZDf0@JDKZglCwc@86iDsgLBveCYQxQyi0daj41ySKXVxvjFhCY0q5mzLCyiGQ0Dr99Vaj9xv3GkxmpSOJ7He/m6J7MiGxVdg4KrkCWcJHWcPqYJ1ar0wMmqm5VX9U5WLANN16RmkYslWuGBD8lCVFqhP4pIW22SXUnXSnDWPFsWOqpgkJR5HmyXFBCwoYNJvPit1FrYYWHIKatiCWpFzKUCE3Bic8FB2hxMylNwIws1FGR7s/kA https://tio.run/##jZK7SgNBFIb7fYrTbQKbyyYINum1srBNM27G7OLemJ... Potentially cal -y on macOS produces a different shape? What's ⍴↑cal? Try doing cal←⎕SE.UCMD'Calendar 2021' and replace ↑2↓cal with 1↓cal - potentially that'll work?
- markjreed 5y ago⍴↑⎕sh 'cal -y' is 36 66. ⍴⎕SE.UCMD'Calendar 2021' is 33 66. Hm. What system are you on? On Ubuntu, cal -y | wc -l also gives me 36.
- rak1507 5y agoI was just testing with TIO, it looks like the version of `cal` on there is different to the common one. The ⎕SE.UCMD'Calendar 2021' version should work cross platform (as it doesn't rely on anything external).