Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Bounty Awarded with 200 reputation awarded by Adám
deleted 10 characters in body
Source Link
Bubbler
  • 79.3k
  • 5
  • 162
  • 484

APL (Dyalog Unicode), (削除) 73 (削除ここまで) 6967 bytes

{e×ばつ⍨⍳⍵⋄0= ̄2⊥⊃+e×ばつ⍨⍳⍵⋄0= ̄2⊥+/w=e×ばつ,w=e×ばつ(⍉↓r∘.+r∘r∘.×ばつ32+⍨32 8×ばつr)×ばつe×ばつ⍨⍳w}

Try it online! Try it online!

-46 bytes thanks to @ngn and @H.PWiz.

APL (Dyalog Unicode), (削除) 73 (削除ここまで) 69 bytes

{e×ばつ⍨⍳⍵⋄0= ̄2⊥⊃+/w=e×ばつ,(⍉↓r∘.+r∘.×ばつ32 8)×ばつe×ばつ⍨⍳w}

Try it online!

-4 bytes thanks to @ngn and @H.PWiz.

APL (Dyalog Unicode), (削除) 73 (削除ここまで) 67 bytes

{e×ばつ⍨⍳⍵⋄0= ̄2⊥+/w=e×ばつ(r∘.+⍨32 ×ばつr)×ばつe×ばつ⍨⍳w}

Try it online!

-6 bytes thanks to @ngn and @H.PWiz.

added 1 character in body
Source Link
Bubbler
  • 79.3k
  • 5
  • 162
  • 484

APL (Dyalog Unicode), (削除) 73 (削除ここまで) 7169 bytes

{e×ばつ⍨⍳⍵⋄0= ̄2⊥⊃+e×ばつ⍨⍳⍵⋄0= ̄2⊥⊃+/w=e×ばつ,(×ばつ32 8)×ばつe×ばつ⍨⍳w}

Try it online! Try it online!

-24 bytes thanks to @ngn and @H.PWiz.

f←{
 ⍝ Extract squarefree part of ⍵
 ×ばつ⍨⍳⍵
⍝ ×ばつ⍨⍳⍵ ⍝ Square of 1..⍵
⍝ ⍵|⍨ ⍝ Remainders of dividing ⍵ by each of the above
⍝ ⊃⌽⍒ ⍝ Last item of descending sort order; index of last 0
⍝ ×ばつ⍨ ⍝ Remove square term and name it w
 ⍝ 1 if odd, 2 if even; divide w by that
 w÷←e←2-2|ww÷←e←2∨we←2-2|we←2∨w2GCD minusof w modulowith 2; name it e
⍝ w÷← ⍝ Divide w by e and overwrite to w
 ⍝ Square of plus-minus range
 ×ばつ⍨⍳w
⍝ ×ばつ⍨⍳w ⍝ Square of 1..w
⍝ r←0,2/ ⍝ Make two copies of each number, prepend 0 and name it r
 ⍝ y2+32z2 (A/C) and y2+8z2 (B/D), with y and z swapped
 m←∘.(32 8⊥ ̈∘⊂,)⍨r
⍝ ∘.( )⍨r ⍝ Self outer product of r by...
⍝ , ⍝ Concatenate two input numbers and
 32 8⊥ ̈∘⊂ ⍝ Interpret as base-32 and base-8
⍝ m← ⍝ Name it m
 ⍝ Add ×ばつe×ばつx2
 ×ばつe×ばつr
⍝ ×ばつe×ばつr ⍝ Outer product by + with ×ばつe×ばつx2
⍝ m←, ⍝ Flatten and overwrite m
 ⍝ count w in m and check if B/D is twice A/C
 0= ̄2⊥⊃+/w=m
⍝ w=m ⍝ Test for each sum being w
⍝ ⊃+/ ⍝ Count of 'w's in A/C and B/D
⍝ ̄2⊥ ⍝ ( ×ばつA/C) + B/D
⍝ 0= ⍝ Equals 0?
}

APL (Dyalog Unicode), (削除) 73 (削除ここまで) 71 bytes

{e×ばつ⍨⍳⍵⋄0= ̄2⊥⊃+/w=e×ばつ,(×ばつ32 8)×ばつe×ばつ⍨⍳w}

Try it online!

-2 bytes thanks to @ngn.

f←{
 ⍝ Extract squarefree part of ⍵
 ×ばつ⍨⍳⍵
⍝ ×ばつ⍨⍳⍵ ⍝ Square of 1..⍵
⍝ ⍵|⍨ ⍝ Remainders of dividing ⍵ by each of the above
⍝ ⊃⌽⍒ ⍝ Last item of descending sort order; index of last 0
⍝ ×ばつ⍨ ⍝ Remove square term and name it w
 ⍝ 1 if odd, 2 if even; divide w by that
 w÷←e←2-2|we←2-2|w2 minus w modulo 2; name it e
⍝ w÷← ⍝ Divide w by e and overwrite to w
 ⍝ Square of plus-minus range
 ×ばつ⍨⍳w
⍝ ×ばつ⍨⍳w ⍝ Square of 1..w
⍝ r←0,2/ ⍝ Make two copies of each number, prepend 0 and name it r
 ⍝ y2+32z2 (A/C) and y2+8z2 (B/D), with y and z swapped
 m←∘.(32 8⊥ ̈∘⊂,)⍨r
⍝ ∘.( )⍨r ⍝ Self outer product of r by...
⍝ , ⍝ Concatenate two input numbers and
 32 8⊥ ̈∘⊂ ⍝ Interpret as base-32 and base-8
⍝ m← ⍝ Name it m
 ⍝ Add ×ばつe×ばつx2
 ×ばつe×ばつr
⍝ ×ばつe×ばつr ⍝ Outer product by + with ×ばつe×ばつx2
⍝ m←, ⍝ Flatten and overwrite m
 ⍝ count w in m and check if B/D is twice A/C
 0= ̄2⊥⊃+/w=m
⍝ w=m ⍝ Test for each sum being w
⍝ ⊃+/ ⍝ Count of 'w's in A/C and B/D
⍝ ̄2⊥ ⍝ ( ×ばつA/C) + B/D
⍝ 0= ⍝ Equals 0?
}

APL (Dyalog Unicode), (削除) 73 (削除ここまで) 69 bytes

{e×ばつ⍨⍳⍵⋄0= ̄2⊥⊃+/w=e×ばつ,(×ばつ32 8)×ばつe×ばつ⍨⍳w}

Try it online!

-4 bytes thanks to @ngn and @H.PWiz.

f←{
 ⍝ Extract squarefree part of ⍵
 ×ばつ⍨⍳⍵
⍝ ×ばつ⍨⍳⍵ ⍝ Square of 1..⍵
⍝ ⍵|⍨ ⍝ Remainders of dividing ⍵ by each of the above
⍝ ⊃⌽⍒ ⍝ Last item of descending sort order; index of last 0
⍝ ×ばつ⍨ ⍝ Remove square term and name it w
 ⍝ 1 if odd, 2 if even; divide w by that
 w÷←e←2∨we←2∨wGCD of w with 2; name it e
⍝ w÷← ⍝ Divide w by e and overwrite to w
 ⍝ Square of plus-minus range
 ×ばつ⍨⍳w
⍝ ×ばつ⍨⍳w ⍝ Square of 1..w
⍝ r←0,2/ ⍝ Make two copies of each number, prepend 0 and name it r
 ⍝ y2+32z2 (A/C) and y2+8z2 (B/D), with y and z swapped
 m←∘.(32 8⊥ ̈∘⊂,)⍨r
⍝ ∘.( )⍨r ⍝ Self outer product of r by...
⍝ , ⍝ Concatenate two input numbers and
 32 8⊥ ̈∘⊂ ⍝ Interpret as base-32 and base-8
⍝ m← ⍝ Name it m
 ⍝ Add ×ばつe×ばつx2
 ×ばつe×ばつr
⍝ ×ばつe×ばつr ⍝ Outer product by + with ×ばつe×ばつx2
⍝ m←, ⍝ Flatten and overwrite m
 ⍝ count w in m and check if B/D is twice A/C
 0= ̄2⊥⊃+/w=m
⍝ w=m ⍝ Test for each sum being w
⍝ ⊃+/ ⍝ Count of 'w's in A/C and B/D
⍝ ̄2⊥ ⍝ ( ×ばつA/C) + B/D
⍝ 0= ⍝ Equals 0?
}
deleted 4 characters in body
Source Link
Bubbler
  • 79.3k
  • 5
  • 162
  • 484

APL (Dyalog Unicode), (削除) 73 (削除ここまで) 7271 bytes

{e×ばつ⍨⍳⍵⋄0= ̄2⊥⊃+/w=e×ばつ,(⍉↓r∘.(32×ばつ32 8⊥ ̈∘⊂,)⍨r8)×ばつe×ばつ⍨⍳w}

Try it online! Try it online!

-1 byte2 bytes thanks to @ngn.

APL (Dyalog Unicode), (削除) 73 (削除ここまで) 72 bytes

{e×ばつ⍨⍳⍵⋄0= ̄2⊥⊃+/w=e×ばつ,(.(32 8⊥ ̈∘⊂,)⍨r)×ばつe×ばつ⍨⍳w}

Try it online!

-1 byte thanks to @ngn.

APL (Dyalog Unicode), (削除) 73 (削除ここまで) 71 bytes

{e×ばつ⍨⍳⍵⋄0= ̄2⊥⊃+/w=e×ばつ,(⍉↓r∘.×ばつ32 8)×ばつe×ばつ⍨⍳w}

Try it online!

-2 bytes thanks to @ngn.

deleted 56 characters in body
Source Link
Bubbler
  • 79.3k
  • 5
  • 162
  • 484
Loading
added 37 characters in body
Source Link
Bubbler
  • 79.3k
  • 5
  • 162
  • 484
Loading
Source Link
Bubbler
  • 79.3k
  • 5
  • 162
  • 484
Loading

AltStyle によって変換されたページ (->オリジナル) /