+ 12

**DAILY CHALLENGE**: Write a code that get as input a mathematical function as string. calculate and print the result of it!

RESTRICTIONS: 1) function is allways polynom of 2nd degree 2) each coefficient is included even if they are 0 3) + AND - can occure 4) allways exactly 6 whitespaces in the string (function) EXAMPLE 1: - input = "f(3) = 2x^2 + 1x - 2" - output = 19 EXAMPLE 2: input = "f(2) = 4x^2 - 2x + 0" output = 12 EXAMPLE 3: input = "f(5) = 0x^2 - 0x - 3" output = -3 PS: try to make your own parse function (if you're able to handle it) GOOD LUCK EVERYONE ... ENJOY CODING :)

27th Jul 2017, 9:17 PM
Julian Fechner
Julian Fechner - avatar
24 Respostas
+ 2
Here's my python solution. I assumed first term couldn't be negative because it says always 6 white spaces. It returns floats because I wanted it to handle float without rounding. https://code.sololearn.com/cFH4q6S8N84g/?ref=app
28th Jul 2017, 8:30 AM
Ready
Ready - avatar
28th Jul 2017, 1:15 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 9
https://code.sololearn.com/cip3XLDRIMeg/?ref=app Here's mine. It isn't pretty yet, but it should work.
27th Jul 2017, 11:53 PM
J.G.
J.G. - avatar
+ 6
ADDITIONAL EXPLANATION: - 6 whitespaces means (whitespace marked as underscore): f(3)_=_2x^2_+_1x_-_2 - input pattern is: ( - / + can change) f(X) = Ax^2 + Bx - C - not allowed input is: f(2) = 4x^2 - 2x -> missing C f(5) = - 3 -> missing Ax^2 and Bx f(3) = 1x -> missing Ax^2 and C
27th Jul 2017, 9:27 PM
Julian Fechner
Julian Fechner - avatar
+ 6
Got it! This was a fun one! You can use any positive number and 0 as x and any positive numbers and 0 as constants. Used a regex to get the pattern of the function. https://code.sololearn.com/cOc2G4zKd89P/?ref=app
28th Jul 2017, 9:07 AM
Vari93
Vari93 - avatar
+ 6
Dear downvoters; with all due respect, if you found a bug in my code you could at least point it out. I'm sure that's a much more noble way to go about it don't you think?
28th Jul 2017, 12:20 PM
Garikai
Garikai - avatar
+ 4
So f(0) = 0x^0 + 0x + 0 works as an input?
27th Jul 2017, 11:13 PM
J.G.
J.G. - avatar
+ 4
@J G. f(0) = 0x^0 + 0x + 0 isn't a function of 2nd degree! it should be: f(0) = 0x^2 + 0x + 0 !!!
28th Jul 2017, 7:45 AM
Julian Fechner
Julian Fechner - avatar
+ 4
28th Jul 2017, 8:47 AM
Garikai
Garikai - avatar
29th Jul 2017, 3:38 AM
Cristian Tomas Torres
Cristian Tomas Torres - avatar
+ 2
https://code.sololearn.com/c5XAQCI0PZ7Q/?ref=app
1st Aug 2017, 8:54 AM
Kartikey Sahu
Kartikey Sahu - avatar
+ 1
HEY PEOPLE OUT THERE. I'M BACK FROM VACATION. AND ANOTHER DAY MEANS ANOTHER CHALLENGE. CHECK IT OUT!!! https://www.sololearn.com/discuss/622449/?ref=app SOLUTION WILL BE UPLOADED TOMORROW NIGHT!
13th Aug 2017, 8:05 PM
Julian Fechner
Julian Fechner - avatar
14th Aug 2017, 7:02 PM
EraserHead
EraserHead - avatar
15th Aug 2017, 1:19 PM
Julian Fechner
Julian Fechner - avatar
15th Aug 2017, 8:19 PM
Julian Fechner
Julian Fechner - avatar
0
my new daily challenge: https://www.sololearn.com/discuss/634515/?ref=app CHECK IT OUT!!!
18th Aug 2017, 10:21 AM
Julian Fechner
Julian Fechner - avatar
0
HEY CODERS OUT THERE... NEW *DAILY CHALLENGE* RIGHT HERE: https://www.sololearn.com/discuss/645450/?ref=app
21st Aug 2017, 3:44 PM
Julian Fechner
Julian Fechner - avatar
0
MY NEW *DAILY CHALLENGE*: GIVE IT A TRY!!! https://www.sololearn.com/discuss/647083/?ref=app
22nd Aug 2017, 10:24 AM
Julian Fechner
Julian Fechner - avatar
23rd Aug 2017, 9:43 AM
Julian Fechner
Julian Fechner - avatar
23rd Aug 2017, 10:35 AM
Julian Fechner
Julian Fechner - avatar