3 ms·
Just for fun, I tried it in Raku. say qx< cal -hy > # Command output as string .lines.skip.join("\n").split(/\n\n+/)
by elcaro 5y ago
Just for fun, I tried it in Raku.
say qx< cal -hy > # Command output as string
.lines.skip.join("\n").split(/\n\n+/) # Skip year & split groups
.map({ |([Z] .lines.join.comb(22).batch(3)) }) # Single column structure
.map({ |(.[2] ~ .[0].trim, |.[3 .. *]) }) # Month name on first row
.grep(*.trim.chars).join("\n") # Join non-blank lines
.subst(/\s+ ^^ \s\s+ 1»/, ' 1', :g) # Collapse weeks together
I was never going to beat APL... Though I imagine some clever Rakoons could probably find a few places where this can be golfed down.
- elcaro 5y agoThe first operation where I split to lines, then join, then split again... was annoying me. So now I've got this say qx< cal -hy >.lines.skip.batch(9) .map({ |([Z] .join.comb(22).batch(3)) }) .map({ |(.[2] ~ .[0].trim, |.[3 .. *]) }) .grep(*.trim.chars).join("\n") .subst(/\s+ ^^ \s\s+ 1»/, ' 1', :g)