# A really inefficient calculator [closed]

Challenge: Add two numbers. In O(n^m) time, where n and m are the two numbers given. Sleeping, or your language equivalent, is not allowed.

Input: Two integers, separated by a space.

Output: The sum of the two integers.

Additional notes: The exact timing doesn't matter, as long as the input 1000 2 takes roughly 1/1000th the time as the input 1000 3

## closed as unclear what you're asking by xnor, Luis Mendo, Jonathan Frech, Stewie Griffin, caird coinheringaahingSep 26 at 7:29

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• O(n^m) time means at most n^m asymptotically. I think you want theta. – xnor Sep 26 at 6:26
• I presume you want people to use some kind of super slow algorithm, but there's nothing stopping them from doing simple addition followed by an n^m loop of NOPs to pad the runtime. I don't think there's a way around that (we do not allow unobservable requirements) but just a warning that submissions may be less interesting than you envisioned. – Sanchises Sep 26 at 6:30
• Is it OK if a program takes n^m time to complete after printing the sum, or would it have to take the time before printing? – xnor Sep 26 at 6:35
• Why the awkward input requirement. Can I really not just take two arguments? – Adám Sep 26 at 7:04
• Maybe try the sandbox next time to get feedback on your challenge before you post it. And why not try to answer some challenges yourself! Then you get a good feel for what works. – Sanchises Sep 26 at 9:25

# APL (Dyalog Unicode), 4 bytesSBCS

Anonymous tacit infix function:

⊃*⍴+


Try it online!

However, if it really needs to take the two arguments together, separated by a space, we need the following anonymous tacit prefix function:

# APL (Dyalog Unicode), 6 bytesSBCS

⊃*/⍴+/


Try it online!

+ or +/ sum the numbers

⍴ cyclically reshape that to the following length:

* or */ one number raised to the power of the other

⊃ pick the first element of that

# Python 3, 34 bytes

lambda n,m:sum(range(n**m))and m+n


Try it online!

Alternatively, as suggested by user202729:

# Python 2, 26 bytes

lambda n,m:n**m*[1]and n+m


Try it online!

which also works with Python 3.

• Why sum()? Isn't range(n**m) already $O(n^m)$? – Adám Sep 26 at 8:40
• @Adám Yes in Python 2, but not in Python 3 where range doesn't actually create the list: TIO – xnor Sep 26 at 10:44
• What about [1]*? – user202729 Sep 26 at 11:05
• @user202729 : I'd guess you're right. – Chas Brown Sep 27 at 5:31