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

#dc, 10 - 25 = -15

dc, 10 - 25 = -15

2?A*Ar^1-n

Takes a blank line for "no input".

Calculates 10 ^ (10 * n) - 1, where n is the input, or 2 if input is empty. Prints a string of 9s of the required length.

  • 2 push 2 to the stack in case input is empty
  • ? push input to the stack
  • A push 10 to the stack (dc has shortcuts A-F for 10 - 15)
  • * pop twice and multiply (multiply input by 10)
  • A push 10 to the stack
  • r reverse top two stack elements
  • ^ exponentiate 10 ^ (10 * input)
  • 1- subtract 1 from the top of stack
  • n print with no newline.

#dc, 10 - 25 = -15

2?A*Ar^1-n

Takes a blank line for "no input".

Calculates 10 ^ (10 * n) - 1, where n is the input, or 2 if input is empty. Prints a string of 9s of the required length.

  • 2 push 2 to the stack in case input is empty
  • ? push input to the stack
  • A push 10 to the stack (dc has shortcuts A-F for 10 - 15)
  • * pop twice and multiply (multiply input by 10)
  • A push 10 to the stack
  • r reverse top two stack elements
  • ^ exponentiate 10 ^ (10 * input)
  • 1- subtract 1 from the top of stack
  • n print with no newline.

dc, 10 - 25 = -15

2?A*Ar^1-n

Takes a blank line for "no input".

Calculates 10 ^ (10 * n) - 1, where n is the input, or 2 if input is empty. Prints a string of 9s of the required length.

  • 2 push 2 to the stack in case input is empty
  • ? push input to the stack
  • A push 10 to the stack (dc has shortcuts A-F for 10 - 15)
  • * pop twice and multiply (multiply input by 10)
  • A push 10 to the stack
  • r reverse top two stack elements
  • ^ exponentiate 10 ^ (10 * input)
  • 1- subtract 1 from the top of stack
  • n print with no newline.
added 506 characters in body
Source Link
Digital Trauma
  • 73.7k
  • 10
  • 116
  • 268

#dc, 10 - 25 = -15

2?A*Ar^1-pn

Takes a blank line for "no input".

Calculates 10 ^ (10 * n) - 1, where n is the input, or 2 if input is empty. Prints a string of 9s of the required length.

  • 2 push 2 to the stack in case input is empty
  • ? push input to the stack
  • A push 10 to the stack (dc has shortcuts A-F for 10 - 15)
  • * pop twice and multiply (multiply input by 10)
  • A push 10 to the stack
  • r reverse top two stack elements
  • ^ exponentiate 10 ^ (10 * input)
  • 1- subtract 1 from the top of stack
  • n print with no newline.

#dc, 10 - 25 = -15

2?A*Ar^1-p

Takes a blank line for "no input".

#dc, 10 - 25 = -15

2?A*Ar^1-n

Takes a blank line for "no input".

Calculates 10 ^ (10 * n) - 1, where n is the input, or 2 if input is empty. Prints a string of 9s of the required length.

  • 2 push 2 to the stack in case input is empty
  • ? push input to the stack
  • A push 10 to the stack (dc has shortcuts A-F for 10 - 15)
  • * pop twice and multiply (multiply input by 10)
  • A push 10 to the stack
  • r reverse top two stack elements
  • ^ exponentiate 10 ^ (10 * input)
  • 1- subtract 1 from the top of stack
  • n print with no newline.
Source Link
Digital Trauma
  • 73.7k
  • 10
  • 116
  • 268

#dc, 10 - 25 = -15

2?A*Ar^1-p

Takes a blank line for "no input".

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