What I want:

Take an input, x

Take a formula. It has to be capable of reading something in the format:

  • ax^m + bx^n + cx^o ... where m, n, o and any terms after that can represent any value.
  • coefficients, again for any number. For example, 6x^2. (That means 6(x^2))
  • Doesn't necessarily have to put up with spaces
  • times, divide, plus and minus
  • brackets - up to stacking of 5
  • ANY negative numbers
  • fractions
  • To the power of x , these can be integeric (<-- is not a word, but that is the best word I can make up!)
  • If x = 5, you can put -x to get -5 and -x^2 is -(x^2). You could use (-x)^2

After it interprets the formula, it has to plug x into the function, then output the value.

The Challenge:

  • Do it in as less bytes as possible
  • The lowest number of bytes wins!

Note: I feel that I have included everything here, but if I haven't please comment below, and I will answer it within the next 30 minutes!


Key: bp = Background Process

  • Give me an input, (x)


  • Give me a formula:


  • (bp) So I have to do 2 to the power of x, which is 2^4, which is 16
  • Output: 16
  • \$\begingroup\$ >Something in the form of ax means a*x \$\endgroup\$
    – VortexYT
    Apr 28 '17 at 15:38
  • \$\begingroup\$ Does 6-x^2 mean 6 * -(x^2) or 6 * ((-x)^2)? \$\endgroup\$
    – Stephen
    Apr 28 '17 at 15:40
  • \$\begingroup\$ I'm really not sure as to what this challenge is asking, could you at least add some test-cases? \$\endgroup\$
    – Skidsdev
    Apr 28 '17 at 15:41
  • 1
    \$\begingroup\$ Very closely related, almost duplicate. I'm not sure that adapting the answers to include the use of x would make a significant change to the solutions. \$\endgroup\$
    – user62131
    Apr 28 '17 at 15:58
  • 1
    \$\begingroup\$ @ScottMilner: If I thought it was an exact duplicate I'd have thrown a close vote on. (And given that I got dupehammer rights yesterday, it'd close the challenge by itself.) I don't think it's quite close enough to do that, but it's certainly close enough to make people aware of the possibility. \$\endgroup\$
    – user62131
    Apr 28 '17 at 16:12

TI BASIC, 6 bytes

This might change, since the rules are still not totally stable, but I wanted to post this while I could.

:Prompt X,F

Asks for X, then parses whatever formula is put into F and displays it.

If I could assume that X was already stored in the memory, it would be

TI BASIC (maybe), 0 bytes

Is this ok?Guess not. :-(

  • \$\begingroup\$ How do I test this? \$\endgroup\$
    – VortexYT
    Apr 28 '17 at 15:53
  • \$\begingroup\$ @simplest_mathematics If you have a TI-83/84 calculator, you can create a new program and plug it in. If not, you can find emulators online. \$\endgroup\$ Apr 28 '17 at 15:55
  • \$\begingroup\$ I still don't understand \$\endgroup\$
    – VortexYT
    Apr 28 '17 at 15:59
  • \$\begingroup\$ A blank code block is <pre></pre>. However, I'm pretty sure the second answer won't work because it would need to take input with X= preceding it, which means you're taking input via a variable, something that's not allowed by default on PPCG. \$\endgroup\$
    – user62131
    Apr 28 '17 at 16:03
  • \$\begingroup\$ TI BASIC is the programming language of TI 83/84 graphing calculators. You can create full programs in this language. You can find more information here \$\endgroup\$ Apr 28 '17 at 16:03

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