-3
\$\begingroup\$

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

\$\endgroup\$

closed as unclear what you're asking by xnor, Luis Mendo, Jonathan Frech, Stewie Griffin, caird coinheringaahing Sep 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.

  • 3
    \$\begingroup\$ O(n^m) time means at most n^m asymptotically. I think you want theta. \$\endgroup\$ – xnor Sep 26 at 6:26
  • 5
    \$\begingroup\$ 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. \$\endgroup\$ – Sanchises Sep 26 at 6:30
  • 2
    \$\begingroup\$ 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? \$\endgroup\$ – xnor Sep 26 at 6:35
  • 4
    \$\begingroup\$ Why the awkward input requirement. Can I really not just take two arguments? \$\endgroup\$ – Adám Sep 26 at 7:04
  • 2
    \$\begingroup\$ 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. \$\endgroup\$ – Sanchises Sep 26 at 9:25
1
\$\begingroup\$

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

\$\endgroup\$
0
\$\begingroup\$

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.

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

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