Skip to main content
added 1176 characters in body
Source Link

APL (Dyalog Extended), 70 bytes

Not great, but I felt like submitting it anyway

{⍺←⍬⋄{⍵÷⊃⌽⊃∩⍥(⍸0=⊢|⍨⍳)/|⍵}((W×⍎'0',⍺)-(⍎⍵)×⍎'1','0'\⍨⍴,⍺),W←⍎'9'\⍨⍴,⍵}

Not sure why, but my code to handle single arguments works in TryAPL.org but not in tio.run

Also, because of how APL handles default arguments, I had to swap the order on input...like I said, not the best solution :|

⍺←⍬⋄ ⍝ assign Empty Set to the default value for the left argument (Y from the problem statement)
 ⍵÷⊃⌽ ⍝ divide the 2-tuple (a and b from the problem statement) by their gcd
  ⊃ ⍝ pick (removes one layer of nesting)
   ∩ ⍝ intersection
    ⍥ ⍝ function composition operator (Over)
     (⍸0=⊢|⍨⍳)/ ⍝ fold/reduce by finding divisors
      |⍵ ⍝ absolute value of 2-tuple (a and b from the problem statement)
       W×⍎'0',⍺ ⍝ W (from problem statement) times the integer representation of the left argument (Y from the problem statement) or zero if alpha is the empty set
        -(⍎⍵) ⍝ subtract the integer representation of the right argument (X from the problem statement)
         ×⍎ ⍝ decode then multiply
          '1', ⍝ concatenate the character 1
           '0'\⍨⍴ ⍝ expand the character 0 by the number of characters in Y
             ,⍺ ⍝ ravel Y (effectively making single characters into singleton arrays)
              , ⍝ concatenate
                W←⍎'9'\⍨⍴ ⍝ assign the integer representation of the expansion of the character 9 by the number of characters in X
                 ,⍵ ⍝ ravel X

Try it online!

APL (Dyalog Extended), 70 bytes

Not great, but I felt like submitting it anyway

{⍺←⍬⋄{⍵÷⊃⌽⊃∩⍥(⍸0=⊢|⍨⍳)/|⍵}((W×⍎'0',⍺)-(⍎⍵)×⍎'1','0'\⍨⍴,⍺),W←⍎'9'\⍨⍴,⍵}

Not sure why, but my code to handle single arguments works in TryAPL.org but not in tio.run

Also, because of how APL handles default arguments, I had to swap the order on input...like I said, not the best solution :|

Try it online!

APL (Dyalog Extended), 70 bytes

Not great, but I felt like submitting it anyway

{⍺←⍬⋄{⍵÷⊃⌽⊃∩⍥(⍸0=⊢|⍨⍳)/|⍵}((W×⍎'0',⍺)-(⍎⍵)×⍎'1','0'\⍨⍴,⍺),W←⍎'9'\⍨⍴,⍵}

Not sure why, but my code to handle single arguments works in TryAPL.org but not in tio.run

Also, because of how APL handles default arguments, I had to swap the order on input...like I said, not the best solution :|

⍺←⍬⋄ ⍝ assign Empty Set to the default value for the left argument (Y from the problem statement)
 ⍵÷⊃⌽ ⍝ divide the 2-tuple (a and b from the problem statement) by their gcd
  ⊃ ⍝ pick (removes one layer of nesting)
   ∩ ⍝ intersection
    ⍥ ⍝ function composition operator (Over)
     (⍸0=⊢|⍨⍳)/ ⍝ fold/reduce by finding divisors
      |⍵ ⍝ absolute value of 2-tuple (a and b from the problem statement)
       W×⍎'0',⍺ ⍝ W (from problem statement) times the integer representation of the left argument (Y from the problem statement) or zero if alpha is the empty set
        -(⍎⍵) ⍝ subtract the integer representation of the right argument (X from the problem statement)
         ×⍎ ⍝ decode then multiply
          '1', ⍝ concatenate the character 1
           '0'\⍨⍴ ⍝ expand the character 0 by the number of characters in Y
             ,⍺ ⍝ ravel Y (effectively making single characters into singleton arrays)
              , ⍝ concatenate
                W←⍎'9'\⍨⍴ ⍝ assign the integer representation of the expansion of the character 9 by the number of characters in X
                 ,⍵ ⍝ ravel X

Try it online!

Source Link

APL (Dyalog Extended), 70 bytes

Not great, but I felt like submitting it anyway

{⍺←⍬⋄{⍵÷⊃⌽⊃∩⍥(⍸0=⊢|⍨⍳)/|⍵}((W×⍎'0',⍺)-(⍎⍵)×⍎'1','0'\⍨⍴,⍺),W←⍎'9'\⍨⍴,⍵}

Not sure why, but my code to handle single arguments works in TryAPL.org but not in tio.run

Also, because of how APL handles default arguments, I had to swap the order on input...like I said, not the best solution :|

Try it online!