| Bytes | Lang | Time | Link |
|---|---|---|---|
| 087 | Python 3 | 240930T074255Z | Lucenapo |
| 028 | APLDyalog Unicode | 240918T161407Z | akamayu |
| 039 | Charcoal | 240919T155240Z | Neil |
| 014 | Jelly | 240918T130840Z | Jonathan |
| 019 | 05AB1E | 240918T080738Z | Kevin Cr |
| 059 | JavaScript ES6 | 240917T223816Z | Arnauld |
Python 3, 87 bytes
import math
a=4;b=2
while 1:math.gcd(a,b)>1==print(f'{a-b}\n{b}');a+=b<3;b=[b,a][b<3]-1
Here, output is like
2
2
2
4
3
3
Python 3, 79 bytes
import math
a=4;b=2
while 1:math.gcd(a,b)>1==print(a-b,b);a+=b<3;b=[b,a][b<3]-1
Here, output is like
2 2
2 4
3 3
APL(Dyalog Unicode), 29 28 bytes SBCS
-1 byte by replacing () with an ¨ on ,¨∘⌽⍨∘⍸
Prints the first n pairs.
{⍵↑⊃,⌿,¨∘⌽⍨∘⍸¨1≠∨∘⌽⍨¨⍳¨⍳⍵+9}
Charcoal, 39 bytes
NθW‹Lυθ«→FΦ…²ⅈ⊙…²ⅈ¬∨﹪ⅈμ﹪κμ⊞⊞Oυκ⁻ⅈκ»I…υθ
Try it online! Link is to verbose version of code. Takes n as input and outputs the first n elements. Explanation:
Nθ
Input n.
W‹Lυθ«
Repeat until n elements have been found.
→
Increment i+j.
FΦ…²ⅈ⊙…²ⅈ¬∨﹪ⅈμ﹪κμ
Loop through all values of i from 2 to i+j exclusive, for each value looping again though the same range, checking to see whether both i and i+j are divisible by the same nontrivial factor.
⊞⊞Oυκ⁻ⅈκ
For those that have a common factor, push i and i+j-i=j to the list of found elements.
»I…υθ
Output the first n elements.
Jelly, 14 bytes
żṚṄ€g/Ḋ$¡€ṛŻ‘ß
A full program that prints the sequence values forever.
How?
żṚṄ€g/Ḋ$¡€ṛŻ‘ß - Main Link: no arguments (X = implicit integer zero)
Ṛ - reverse {X} (0 -> [0])
ż - {zip X} with {that}
€ - for each pair:
¡ - if...
$ - ...condition: last two links as a monad - f(pair):
/ - reduce by:
g - greatest common divisor
Ḋ - dequeue -> [2..that] (the first pass has pair [0,0] with GCD 0, so can't just decrement as -1 is truthy - but it saves a byte or two elsewhere)
Ṅ€ - ...then: print each on its own line
Ż - zero range (first pass -> [0]) / prefix with 0 (otherwise)
ṛ - get the right argument -> {that}
‘ - increment (vectorises)
ß - call this link again with X set to {that}
05AB1E, 19 bytes
∞εL¨Ryδ‚ʒ¿≠}εηíÆR€,
Port of @Arnauld's JavaScript answer, so make sure to upvote that answer as well!
Also outputs the infinite sequence on separated newlines.
Try it online.
Try it online with more readable format.
Explanation:
∞ # Push an infinite positive list: [1,2,3,...]
ε # Map each value to:
L # Convert it to a list in the range [1,value]
¨R # Remove the last item and reverse it: range (value,1]
δ # Map over each inner number
y ‚ # Pair it with the current value
ʒ # Filter this list of pairs by:
¿ # Check the pair's GCD (Greatest Common Divisor)
≠ # Check that this is NOT 1
}ε # After the filter: map over each pair [b,a]:
η # Get its prefixes: [[b],[b,a]]
í # Reverse each: [[b],[a,b]]
Æ # Reduce each by subtracting: [b,a-b]
R # Reverse the pair: [a-b,b]
€ # Map over both values:
, # Output it with trailing newline
JavaScript (ES6), 59 bytes
-13 thanks to @tsh!
Prints the sequence indefinitely.
for(a=b=c=1;;)a%c+b%c--||(c&&print(a-b+`
`+b),c=b=b-1||a++)