Skip to main content
24 -> 23
Source Link
noodle person
  • 10.3k
  • 1
  • 22
  • 76

GolfScript, 25 2424 23 bytes

{:i;0.0\{@@).2$?.i<-1$<}do@;@}

Try it online!Try it online!

I’m pretty sure this method is optimal, considering GolfScript doesn’t have floats and thus no min/max. It’s possible that there’s a shorter wayIt’s possible that there’s a shorter way to do the stack manipulation, but that seems pretty unlikely to me at this point. I stand corrected (by myself)—I was able to doget rid of the stack manipulation, but that seems pretty unlikely to me at this pointvariable i. Now I think this is optimal…but then I’ll probably find another 1-byte save somewhere else 😂

This is a block (function) taking N then P on the stack and leaving the two values on top of the stack.

Explanation:

Code Stack (bottom to top)
{…} Block 2 17
:i; Assign to i 2
0.0\ 2 0 017
{…}do Run until result is 0… Showing first pass over:
@@ Stack shift -117 2 0
) Increment -117 2 1
: Duplicate -117 2 1 1
2$ Push third from stack -117 2 1 1 2
? Exponentiate -117 2 1 2
: Duplicate -17 2 1 2 2
-1$ Push bottom of stack17 2 1 2 2 17
i<< Less than i? -1 2 1 2 0
(pop and either repeat or stop) -117 2 1 2

At the end of the loop, the stack looks like 017 1 4 9 16 2 5 25 so we do @;@ to make the top of the stack be 25 16.

It took like twenty minutes of fiddling around to get the stack manipulation to work right.

GolfScript, 25 24 bytes

{:i;0.{@@).2$?.i<}do@;@}

Try it online!

I’m pretty sure this method is optimal, considering GolfScript doesn’t have floats and thus no min/max. It’s possible that there’s a shorter way to do the stack manipulation, but that seems pretty unlikely to me at this point.

This is a block (function) taking N then P on the stack and leaving the two values on top of the stack.

Explanation:

Code Stack (bottom to top)
{…} Block 2 17
:i; Assign to i 2
0. 2 0 0
{…}do Run until result is 0… Showing first pass over:
@@ Stack shift -1 2 0
) Increment -1 2 1
: Duplicate -1 2 1 1
2$ Push third from stack -1 2 1 1 2
? Exponentiate -1 2 1 2
: Duplicate -1 2 1 2 2
i< Less than i? -1 2 1 2 0
(pop and either repeat or stop) -1 2 1 2

At the end of the loop, the stack looks like 0 1 4 9 16 2 5 25 so we do @;@ to make the top of the stack be 25 16.

It took like twenty minutes of fiddling around to get the stack manipulation to work right.

GolfScript, 25 24 23 bytes

{0\{@@).2$?.-1$<}do@;@}

Try it online!

I’m pretty sure this method is optimal, considering GolfScript doesn’t have floats and thus no min/max. It’s possible that there’s a shorter way to do the stack manipulation, but that seems pretty unlikely to me at this point. I stand corrected (by myself)—I was able to get rid of the variable i. Now I think this is optimal…but then I’ll probably find another 1-byte save somewhere else 😂

This is a block (function) taking N then P on the stack and leaving the two values on top of the stack.

Explanation:

Code Stack (bottom to top)
{…} Block 2 17
0\ 2 0 17
{…}do Run until result is 0… Showing first pass over:
@@ Stack shift 17 2 0
) Increment 17 2 1
: Duplicate 17 2 1 1
2$ Push third from stack 17 2 1 1 2
? Exponentiate 17 2 1 2
: Duplicate 17 2 1 2 2
-1$ Push bottom of stack17 2 1 2 2 17
< Less than? -1 2 1 2 0
(pop and either repeat or stop) 17 2 1 2

At the end of the loop, the stack looks like 17 1 4 9 16 2 5 25 so we do @;@ to make the top of the stack be 25 16.

It took like twenty minutes of fiddling around to get the stack manipulation to work right.

typo
Source Link
noodle person
  • 10.3k
  • 1
  • 22
  • 76

GolfScript, 25 24 bytes

{:i;0.{@@).2$?.i<}do@;@}

Try it online!

I’m pretty sure this method is optimal, considering GolfScript doesn’t have floats and thus no min/max. It’s possible that there’s a shorter way to do the stack manipulation, but that seems pretty unlikely to me at this point.

This is a block (function) taking N then P on the stack and leaving the two values on top of the stack.

Explanation:

Code Stack (bottom to top)
{…} Block 2 17
:i; Assign to i 2
0. 2 0 0
{…}do Run until result is 0… Showing first pass over:
@@ Stack shift -1 2 0
) Increment -1 2 1
: Duplicate -1 2 1 1
2$ Push third from stack -1 2 1 1 2
? Exponentiate -1 2 1 2
: Duplicate -1 2 1 2 2
i< Less than i? -1 2 1 2 0
(pop and either repeat or stop) -1 2 1 2

At the end of the loop, the stack looks like -10 1 4 9 16 2 5 25 so we do @;@ to make the top of the stack be 25 16.

It took like twenty minutes of fiddling around to get the stack manipulation to work right.

GolfScript, 25 24 bytes

{:i;0.{@@).2$?.i<}do@;@}

Try it online!

I’m pretty sure this method is optimal, considering GolfScript doesn’t have floats and thus no min/max. It’s possible that there’s a shorter way to do the stack manipulation, but that seems pretty unlikely to me at this point.

This is a block (function) taking N then P on the stack and leaving the two values on top of the stack.

Explanation:

Code Stack (bottom to top)
{…} Block 2 17
:i; Assign to i 2
0. 2 0 0
{…}do Run until result is 0… Showing first pass over:
@@ Stack shift -1 2 0
) Increment -1 2 1
: Duplicate -1 2 1 1
2$ Push third from stack -1 2 1 1 2
? Exponentiate -1 2 1 2
: Duplicate -1 2 1 2 2
i< Less than i? -1 2 1 2 0
(pop and either repeat or stop) -1 2 1 2

At the end of the loop, the stack looks like -1 1 4 9 16 2 5 25 so we do @;@ to make the top of the stack be 25 16.

It took like twenty minutes of fiddling around to get the stack manipulation to work right.

GolfScript, 25 24 bytes

{:i;0.{@@).2$?.i<}do@;@}

Try it online!

I’m pretty sure this method is optimal, considering GolfScript doesn’t have floats and thus no min/max. It’s possible that there’s a shorter way to do the stack manipulation, but that seems pretty unlikely to me at this point.

This is a block (function) taking N then P on the stack and leaving the two values on top of the stack.

Explanation:

Code Stack (bottom to top)
{…} Block 2 17
:i; Assign to i 2
0. 2 0 0
{…}do Run until result is 0… Showing first pass over:
@@ Stack shift -1 2 0
) Increment -1 2 1
: Duplicate -1 2 1 1
2$ Push third from stack -1 2 1 1 2
? Exponentiate -1 2 1 2
: Duplicate -1 2 1 2 2
i< Less than i? -1 2 1 2 0
(pop and either repeat or stop) -1 2 1 2

At the end of the loop, the stack looks like 0 1 4 9 16 2 5 25 so we do @;@ to make the top of the stack be 25 16.

It took like twenty minutes of fiddling around to get the stack manipulation to work right.

added 230 characters in body
Source Link
noodle person
  • 10.3k
  • 1
  • 22
  • 76

GolfScript, 25 24 bytes

{:i;0.{@@).2$?.i<}do@;@}

Try it online!

BlockI’m pretty sure this method is optimal, considering GolfScript doesn’t have floats and thus no min/max. It’s possible that there’s a shorter way to do the stack manipulation, but that seems pretty unlikely to me at this point.

This is a block (function) taking N then P on the stack and leaving the two values on top of the stack.

Explanation:

Code Stack (bottom to top)
{…} Block 2 17
:i; Assign to i 2
0. 2 0 0
{…}do Run until result is 0… Showing first pass over:
@@ Stack shift -1 2 0
) Increment -1 2 1
: Duplicate -1 2 1 1
2$ Push third from stack -1 2 1 1 2
? Exponentiate -1 2 1 2
: Duplicate -1 2 1 2 2
i< Less than i? -1 2 1 2 0
(pop and either repeat or stop) -1 2 1 2

At the end of the loop, the stack looks like -1 1 4 9 16 2 5 25 so we do @;@ to make the top of the stack be 25 16.

It took like twenty minutes of fiddling around to get the stack manipulation to work right.

GolfScript, 25 24 bytes

{:i;0.{@@).2$?.i<}do@;@}

Try it online!

Block (function) leaving the two values on top of the stack.

Explanation:

Code Stack (bottom to top)
{…} Block 2 17
:i; Assign to i 2
0. 2 0 0
{…}do Run until result is 0… Showing first pass over:
@@ Stack shift -1 2 0
) Increment -1 2 1
: Duplicate -1 2 1 1
2$ Push third from stack -1 2 1 1 2
? Exponentiate -1 2 1 2
: Duplicate -1 2 1 2 2
i< Less than i? -1 2 1 2 0
(pop and either repeat or stop) -1 2 1 2

At the end of the loop, the stack looks like -1 1 4 9 16 2 5 25 so we do @;@ to make the top of the stack be 25 16.

It took like twenty minutes of fiddling around to get the stack manipulation to work right.

GolfScript, 25 24 bytes

{:i;0.{@@).2$?.i<}do@;@}

Try it online!

I’m pretty sure this method is optimal, considering GolfScript doesn’t have floats and thus no min/max. It’s possible that there’s a shorter way to do the stack manipulation, but that seems pretty unlikely to me at this point.

This is a block (function) taking N then P on the stack and leaving the two values on top of the stack.

Explanation:

Code Stack (bottom to top)
{…} Block 2 17
:i; Assign to i 2
0. 2 0 0
{…}do Run until result is 0… Showing first pass over:
@@ Stack shift -1 2 0
) Increment -1 2 1
: Duplicate -1 2 1 1
2$ Push third from stack -1 2 1 1 2
? Exponentiate -1 2 1 2
: Duplicate -1 2 1 2 2
i< Less than i? -1 2 1 2 0
(pop and either repeat or stop) -1 2 1 2

At the end of the loop, the stack looks like -1 1 4 9 16 2 5 25 so we do @;@ to make the top of the stack be 25 16.

It took like twenty minutes of fiddling around to get the stack manipulation to work right.

added 5 characters in body
Source Link
noodle person
  • 10.3k
  • 1
  • 22
  • 76
Loading
added 619 characters in body
Source Link
noodle person
  • 10.3k
  • 1
  • 22
  • 76
Loading
Source Link
noodle person
  • 10.3k
  • 1
  • 22
  • 76
Loading