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

Commonmark migration
Source Link

###Explanation

Explanation

###Explanation

Explanation

added 220 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382

Try it online! Or see a graphical display (takes a while; times out for inputs exceeding approximately 60).

Try it online! Or see a graphical display (takes a while; times out for inputs exceeding approximately 60).

added 1625 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382

###Explanation

l % Push 1. This is the array that holds the sequence, initialized to
 % a single term. Will be extended with subsequent terms
XH % Copy into clipboard H, which holds the latest result of the 
 % "accumulated" square root
iq:" % Input n. Do the following n-1 times
 ` % Do...while
 @ % Push interaton index k, starting at 1. This is the candidate
 % to being the next term of the sequence
 y % Push copy of array of terms found so far
 m % Ismbmer? True if k is in the array
 H % Push accumulated root
 @+ % Add k
 X^ % Square root
 1\ % Modulo 1. This gives 0 if k gives an integer square root
 + % Add. Gives nonzero if k is in the array or doesn't give an
 % integer square root; that is, if k is invalid.
 % The body of the do...while loop ends here. If the top of the
 % stack is nonzero a new iteration will be run. If it is zero that
 % means that the current k is a new term of the sequence
 } % Finally: this is executed after the last iteration, right before
 % the loop is exited
 8M % Push latest result of the square root
 XH % Copy in clipboard K
 x % Delete
 @ % Push current k
 h % Append to the array
 % End do...while (implicit)
 % Display (implicit)

###Explanation

l % Push 1. This is the array that holds the sequence, initialized to
 % a single term. Will be extended with subsequent terms
XH % Copy into clipboard H, which holds the latest result of the 
 % "accumulated" square root
iq:" % Input n. Do the following n-1 times
 ` % Do...while
 @ % Push interaton index k, starting at 1. This is the candidate
 % to being the next term of the sequence
 y % Push copy of array of terms found so far
 m % Ismbmer? True if k is in the array
 H % Push accumulated root
 @+ % Add k
 X^ % Square root
 1\ % Modulo 1. This gives 0 if k gives an integer square root
 + % Add. Gives nonzero if k is in the array or doesn't give an
 % integer square root; that is, if k is invalid.
 % The body of the do...while loop ends here. If the top of the
 % stack is nonzero a new iteration will be run. If it is zero that
 % means that the current k is a new term of the sequence
 } % Finally: this is executed after the last iteration, right before
 % the loop is exited
 8M % Push latest result of the square root
 XH % Copy in clipboard K
 x % Delete
 @ % Push current k
 h % Append to the array
 % End do...while (implicit)
 % Display (implicit)
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382
Loading

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