L3GabeL4
|
  |
| Joined: 18 Feb 2012 |
| Total Posts: 808 |
|
|
| 25 Aug 2012 04:29 PM |
make a calculator that can take input like: input: "1 + 1" output: "1 + 1 = 2" input: "4 * 4" output: "4 * 4 = 16"
the shortest code gets 1k Robuxs
|
|
|
| Report Abuse |
|
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 25 Aug 2012 04:30 PM |
Not the shortest, but just for fun: http://wiki.roblox.com/index.php/User:XLEGOx/luatext-astexample |
|
|
| Report Abuse |
|
|
|
| 25 Aug 2012 04:30 PM |
| I think the prize should be Half Life 3. |
|
|
| Report Abuse |
|
|
TheMyrco
|
  |
| Joined: 13 Aug 2011 |
| Total Posts: 15105 |
|
|
| 25 Aug 2012 04:34 PM |
@stravant: "Demonstrates building of a simple AST"
Yeah right. |
|
|
| Report Abuse |
|
|
L3GabeL4
|
  |
| Joined: 18 Feb 2012 |
| Total Posts: 808 |
|
|
| 25 Aug 2012 04:36 PM |
this for c++, not rbx.lua. but i respect you, so its okay
how much does Half life 3 cost? i have a decent amount of money in my bank account |
|
|
| Report Abuse |
|
|
myrkos
|
  |
| Joined: 06 Sep 2010 |
| Total Posts: 8072 |
|
|
| 25 Aug 2012 04:38 PM |
int main(void) { int x; int y; char op; std::cin >> x >> op >> y; int result; switch (op) { case '+': result = x + y; break; case '-': result = x - y; break; case '*': result = x * y; break; case '/': result = x / y; break; } std::cout << x << ' ' << op << ' ' << y << " = " << result; }
untested |
|
|
| Report Abuse |
|
|
TheMyrco
|
  |
| Joined: 13 Aug 2011 |
| Total Posts: 15105 |
|
|
| 25 Aug 2012 04:40 PM |
| Myrkos, why not directly print from the case instead? |
|
|
| Report Abuse |
|
|
L3GabeL4
|
  |
| Joined: 18 Feb 2012 |
| Total Posts: 808 |
|
|
| 25 Aug 2012 04:42 PM |
because would add more lines and it's not needed
myrkos, that's the exact same way I coded it |
|
|
| Report Abuse |
|
|
TheMyrco
|
  |
| Joined: 13 Aug 2011 |
| Total Posts: 15105 |
|
|
| 25 Aug 2012 04:44 PM |
| @l3: No I don't think that you know what I mean =3 |
|
|
| Report Abuse |
|
|
TheMyrco
|
  |
| Joined: 13 Aug 2011 |
| Total Posts: 15105 |
|
|
| 25 Aug 2012 04:47 PM |
int main(void) { int x, y; char op; std::cin >> x >> op >> y; switch (op) { case '+': std::cout << x << ' ' << op << ' ' << y << " = " << x + y; break; case '-': std::cout << x << ' ' << op << ' ' << y << " = " << x - y; break; case '*': std::cout << x << ' ' << op << ' ' << y << " = " << x * y; break; case '/': std::cout << x << ' ' << op << ' ' << y << " = " << x / y; break; } } |
|
|
| Report Abuse |
|
|
L3GabeL4
|
  |
| Joined: 18 Feb 2012 |
| Total Posts: 808 |
|
|
| 25 Aug 2012 04:47 PM |
int main(void) { int ans, a, b; char op; std::cin >> a >> op >> b; switch(op) { case('+'): ans = a + b; break; case('-'): ans = a - b; break; case('*'): ans = a * b; break; case('/'): ans = a / b; break; } std::cout << a << ' ' << op << ' ' << b << " = " << ans; return 0; } |
|
|
| Report Abuse |
|
|
L3GabeL4
|
  |
| Joined: 18 Feb 2012 |
| Total Posts: 808 |
|
|
| 25 Aug 2012 04:49 PM |
oh that probably would have been smarter. :) just so I don't feel bad, well also take character count into affect when finding the winner |
|
|
| Report Abuse |
|
|
mew903
|
  |
| Joined: 03 Aug 2008 |
| Total Posts: 22071 |
|
|
| 25 Aug 2012 04:54 PM |
| Well, I was overthinking this. I was about to use regex .... ew. |
|
|
| Report Abuse |
|
|
L3GabeL4
|
  |
| Joined: 18 Feb 2012 |
| Total Posts: 808 |
|
|
| 25 Aug 2012 04:56 PM |
| yeah a lot of people do. so, did you ever finish that one yesterday? |
|
|
| Report Abuse |
|
|
L3GabeL4
|
  |
| Joined: 18 Feb 2012 |
| Total Posts: 808 |
|
|
| 25 Aug 2012 05:00 PM |
| next challenge is going to involve string manipulation. |
|
|
| Report Abuse |
|
|
mew903
|
  |
| Joined: 03 Aug 2008 |
| Total Posts: 22071 |
|
|
| 25 Aug 2012 05:03 PM |
| I don't have time at the moment, I'm working on a game. |
|
|
| Report Abuse |
|
|
myrkos
|
  |
| Joined: 06 Sep 2010 |
| Total Posts: 8072 |
|
|
| 25 Aug 2012 05:07 PM |
>Myrkos, why not directly print from the case instead?
because code repetition is evil :O |
|
|
| Report Abuse |
|
|
L3GabeL4
|
  |
| Joined: 18 Feb 2012 |
| Total Posts: 808 |
|
|
| 25 Aug 2012 05:09 PM |
| what should the next beginner challenge be? rot13 encoding? brainf interpreter? |
|
|
| Report Abuse |
|
|
myrkos
|
  |
| Joined: 06 Sep 2010 |
| Total Posts: 8072 |
|
| |
|
L3GabeL4
|
  |
| Joined: 18 Feb 2012 |
| Total Posts: 808 |
|
|
| 25 Aug 2012 05:27 PM |
| Anyone else have anything to say? |
|
|
| Report Abuse |
|
|
|
| 25 Aug 2012 05:57 PM |
pastebin/jJ5RsVa0
What do I win? :)
|
|
|
| Report Abuse |
|
|
mew903
|
  |
| Joined: 03 Aug 2008 |
| Total Posts: 22071 |
|
| |
|
TheMyrco
|
  |
| Joined: 13 Aug 2011 |
| Total Posts: 15105 |
|
|
| 25 Aug 2012 06:08 PM |
>>Myrkos, why not directly print from the case instead?
>because code repetition is evil :O
But you repeated result = hax =3 |
|
|
| Report Abuse |
|
|
L3GabeL4
|
  |
| Joined: 18 Feb 2012 |
| Total Posts: 808 |
|
|
| 25 Aug 2012 06:11 PM |
enumeration is winning.
the prize is a game or 1k robuxs |
|
|
| Report Abuse |
|
|
myrkos
|
  |
| Joined: 06 Sep 2010 |
| Total Posts: 8072 |
|
|
| 25 Aug 2012 06:14 PM |
int main(void) { std::string expression; std::getline(std::cin,expression); std::string command = "echo $((" + expression + "))"; FILE * file = popen(command.c_str(),"r"); char result[5]; fgets(result,4,file); pclose(file); std::cout << expression << " = " << result; }
my solution is cooler |
|
|
| Report Abuse |
|
|