Challenge : creating new operators
In this challenge, you'll have to create a new operator : the exponent operator (so languages who already have it are not allowed). The syntax, when using this operator, should feel natural. The easy version is with the '^' symbol. The hard one is with the '**' symbol. Your operator should be usable like that : 2^3 or 3.5**4.2 Good luck :) BONUS : For those who find it too easy, try to make the +++ operator, to do two time the ++ operator (+++i or i+++ are equivalent to ++i;++i or i++;i++)
8/9/2017 5:36:39 PMBaptiste E. Prunier
27 AnswersNew Answer
here are solutions https://code.sololearn.com/cnoXp5H1a4gL/?ref=app
https://code.sololearn.com/cMAW3cx2ZfNZ/?ref=app Is this what you mean?
It was quite interesting, I did some research and I came across this: https://github.com/klmr/named-operator Which demonstrates how to make your own operators in C++ like this: https://code.sololearn.com/c23FwvpzbVtc/?ref=app You learn something new every day ^^
To make it clear, I did it so that it wouldn't be easy on purpose :p @Pixie, yes for the first part it is right ! @Denis wooo ... just wooo .... I am glad I made this challenge just for your answer ! I will take some screen shots of the code to study it in details !
Java doesn't support operator overloading 😒 (feeling like a grounded naughty kid)
I wrote the exact same code for Python. :( I would've preferred using the old Infix () function as that used to be the only possible way to make semi-kinda custom operators. Otherwise Python is a convenient, but very heavily restrictive language. x.x
hm. that makes it hard since every language I know has already an exponent operator.
This sounds difficult since majority of languages I'm even aware of personally have exponents incorporated into them. Are we allowed to just override default behavior of exponents the languages we're already using?
No @VcC as you used an already existing exponent operator ^^ Plus ** is hard in languages which do not have a ** operator (like Cpp)
@Sapphire, I should have said that if ** exist, overloading ** would have been the same as ^ for other languages I am sad nobody manage to do the bonus, because neither do I :p Here is what I did (did it just after posting the thread so I didn't see your answers before) https://code.sololearn.com/cp3M2lJpklrH/#cpp
Yeah @visph, for languages who have already **, you can do the ^ part (and +++ of course)
Nice challenge, I will keep this in mind. But not now, I'm not enough experienced T_T.
No @VcC and @Daniil, you are doing functions, not operators
Yeah, or at least nearly @VcC. As I said before, if the language already have the ** operator as an exponent, you'll have to use ^ instead
Nice work @Marek Wawrzos ! The two first points are clean and working ! nice ! The bonus point is not in your code, what you did is just overloading the ++ operator, so we can only have an even number of '+', we can not have '+++' like asked
You are right @Baptiste E. Prunier ! I have made a fix. Now it works with any number of ++'es
doing a simply try in https://code.sololearn.com/WPO79PKx8Mvy/?ref=app 😓