Leap Years with GCD in various languages

I saw this deck via Haskell Weekly Recap which noted an interesting property: “x is a leap year if and only if gcd(80, x) > gcd(50, x)” (gcd = ‘greatest common divisor’) which I haven’t fully appreciated the origin of, but wanted to try some implementations. The …

Breaking down squared digits in (Dyalog) APL

I love small challenges as a way to learn a language. I spotted this one in the #rstats hashtag on Mastodon “square each digit of an integer (return integer), eg 9113 becomes 81119” and I just had to try it in APL. First, extract each of the digits using format {⍎¨⍕⍵}9113 9 1 1 3 then …

Breaking down fizzbuzz in (Dyalog) APL

The one-liner solution: {∊(3↑(0=3 5|⍵)∪1)/'Fizz' 'Buzz' ⍵}¨⍳20 The explanation: For each value in [1, 2, ..., 20], find the boolean mask of “is this divisible by 3 or 5?” (vectorized). {0=3 5|⍵}¨⍳20 ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐ │0 0│0 …