≈đG←
Attempt This Online!
Takes input as two pairs of numbers, e.g. [-8,5] [0,5]
.
≈đG←
≈ Absolute difference (vectorized)
đ Unpair; get the two elements of a pair
G GCD
← Decrement
I wonder how an approach that defines the solution to be an integer point on the line, and using -n
for the final result. (I haven't really tried to learn Nekomata yet and somehow doubt it would be shorter for this problem, but seems interesting) – noodle man
The shortest I can get using this approach is 10 bytes:
≈:Ṁᵉ{~Z*}¦
Attempt This Online!
≈:Ṁᵉ{~Z*}¦ Take [-8,5] [0,5] as an example
≈ Absolute difference (vectorized)
[-8,5] [0,5] -> [8,0]
: Duplicate
[8,0] -> [8,0] [8,0]
Ṁ Maximum
[8,0] [8,0] -> [8,0] 8
ᵉ{ Apply the following block and then push the original top of stack
~Z Choose any integer in [1,n)
[8,0] 8 -> [8,0] 1 or [8,0] 2 or ... or [8,0] 7
* Multiply
[8,0] 1 -> [8,0]
[8,0] 2 -> [16,0]
...
[8,0] 7 -> [56,0]
} End the block (ᵉ pushes the original top of stack)
[8,0] -> [8,0] 8
[16,0] -> [16,0] 8
...
[56,0] -> [56,0] 8
¦ Divide and check if the result is an integer
[8,0] 8 -> [1,0]
[16,0] 8 -> [2,0]
...
[56,0] 8 -> [7,0]
-n
counts the number of solutions, so the output is 7
.
(0,0),(1,1)
,(1,1),(8,24)
, some test cases that x0=x1:(0,0),(0,5)
\$\endgroup\$