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.
2 Answers 2
APL (Dyalog Unicode), 7 bytes SBCS
Anonymous tacit infix function. y is left argument and x is right argument.
(+/⍴)/⍴
⍴
cyclically reshape (gives y copies of x)
(
...)/
reduce by the following function:
⍴
cyclically reshape to left argument copies of right argument
+/
sum
-
\$\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– Jeff Zeitlin2019年01月16日 14:12:47 +00:00Commented Jan 16, 2019 at 14:12 -
\$\begingroup\$ @JeffZeitlin If you put code in TIO's Code field, you must use
⎕←
to output. \$\endgroup\$Adám– Adám2019年01月16日 14:16:20 +00:00Commented Jan 16, 2019 at 14:16 -
\$\begingroup\$ Thanks. I don't know a facepalm emoticon/emoji, but consider it included here... \$\endgroup\$Jeff Zeitlin– Jeff Zeitlin2019年01月16日 14:29:51 +00:00Commented Jan 16, 2019 at 14:29
-
\$\begingroup\$ @JeffZeitlin 🤦︎ \$\endgroup\$Adám– Adám2019年01月16日 14:34:13 +00:00Commented Jan 16, 2019 at 14:34
Explore related questions
See similar questions with these tags.
x
andy
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\$