1
\$\begingroup\$

This question already has an answer here:

The challenge is to implement a function or program that takes two numbers, \$x\$ and \$y\$ and return the result of \$x^y\$.

The program cannot use any other mathematical operation other than \$+\$ or \$-\$, so no multiplication or division. Functions built into languages are also not allowed.

The code in the least amount of bytes wins.

\$\endgroup\$

marked as duplicate by Luis felipe De jesus Munoz, Adám, Arnauld code-golf Jan 16 at 14:14

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    \$\begingroup\$ Hi, maybe this question belongs to puzzling.stackexchange.com or math.stackexchange.com rather than here \$\endgroup\$ – Luis felipe De jesus Munoz Jan 16 at 13:44
  • 3
    \$\begingroup\$ In general, we avoid challenges of the type "do x without y". \$\endgroup\$ – Adám Jan 16 at 13:53
  • 1
    \$\begingroup\$ Are x and y guaranteed to be integers? What counts as "other mathematical operation"s ... does equality and inequality count? How about array or string multiplication that isn't a mathematical operator but creates copies of the array or string? \$\endgroup\$ – AdmBorkBork Jan 16 at 13:59
  • 5
    \$\begingroup\$ Duplicate of Calculate the a ^ b WITHOUT using *, / and ^ which itself is a duplicate of this which is a duplicate of this \$\endgroup\$ – Adám Jan 16 at 14:12
1
\$\begingroup\$

APL (Dyalog Unicode), 7 bytesSBCS

Anonymous tacit infix function. y is left argument and x is right argument.

(+/⍴)/⍴

Try it online!

 cyclically reshape (gives y copies of x)

()/ reduce by the following function:

 cyclically reshape to left argument copies of right argument

+/ sum

\$\endgroup\$
  • \$\begingroup\$ I was groping toward this solution in a "traditional" mode; however, for some reason, I can never get APL to produce output on TIO - what might I be doing wrong? The test case I was trying with was +/4⍴+/3⍴3, to see if I was on the right track for 3^4. \$\endgroup\$ – Jeff Zeitlin Jan 16 at 14:12
  • \$\begingroup\$ @JeffZeitlin If you put code in TIO's Code field, you must use ⎕← to output. \$\endgroup\$ – Adám Jan 16 at 14:16
  • \$\begingroup\$ Thanks. I don't know a facepalm emoticon/emoji, but consider it included here... \$\endgroup\$ – Jeff Zeitlin Jan 16 at 14:29
  • \$\begingroup\$ @JeffZeitlin 🤦︎ \$\endgroup\$ – Adám Jan 16 at 14:34
1
\$\begingroup\$

Python 2, 53 bytes

lambda x,y:y>1and sum(x for _ in range(f(x,y-1)))or x

Try it online!

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.