1
\$\begingroup\$

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.

Adám
31.7k4 gold badges130 silver badges292 bronze badges
asked Jan 16, 2019 at 13:40
\$\endgroup\$
4
  • 1
    \$\begingroup\$ Hi, maybe this question belongs to puzzling.stackexchange.com or math.stackexchange.com rather than here \$\endgroup\$ Commented Jan 16, 2019 at 13:44
  • 3
    \$\begingroup\$ In general, we avoid challenges of the type "do x without y". \$\endgroup\$ Commented Jan 16, 2019 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\$ Commented Jan 16, 2019 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\$ Commented Jan 16, 2019 at 14:12

2 Answers 2

1
\$\begingroup\$

APL (Dyalog Unicode), 7 bytes SBCS

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

answered Jan 16, 2019 at 14:02
\$\endgroup\$
4
  • \$\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\$ Commented Jan 16, 2019 at 14:12
  • \$\begingroup\$ @JeffZeitlin If you put code in TIO's Code field, you must use ⎕← to output. \$\endgroup\$ Commented Jan 16, 2019 at 14:16
  • \$\begingroup\$ Thanks. I don't know a facepalm emoticon/emoji, but consider it included here... \$\endgroup\$ Commented Jan 16, 2019 at 14:29
  • \$\begingroup\$ @JeffZeitlin 🤦︎ \$\endgroup\$ Commented Jan 16, 2019 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!

answered Jan 16, 2019 at 14:09
\$\endgroup\$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.