Kyle
New Member
Veteran
hello my name is Kyle
Posts: 8
|
Post by Kyle on May 3, 2017 11:06:01 GMT
Write a program that takes a calculation as input in a format such as 9+1 that will output the solution. If your language cannot take input, you should assume that there is a variable called input which contains the calculation.
Examples of input:
9+1 > 10 5*5 > 25 5-1 > 4 10/2 > 5 5^2 > 25
The program should understand at least: +, *, -, /, ^
Note that the integers can be of any length.
|
|
|
Post by Josh on May 3, 2017 11:12:56 GMT
Python3, 38 characters
print(eval(input().replace("^","**"))) If you do not want to accept solutions with ".0", then...
Python3, 60 characters
print(str(eval(input().replace("^","**"))).replace(".0",""))
Thanks for contributing!
(Don't bully me for using eval)
|
|
|
Post by 128Gigabytes on May 3, 2017 15:46:43 GMT
print(load("return "..io.read())())
Lua, 35
|
|
Dankvisky
New Member
Veteran
5 bans and still alive. try to beat that with a single account!
Posts: 17
ROBLOX Username: Dankvisky
|
Post by Dankvisky on May 3, 2017 15:55:11 GMT
Rbx.lua with loadstring enabled loadstring("warn("..input..")")()
>33 chars
|
|
|
Post by Josh on May 3, 2017 15:55:47 GMT
|
|
|
Post by 128Gigabytes on May 3, 2017 15:57:41 GMT
Lua, 32
load("print("..io.read()..")")()
|
|
zmart
New Member
Veteran
Posts: 8
|
Post by zmart on May 3, 2017 16:22:32 GMT
JavaScript, 14 - XxtraCheesy
eval(prompt())
|
|
|
Post by Josh on May 3, 2017 16:48:55 GMT
Great solution, zmart - you always seem to get the shortest!
|
|
lae
Active Member
Veteran
Posts: 27
ROBLOX Username: LaeMVP
|
Post by lae on May 3, 2017 19:33:38 GMT
doing it on paper results in less characters
|
|
|
Post by Josh on May 3, 2017 19:50:38 GMT
doing it on paper results in less characters That is true, but lets see what you can do if you type it on a PC
|
|
zmart
New Member
Veteran
Posts: 8
|
Post by zmart on May 3, 2017 21:20:52 GMT
Thanks! Inspired by the fine golfing of others out on the pitch, including yourself, vha, goulstem, nilogic, and other participants!
I wanted to make a non-cheesy version of this .. something like a functional object that took a string version of a mathematical operation and combined the digits accordingly, but that would quickly go over 100 chars.
|
|
|
Post by Bit on May 3, 2017 21:22:59 GMT
"Sometimes, I dream about cheese." Nice solution.
|
|
lae
Active Member
Veteran
Posts: 27
ROBLOX Username: LaeMVP
|
Post by lae on May 3, 2017 23:01:15 GMT
doing it on paper results in less characters That is true, but lets see what you can do if you type it on a PC what if I'm using Mac?
|
|
|
Post by Bit on May 3, 2017 23:57:56 GMT
Lmao
|
|