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

added a commented version
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

JavaScript (ES6), 28 bytes

(a,b,c)=>c-2*b+a?c*c/b:2*c-b

Try it online!

Commented

(a, b, c) => // given the 3 integers,
c - 2 * b + a ? // if the sequence is not arithmetic:
 c * c / b // assume it's geometric and return the next geometric term
: // else:
 2 * c - b // return the next arithmetic term

JavaScript (ES6), 28 bytes

(a,b,c)=>c-2*b+a?c*c/b:2*c-b

Try it online!

JavaScript (ES6), 28 bytes

(a,b,c)=>c-2*b+a?c*c/b:2*c-b

Try it online!

Commented

(a, b, c) => // given the 3 integers,
c - 2 * b + a ? // if the sequence is not arithmetic:
 c * c / b // assume it's geometric and return the next geometric term
: // else:
 2 * c - b // return the next arithmetic term
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

JavaScript (ES6), 28 bytes

(a,b,c)=>c-2*b+a?c*c/b:2*c-b

Try it online!

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