+ 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 :)
24 Antworten
+ 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
+ 12
+ 9
https://code.sololearn.com/cip3XLDRIMeg/?ref=app
Here's mine. It isn't pretty yet, but it should work.
+ 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
+ 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
+ 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?
+ 4
So f(0) = 0x^0 + 0x + 0 works as an input?
+ 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 !!!
+ 4
Lekker challenge mate 👍
https://code.sololearn.com/cjSe1lA1KEp0/?ref=app
+ 2
https://code.sololearn.com/c5XAQCI0PZ7Q/?ref=app
+ 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!
0
NEW CHALLENGE HERE:
https://www.sololearn.com/discuss/626739/?ref=app
0
NEW DAILY PRINT-CHALLENGE:
https://www.sololearn.com/discuss/628136/?ref=app
0
my new daily challenge:
https://www.sololearn.com/discuss/634515/?ref=app
CHECK IT OUT!!!
0
HEY CODERS OUT THERE...
NEW *DAILY CHALLENGE* RIGHT HERE:
https://www.sololearn.com/discuss/645450/?ref=app
0
MY NEW *DAILY CHALLENGE*:
GIVE IT A TRY!!!
https://www.sololearn.com/discuss/647083/?ref=app
0
NEW DAILY CHALLENGE FOR YOU:
https://www.sololearn.com/discuss/649970/?ref=app
0
ANOTHER MINI-CHALLENGE HERE:
https://www.sololearn.com/discuss/650079/?ref=app