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

edited body
Source Link
B. Mehta
  • 753
  • 4
  • 11

Try it online! Try it online!

Stretching the limits of "reasonable way" here, but the expressions are separated.

Explanation

First expression:

XH'^'i'='XJ
XH % implicitly take input A, save it to clipboard H
'^' % push literal '^'
i % take input B
'=' % push literal '='
XJ % copy '=' to clipboard J, we'll use this twice more so it's worth it

Second expression:

2G:"H'*']xJ
2G % paste the second input (B) again
:" % do the following B times
 H % paste A from clipboard H
 '*' % push literal '*'
] % end loop
x % delete the final element (at the moment we have a trailing *)
J % paste '=' from clipboard J

Third expression:

&Gq^:"H'+']xJ
&G % paste all of the input, ie push A and B
q % decrement B
^ % power, giving A^(B-1)
:" % do the following A^(B-1) times 
 H % paste A from clipboard H
 '+' % push literal '+'
] % end loop
x % delete the final element (at the moment we have a trailing +)
J % paste '=' from clipboard J

Fourth expression:

&G^:"1'+']x
&G % paste all of the input, ie push A and B
^ % power, giving A^B
:" % do the following A^B times 
 1 % push 1
 '+' % push '+'
] % end loop
x % delete the final element (at the moment we have a trailing +)
 % (implicit) convert all to string and display

Try it online!

Stretching the limits of "reasonable way" here, but the expressions are separated.

Try it online!

Stretching the limits of "reasonable way" here, but the expressions are separated.

Explanation

First expression:

XH'^'i'='XJ
XH % implicitly take input A, save it to clipboard H
'^' % push literal '^'
i % take input B
'=' % push literal '='
XJ % copy '=' to clipboard J, we'll use this twice more so it's worth it

Second expression:

2G:"H'*']xJ
2G % paste the second input (B) again
:" % do the following B times
 H % paste A from clipboard H
 '*' % push literal '*'
] % end loop
x % delete the final element (at the moment we have a trailing *)
J % paste '=' from clipboard J

Third expression:

&Gq^:"H'+']xJ
&G % paste all of the input, ie push A and B
q % decrement B
^ % power, giving A^(B-1)
:" % do the following A^(B-1) times 
 H % paste A from clipboard H
 '+' % push literal '+'
] % end loop
x % delete the final element (at the moment we have a trailing +)
J % paste '=' from clipboard J

Fourth expression:

&G^:"1'+']x
&G % paste all of the input, ie push A and B
^ % power, giving A^B
:" % do the following A^B times 
 1 % push 1
 '+' % push '+'
] % end loop
x % delete the final element (at the moment we have a trailing +)
 % (implicit) convert all to string and display
edited body
Source Link
B. Mehta
  • 753
  • 4
  • 11

MATL, 46 bytes

XH'^'i'='XJ2G:"H'*']xJ&Gq^:"H'+'XI]xJ&G^"H'+']xJ&G^:"1I]x"1'+']x

Try it online!

Stretching the limits of "reasonable way" here, but the expressions are separated.

MATL, 46 bytes

XH'^'i'='XJ2G:"H'*']xJ&Gq^:"H'+'XI]xJ&G^:"1I]x

Try it online!

Stretching the limits of "reasonable way" here, but the expressions are separated.

MATL, 46 bytes

XH'^'i'='XJ2G:"H'*']xJ&Gq^:"H'+']xJ&G^:"1'+']x

Try it online!

Stretching the limits of "reasonable way" here, but the expressions are separated.

Improved answer
Source Link
B. Mehta
  • 753
  • 4
  • 11

MATL, (削除) 64 (削除ここまで) 5846 bytes

VXH94ciV&YcD2GXH'^'i'='XJ2G:"H42c]x&YcD&Gq^"H'*']xJ&Gq^:"H43cXI]x&YcD&G^"H'+'XI]xJ&G^:"1VI]x&YcD"1I]x

Try it online! Try it online!

Stretching the limits of "reasonable way" here, but the expressions are separated.

MATL, (削除) 64 (削除ここまで) 58 bytes

VXH94ciV&YcD2G:"H42c]x&YcD&Gq^:"H43cXI]x&YcD&G^:"1VI]x&YcD

Try it online!

MATL, 46 bytes

XH'^'i'='XJ2G:"H'*']xJ&Gq^:"H'+'XI]xJ&G^:"1I]x

Try it online!

Stretching the limits of "reasonable way" here, but the expressions are separated.

added 4 characters in body
Source Link
B. Mehta
  • 753
  • 4
  • 11
Loading
Source Link
B. Mehta
  • 753
  • 4
  • 11
Loading

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