I've only implemented the parsing. The code is accessible at https://repl.it/KQWN. Since I used a parsec library, you cannot run it there. :/
I don't parse the variable names, so it's possible to use multiple variables mistakenly.

I've only implemented the parsing. The code is accessible at https://repl.it/KQWN. Since I used a parsec library, you cannot run it there. :/
I don't parse the variable names, so it's possible to use multiple variables mistakenly.

This is pretty cool! Can you elaborate a bit on what language you used, how you build up the grammar etc.?
There are three parsers related to polynomials:
polytermandnumber.Line 15: All parsers remove the trailing spaces, so the main parser
polyshould remove the leading whitespace. It basically states: skip the whitespace,polyis made of manyterms and you arrive to the end of the input.Line 18:
termis a tuple of anumberand anothernumber. The second number is located after anidentifierand the symbol^.Line 21-25:
numberis either negative or positive.<|>stands for either. For the second case the number may not start with the sign+,optiontakes care of that.fcomputes the value of the string of numbers.Line 28: We run the parser
polyon the sample input. It prints out the result as a tuple ofterms as indicated in the parser descriptions.Thank you for the explanation! Parsec is really strong, looking forward to leaning more about it :)
It is and I'm using it in very basic form. There're very good documents at https://github.com/haskell/parsec
I implemented
showPoly,add,subtractPoly, andmultiplyfunctions.Oh snap, the simplify looks crazy! It would be so cool if you could make a post explaining how each little piece works in many details, once you are finished.
There are basically three transformations.
sortOn snd polypoly is a list of tuples of two numbers for each polynomial term's coefficient and power. First step sorts the list of tuple by its second element which is power.
groupBy ...We group all terms by their power.
groupByreturns a list of lists. Each list represent a power value.map fFor each list of lists we
foldlthe list which is basically reducing the list to a single value. For instance if we have5x^2-3x^2+x^2it evaluates to3x^2.Once you get used to functional programming, most things will look very clear. ;)
Take a look: http://learnyouahaskell.com
I would agree.
meep
beep loves coding ? :D
meep
I think this is Functional Programming.....
looks like Haskell or F#... not sure.
Checking the author is is most likely Haskell, that was the language he submitted the last challenge in.
It's Haskell. The links provide the information but it wasn't clear at first sight.