5 kyu
Calculating with Functions
35,088 of 86,289BattleRattle
Loading description...
Functional Programming
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
I really really liked this mind-bending kata... I read other comments - and to me the description of what to do was very clear.
I am still very much struggling with closures, Higher Order Functions - but I was able to solve this kata (which is of 5 kyu lvl) way quicker than this 6 kyu kata... https://www.codewars.com/kata/5b0a80ce84a30f4762000069
This comment has been hidden.
I really enjoyed this kata, it's been a fun exercise in functional programming for me. Thanks a lot!
What should I do in this kata? I made a universal function that decomposes a string into expressions and calculates a formula. But what should I do in this damn kata?
I am not sure which part you don't understand. Basically the requirement is to write a bunch of functions, which will return for exmple 35 when called like this:
seven(times(five()))
.If you call it locally in your IDE like this:
print(seven(times(five())))
it will print35
.This comment has been hidden.
kata solution != kata suggestion
Please do not post solution in discourse, and if you intend to post any hints or tips after solving, do apply the Spoiler flag
It has wrong tests on attemp!
Wrong result for one(dividedBy(three)): expected 0.3333333333333333 to equal +0
"three" - passed like variable!
(JavaScript) the problem was with the assertion messages, the tests do call the function. fixed.
fun kata, javascriptable kata
Groovy Translation
This comment has been hidden.
A creative lesson about FP
Mindblowing exercise!! I must learn lambda function
This comment has been hidden.
Could you give some hint for thinking about that?
I can't give too much of a hint, but it's best to make a seperate function for handling the weirdness of the question.
Sorry if that's not very specific but that's about all I can really say. Though it's been some time so you probably already solved this
Even though I didn't solve this kata at moment when I saw your comment, but now - yes. I was really amazed by how many ways you could solve this kata
Yeah this one was actually extremely strange. Like I said before it took me 3 days and when I finally DID manage to figure it out and see everyone elses stuff, the top rated one was completely incomprehensible and looked almost as if it shouldn't be possible. But it was
Either way, good luck with the rest of your kata. I got Kyu 4 kata myself and it seems almost ridiculous what some of this wants. And have fun, very important that part.
C++ Translation.
Approved :)
OCaml translation (author gone)
Approved
C++ translation wanted.
This comment has been hidden.
I am not sure about this. I think that the goal of the kata could be achieved with a simple overloading, couldnt it?
That's true. I remembered the Kata much differently than what it is, and the fixed tests are rather a breeze. All the problems I expected actually show up when trying to adapt the random tests. If I find a clean way to implement the random tests, I'll publish the translation
This comment has been hidden.
C++ Translation. Re: The difficulty doesn't go up much for the user's side. Getting random tests up and working was a living hell, though, since I couldn't make assumptions about implementation details and it's miserable trying to deal with overloaded functions on the type level. I don't expect this to get approved since C++ is the odd one out between the available languages, but who knows. Only downside of this being C++ is that unimplemented functions result in compile time errors rather than gentle runtime errors, but that's a given.
just have the test suite arbitrarily run them each once
can you elaborate?
I apologize, I misunderstood the problem.
Re @o2001: Wow, that C++ translation is looking great! I now realize that I did not consider enough the complexity of writing randomized tests for C++ solutions, since I have no experience at all in setting up katas, but you somehow managed it.
I would certainly approve it, but I have no rights to do so.
Your wish is granted
I really, really enjoyed this kata, it's been a fun exercise in functional programming for me. Thanks a lot!
Ever since I got to solving 5kyu, I feel like I don't know s*** in Python
Haha, I get what you mean. Just reached 2 and 3kye kata's and I'm unable to solve most of them
every day we wake up to learn
PHP translation
Could someone take a look at this? The kata author is no longer active.
i have a serious issue, the tests do pass in vscode for javaScript language but here they don't. is there something i am missing?
Not a kata issue, you're using global vars, and they keep their value between tests. Read this: https://docs.codewars.com/training/troubleshooting
in standart tests is ok, but in random it gives me an error "AttributeError: ", but in Pycharm everything is OK for example three(minus(two())) in console gives "1" and in tests Unexpected exception raised
This comment has been hidden.
This comment has been hidden.
this kata very good it help my to understand how function work and i enjoy very much solving it.
I have absolutely no idea what I'm being asked to do
That was... fun? 🥲
This comment has been hidden.
Chai..
are you nigerian lmaooo
Lol, My guy talk chai.
This comment has been hidden.
Looks like tests are broken here
Wrong result for eight(minus(eight)): expected 8 to equal +0
multiply Wrong result for four(times(zero)): expected 4 to equal +0
You most probably do not read the failure message correctly. 8 - 8 expectes zero, and 4 * 0 expects zero, ad this is what the message says.
This comment has been hidden.
This one is great, but I wonder if you should ban eval. A while ago I solved it with eval and got none of the fun until solving it again the "real" way with functions.
eval does feel kind of cheap. I had the opposite experience sort of. I just retraine on this kata and I used eval() and when I went and looked at my first solution I was like, "Holy shit, did I really write this?!" I think i did since it didn't get any variations. Plus eval is almost never a good idea for security reasons.
Do you have problems with testing this kata? My code is ok in basic tests, but it is incorect in random tests. I don't understand what's happening. I think my solution is ok. Can anybody help me?
Ok, I managed it. The problem was in testing.
I have no idea what the author is asking me to do. Very unclear, vague instructions. Whenever I write instructions for students, I'm careful to word things so there's no ambiguity.
This comment has been hidden.
This comment has been hidden.
Tests in Python are not broken, and dependency between test cases is introduced by a bug in your solution. Try to run this code in sample tests, or in your local IDE:
All of your functions accumulate state between consecutive calls. When one of them, for example
four
, is used more than once, it will work incorrectly and fail.Your solution is buggy, it's not a kata issue.
Thank you for the tip, I really didn't thought about the behavior of creating a list as a default value in a function. But I also didn't try multiple calls for the solution in a test.
Tedious, but fun!
This comment has been hidden.
Your solution does not conform to this point:
It's a bug in your solution, not a kata issue.
Also please use code formatting when posting blocks of code.
Yep, sorry I have fixed my solution.
This comment has been hidden.
I can't get around the need for arguments. In order to pass in the operation functions into the first number, we need to require an argument. But since the second number doesn't take an argument, we can't require one.... So do we have to write two functions for each number?
This comment has been hidden.
This comment has been hidden.
Who can give the solution of this error: TypeError: times() takes 0 positional arguments but 1 was given. Is it kata error or I'm doing something wrong?
Notice that over 25K solves have been successull in Python (your language).
Your function declarations to not take any arguments, but where necessary they will need to... to function.
So, rewrite them to accept the correct input(s).
Yeah I mean I have not doing anything about times() function it is one of the test cases
you have defined a
times
function in your code. however, it does not accept arguments. you need to alter yourtimes
function (and others) so that it (they) take(s) arguments.i dont think i understand this kata, like im sure that im suppose to use callback, and from what i understand my code should return the same result that example given but i keep getting error
This comment has been hidden.
I don't do Haskell, but:
It looks possible.
Sorry, my stance corrected. It's very hacky but I do get where they were going. Thanks!
This comment has been hidden.
Please read this: https://docs.codewars.com/training/troubleshooting/#post-discourse
first of all. I have learned so much by atempting this kata! Very challenging in a fun way.
this may be a stupid question but are we allowed to create more functions than the ones given?
While you write the functions that are needed and they return what they should, there is no limit about another functions you could use inside them.
Error during random calculations
Wrong result for seven(dividedBy(six)): expected 1.1666666666666667 to equal 1
six passed as variable, not as function six()
if i call in console seven(dividedBy(six())) all is ok
Your code isn't doing integer division, not a kata issue.
This comment has been hidden.
Not to sure what I did wrong but when I clicked attempt it says
SyntaxError: Unexpected token '*' at four (test.js:8:47) at Context. (test.js:26:24) at process.processImmediate (node:internal/timers:471:21)
I have * in my code for times. JS Also not sure if im ment to mark this as a issues or question?
This comment has been hidden.
thanks got it working now
Why are there so few languages in which you can write this kata?
Because nobody has translated it to other languages yet :)
Also the nature of the kata might make it not translateable to certain languages.
Amazing Kata!!!, this first time my code was shit but i figured out, :)
i'm confused. why would i want to do this when i could just write a function that takes two numbers and multiplies two numbers eg?
Can't tell if this is a troll comment or not.
At least judging by OP's rank, id believe it's not a troll comment but a honest question.
Maybe you'd have an idea how to explain this clearly? Because I am not sure I'd know how.
not a troll comment. i'm genuinely curious. at first blush to me it seems like this particular example is using an example that you wouldn't really do in the real world, but i may be incorrect in that statement. am i? i've never done functional programming before
(Assuming Haskell version) I'm also new to functional programming, so maybe someone can comment on this. I found this challenging, it took me a while to work out what I was being asked to do, and then a while to work out how to do it.
I think the exact problem is quite contrived, but there are cases where you get passed a function or need to pass a function into something. Or you want to iterate over some functions that on the surface seem very different. A number seems very different from a math operator, but this shows that you can consider both to be functions.
I'll put a 2nd comment with a spoiler warning.
This comment has been hidden.
This is a good, gentle intro to functional programming.
That being said, you would probably be very popular at work if you used this in production code, but for a bad reason.
I'd love to come back to this one. I am not understanding the directions. It sounds like we should be producing 40 total functions, but the code window only has 14. If you do each of the 4 mathematical operations on each of the 10 digits, that would be 40 functions. What am I not understanding?
cool kata!
Great kata, allowed me to finally understand how the returning functions from functions works. Thanks!
My code requires function call as a string but the input is a direct function call. Can someone help me convert the input function call as a string?
Very nice kata. Beginners will learn new concepts from this.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Your solution uses global variables. It passes only once, and fails every further time. It will not work in PyCharm either if you test it more than once.
This comment has been hidden.
Why is the innermost function without brackets in a random test? Because of this, the test does not pass normally.
No idea what you're talking about, but your code fails because your not doing this:
I agree. I just need more rest :)
i did solve the problem but i didn't learn anything new from my solution xD
My solution passed all the tests but upon seeing the official solutions I have doubts that it should count as understanding the spirit of the problem. Any tips on where to study the material involved here?
This comment has been hidden.
Saw the prompt absolutely broke my mind. Then the aha moment clicks and its really fun
Had me for a bit; first time I've encountered called functions within called functions and I wasn't really sure how to approach it. Seems there's many ways to handle this one, not totally satisfied with how I did it, but it seems it's not the worst way either.
This comment has been hidden.
Great kata! I enjoyed solving it, it was the first time I ever tried a functional programming related problem and, honestly speaking, I had no idea where to even begin with.
Though, I would like to make a request for an improvement. It would be good if it took divisiblity by 0 into account. It returns Infinity, at least, in JS
This comment has been hidden.
search for ternary_operators, lambda and keep in mind you can have function arguments that are "optional"
This comment has been hidden.
samee😥
Took me one hour , but the time is worth ! Is a tricky one!
You're awesome to be able to focus on that, but the sense of accomplishment that comes with a solution is unparalleled.
Extremely interesting problem. I def need to go back through everyone's solution to understand how to become more efficient in coding.
This comment has been hidden.
This comment has been hidden.
Using '()' calls the function. So:
function foo(bar()) -> bar() is called within the param and passes the result to foo()
function foo(bar) -> bar is a variable that a function can be assigned to, then called within foo()
Really need help about solution can anyone give me tips o_o
Now i see the value of lambda functions. I kept getting errors because the functions were not expecting arguments so I had to use self Spent some time learning lambda functions. In C they are just function pointers in python they are function objects.
This comment has been hidden.
Ok! I'm did it.)
My solution was super ugly but it worked. I'm going to have to come back to this later to look through the other solutions and learn how to do this properly
I'm trying this in Python 3.6, if anyone can point sources helpful to acccomplish this task, I'd greatly appreciate.
Was fun is there a #2?
This comment has been hidden.
I made it 🎉🥳
This comment has been hidden.
This comment has been hidden.
Just want to say thanks to all the other people who are mentioning the mind-bending nature of this problem: these comments make me feel comforted and I appreciate you all. This is one of those problems where we can doubt our capacities BUT WE MUST TAKE HEART!
The fact it is so challenging means that we are in the perfect place for growth. We must keep bashing into this problem and analyze the solutions and I swear the investment in doing so will pay off far more than other less challenging problems. Deep work is happening here.
As programmers/coders we must learn to love these situations for this is exactly what we are getting into as programmers/coders. We must learn how to become excited and curious, we must learn how to say "How fascinating!" in the face of all the other voices which may speak self-defeating phrases.
Lastly, this is the perfect type of problem to spend like 30-45 mins on analyzing and trying to comprehend, then taking a walk or some other activity (or even a nap) where we are not actively thinking about the problem. Our brain will be working on it in the background, oftentimes despite ourselves. Then when we come back to it we will be shocked that our comprehension has increased. Experiencing this is so crucial because it will teach us to trust in the process, which will allow us to embrace these situations all the more.
Blessings to all you!
Very well said! Thanks for your encouraging words!
Thank you so much for your encouraging words! Helped me not skip over this tough question.
This comment has been hidden.
If you haven't solved it yet, you don't need to learn much for this. It's just about creating a good algorithm
Currying
I tried to do this for a long time, I achieved that in another editor (PyCharm) the tests pass correctly in debug mode, but not during normal launch. What should I do?
If you can't debug your solution yourself and actually hope somebody to help you, you should post your (properly formatted) code in a comment with a spoiler tag.
This comment has been hidden.
a function should return something. In this problem, the number functions should either return a number or a solution.
Factor translation
Note: the kata is slightly different in factor, and so should be reviewed carefully.
Approved.
This comment has been hidden.
Approved
I can't even get function seven(times(five())) in the editor without an error. Guess this one will take some time
Both the idea of actually doing this as well as my solution make me want to vomit... I regret nothing.
Aye but I found a way to condense mine a bit, nothing near the extent of those top solutions though.
Hey there, Can you add this case to test cases as well?
print(two(times(times(six()))))
Thanks in advance.
Why? That's not a valid operation:
This comment has been hidden.
Not a kata issue. Closing.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Your guess is correct. :-)
This comment has been hidden.
Read this: https://docs.codewars.com/training/troubleshooting#works-but-no a problem with your code is not a kata issue.
Call your functions in your IDE, like they're called here in the tests, one after the other:
I don't understand, I'm copying test into my ide and it works. Also, what's the difference between those two examples? I don't see any (not counting different numbers and symnbols), so why one should work, and the other not?
You're using global vars, they keep their value between tests, are you using those two prints exactly as I posted them? Calling only one at a time will work fine, but calling them one after the other won't.
Ok, I know what's wrong now. Thank you for your time!
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Read this: https://docs.codewars.com/training/troubleshooting#your-solution-seems-to-work-or-is-close-to-working-but-still-fails-tests and don't use global vars, they keep their values when tested several times in a row, as you could see.
This comment has been hidden.
This might give some inspiration, but this kata does not really require any specific knowledge, rather just some clever thinking.
Thanks! On It!
This comment has been hidden.
This comment has been hidden.
The Python tests are working correctly. Please note that there are almost 14K solves in that language. If you do not know why your code is not working, please post as a
question
. Posting as anissue
is strictly for when the kata has a fault. If you like, you may post your code with a spoiler tag and use proper markdown formatting. Someone may be able to help. Also, you can check out this documentation on troubleshooting your solution.Thank you for that. Finally found the issue. I forgot to reset my variables after calling the function once.
This comment has been hidden.
Hi, buddy. Which language are you looking to solve the kata with?
I need help too. I am using Python 3.8 to try and solve this kata.
with ruby i looked into lambda functions, passing functions into the next method, and args
This comment has been hidden.
Hi, I only managed to solve this Kata with using eval(), but I learned a lot from others' solutions.
You can read why it is not a good thing to use eval() here: Here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval
"Never use eval()! eval() is a dangerous function, which executes the code it's passed with the privileges of the caller. If you run eval() with a string that could be affected by a malicious party, you may end up running malicious code on the user's machine with the permissions of your webpage / extension. More importantly, a third-party code can see the scope in which eval() was invoked, which can lead to possible attacks in ways to which the similar Function is not susceptible. "
💯
Great kata!, helps to understand language better and use more features
This comment has been hidden.
I wondered the same thing, similarly to you I used parseInt in the divideBy function but then after submitting I noticed in the top solutions they did not do anything special in the divideBy function. I wonder if the Kata has changed to only allow ints since those solutions were submitted?
Can I ask you how do you get m value?
This comment has been hidden.
This comment has been hidden.
hmmmmm!
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Spent a few hours on this, amazing kata!
This comment has been hidden.
Don't post solution in discourse and under other's comment!!!
Thanks for the kata. I had to look over all the materials which I thought I knew very well. It was a good refresher and a nice challenge.
This comment has been hidden.
trust me its not what it seems like...there is a much better method to do it...
Yeahhhh I feel like I'm missing something
This comment has been hidden.
5 kyu isn't exactly 'novice' level anymore, and the kata has tags like 'functional programming' or 'higher order functions', which you should be familiar with if you want to try it.
The description provides examples showing that functions take either 0 or 1 arguments, and it seems pretty clear overall, IMO :/
Now that i've read your answer, this doesn't seem so non-obvious to me. But it still difficult to understand for novices i guess, and although i spent about 4-5 hours to the study "higher order functions" and "lambda" (python) i couldnt solve the kata, exact beacause the misunderstanding with paramethers
I can understand that, some of these concepts are a bit more advanced and it takes time to wrap you head around them.
This kata is really difficult. I have no ideas about it. I could barely print the first function
I would recommend reading up on higher order functions
This comment has been hidden.
You are a true friend.
Thanks so much
thanks mate : )
Those were really helpful resources, especially the vid - thanks for the share :)
This comment has been hidden.
Don't create a function called
eval()
(at least for JS). You will see some weird errors.Thanks a lot for Kata's creators. I spent a night for solving. Kata description gave an idea - studying of HIGHER-ORDER FUNCTIONS.
This comment has been hidden.
Kata I love him very much
This is the most useful challenge I've ever done!! At first it was turning my brain into a pretzel, and then the pretzel gradually clarified into something that made sense, and I feel like I learned a ton. Thanks for this kata!
This comment has been hidden.
can you recommend any reading material for it?
If it's still useful, "composing functions (https://medium.com/javascript-scene/composing-software-an-introduction-27b72500d6ea)", and "run through concepts discussed here (https://www.youtube.com/watch?v=viQz4nUUnpw)", I have taken these quotes from a comment above by @cschipg. Maybe it can be useful for you. (I didn't give you any resources I used because I don't remember them, a pen and paper i guess lol)
This comment has been hidden.
This comment has been hidden.
I second natan: Study higher order functions (and maybe think of things like objects perhaps)
This comment has been hidden.
God it finally works, though not all tests are passed yet. My advice to those struggling is to knuckle down, since it's really rewarding in terms of acquired knowledge. Good luck!
This comment has been hidden.
Have no polite words to describe my misery!!! In tests there is a case 'Test.assert_equals(basefa, a+b)' There weren't any words about bases And no words about letters Please do something
To be honest, i bruteforced this kata Using globals and traceback But mistakes started only from random tests Basic tests passed greatly So would have done random tests if there wasn't this strange construction
Description explains the problem, not the identifiers used in tests. There aren't bases,
base
contains strings used init
messages. There aren't strange constructions.Not an issue.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Took me 2 evenings to solve this one and was really hard to get my head around. Suggest searching the web for "python function closure" as your next port of call.
This comment has been hidden.
Just looking at the solutions of this kata is beautiful.
This comment has been hidden.
If you mean, in Solutions tab you see some solutions where you see
/
as division, then those solutions are for Python 2.7.I'm super stuck here. Read an article about function composition that someone here suggested, but that didn't help. I'm confused as to how the outermost function is supposed to generate a value and then pass it to a function that is it's argument. The function composition article didn't state that at all from what I read. FYI, I'm trying to solve in Python.
I highly recommend codesmith's practice problems on closures, scope, and higher order function! Their video lecture is amazing, really gets under the hood on what is happening when you declare a function, when exactly you are calling it (call site vs call stack), and how to utilize closure (storing variables in a function definition for later access).
https://csx.codesmith.io/units/functions-execution-context
Thanks! I'll check it out!
Remember that you can define a function inside another function definition, as well as pass a function as the output
Can someone give me an idea what I must to learn to solve this kata? I'm stacked, I have no idea now how to solve it.
You need to look for composition here is a good introduction by Eric Elliott https://medium.com/javascript-scene/composing-software-an-introduction-27b72500d6ea
Thanks for the link! I found it quite helpful. I had no idea what to do, but after reading a bit about composing software, I came back here and was able to solve this surprisingly easily.
This comment has been hidden.
This comment has been hidden.
I am facing the same issue. Basic tests are passed successfully, and then I am getting a failure on a test case "Test.assert_equals(basefa, a+b)" I am guessing basef is a dict that maps integers to their string analog, for example basef[3] == "three". In my opinion this violates the initial task which says that functions for each number from 0 ("zero") to 9 ("nine")
This comment has been hidden.
Read the error better:
It's
dividedBy
notdivideBy
This comment has been hidden.
This comment has been hidden.
fixed
This comment has been hidden.
Not an issue.
How can you say it isn't an issue, when I am facing it and I already tried it on multiple machines I am getting the desired output, I can show you the screenshot.
Did you even read the output you posted?
You returned 0.25, expected is 0, because "Divison should be integer division". It's that simple.
It doesn't matter if you tested 100 machines running python 2 or whatnot, python3 uses different operator for integer division, and you can see it in the logs.
By the way, Python Completions: 6282.
Seems like you didn't read what I said, when I said i ran the test on different machines, I did verified the output and it was same as the one that was displayed and I didn't mention python 2, just so you know and that python completion is irrelevant.
LOL! So I guess those thousands of people just got lucky ¯\(ツ)/¯
I'm not sure what you're implying here... Are you saying that those logs you see are fake? Do you think CW code runner interprets python code differently than on your machines? How can you explain your code returning floating point numbers, when only integers are accepted? Spoiler: there's no magic here, what you see is what you're getting.
You're welcome to post your code here (mark it as spoiler) so we can pinpoint the problem in your code, but please stop with this attitude where you know better than everyone. The issue is very clear - your code contains some error, but you're welcome to prove otherwise.
@divy9t: here is why it's not an issue (this is a terminology trouble):
(generic message)
Seems you're "rather new" to cw, so here are some general guidelines about the comments:
Issue
: problem in the kata itself (description, wrong tests, wrong internal solution...)Suggestions
: well, I guess that part is clearQuestion
anything else that is related to you having a problem solving a kata -> that's you, currently.When you post issues:
When you post a question: well, most of the above apply too x)
When you post code, use proper github markdown, so that it's readable.
cheers
EDIT: actually, it's even simpler. As stated by FArekkusu, you're currently just ignoring one of the requirements, so... not surprizing your solution isn't passing:
okay, thanks.
yes devided by as int a//b is going through.. strange
Very interesting and challenging Kata, learned a lot of new things, Thanks for making this!!
Nice! Learned something new today!
Doing it, very fun kata. I am coming to realise that a Test Driven Development approach to this one really helps, and I find it funny because I did not get what made TDD so useful until now!
When I first saw this task, I was completely stucked what to do :D
Very hard kata.
This comment has been hidden.
For me (as a relative novice), this problem seemed really difficult/strange to begin with. However, after understanding it better after som googling, I now think it's an extremely useful kata, and I would recommend everyone being stuck here to hang in there and try a little harder. GL :)
Same here! I didn't know where to start, but someone answered another comment with this link: https://medium.com/javascript-scene/composing-software-an-introduction-27b72500d6ea This kata is challenging, but becomes simple once you apply this idea.
This comment has been hidden.
My tip would be to try and google it, see what you find for other languages, and try to extrapolate to python. Try googling something along the lines of returning a function from a function.
My approach was reading a bit about optional arguments in a function. You could start there and work your way to the solution!
In the description it says : "Divison should be integer division" but there are no test for that case.
I completed this kata but my code and the solutions by others that I've tested(about 4 or 5) on python 3.8 don't work despite working on this site. Also, can someone send me a code which still works on python 3.8 (I'm guessiong it doesn't work because of an update)
This comment has been hidden.
Not a kata issue, it's a problem with your code, you're using global vars and they keep their value between tests. It'll only work with the first test and will fail the others.
Thank you.
Definitely the kind of Kata that forces you to look at the functions in a new way. Gave me a breakthrough moment that was much needed!
I got stuck with this problem. I have a very few ideas about functional programming in javascript. Can you possibly show the solution on codepen or github or wherever you're comfotable with? Thanks in advance.
Golang translation provided
This comment has been hidden.
This comment has been hidden.
Issue with your code, there's an easier way to do it, read this before raising issues next time
This comment has been hidden.
Well done! Everybody has to start somewhere!
Good job mate! where you stand, I've been!
This Kata was extremelly hard for me, nearly impossible. I have learned something new
Language-specific code blocks should not be separated. Also, there's no example for Python (kind of).
Fixed. Thank you for raising these issues.
This comment has been hidden.
I am agree with gxcad. You need to think how to solve it with simple way
This comment has been hidden.
This comment has been hidden.
This was definitely a weird kata for me but it was a nice learning experience! Thanks for creating this.
This comment has been hidden.
This was a really fun kata, lots of ways to solve which leads to a lot of fun reading other peoples solutions.
Thanks for this kata, opened my eyes to a whole new world of coding
This comment has been hidden.
In general, don't redefine functions that are part of the standard because they might be used in the test suite which is exactly what is happening here.
You define an eval function, but the test suite is using eval thinking it is the standard eval function and when it uses your version it borks out.
Just rename yours to myEval or similar.
Very interesting question. I'll have to come back to this.
Awesome kata, props to author for making this (y) ;)
Most of the solutions did not use the integer division requirement, please "Vote up" those which do. Thank you :)
I think division by 0 should return infinity instead of 0.
Fixed (divisor will not be
0
anymore)Wow, you fixed it so fast!
I like this challenge, but I don't like that it requires division by 0 to return 0 rather than NaN or infinity.
Fixed (divisor will not be
0
anymore)Even if there is an instance when there is division by number it should never return infinity. Lets say we examine the limit of 1/x as it approaches 0. As we approach 0 from the right we will get positive infinity but as we approach 0 from the left we get negative infinity. Thus, as we approach 0 we get two different sets of answers and we cannot return infinity. Furthermore, the solution set as we approach 0 contains numbers of ever increasing or decreasing values. So, returning Not a Number is not a valid return. Therefore, the only value that a 0 divisor should return is undefined.
This comment has been hidden.
Good catch, JS version didn't have the extra zero divisor check. Probably my fault again? ;-)
Fixed
This comment has been hidden.
I forgot to change it in other languages. Fixed ;-)
Yes, it is fixed now. But as I am new to CodeWars, could you (or someone else) please explain what happens when test cases are updated and submitted solution does not pass them anymore? Does my solution become invalid? Do I need to fix and resubmit? Are my points reduced? Am I notified in any way that my solution is no longer valid? Thanks!
Your solution becomes invalidated. You can make a new one which passes the tests but it's not obligatory, and as far as I know, you don't lose any honor. You don't receive any notification as well.
There are no notifications but there's a list of your obsolete solutions on your profile page.
Thanks @BattleRattle for this Kata! Learnt something new today almost functional programming.
Python 3.6.0 Version tests for regular division in random tests. It returns failures on floor division. Instructions call for floor division. Example Output:
Fixed
Facing the same issue
It keeps saying "Document not defined"
I have the solve in JS, works in codepen/jsfiddle. This is driving me crazy that I can't mark it as solved...
should it be "eight(divided_by(three()))" on the kata description?
They're different between the two available languages.
Speaking of which, even the top part was unclear about which block belongs to which language, and it's fixed now ;-)
LOVED this kata :). amazing job.
This comment has been hidden.
Description updated
This kata is excellent! I first tried a month ago and couldn't do it. Then I heard about functional programming and I got it.
This is coding gore.
I havn't finnished this yet, but I like how it's testing my knowledge rather than my problem solving abilities. I will figure this one out eventually
I have a solution, but I can't submit it because it tells me that I have gone over my IP limit and to try again in 30 seconds? I wait (for hours even), and try again and get the same error... Has anyone seen this before? I would appreciate any help!
PS - this happens with every problem on Codewars. Started today.
Thank you
I met the same problem in another question...
It's a codewars problem, not a problem of a special kata... (can't submit anything too;-))
Hmmm... So now what? I tried on another computer, it allowed me 2 attemps and now I have the same error again. Effectively locked out of codewars.
Nothing;-)... you have to wait...
For anyone in the same boat, there is an issue opened on GitHub:
https://github.com/Codewars/codewars.com/issues/1191
This comment has been hidden.
This kata was fun, had to put my functional hat on!
This comment has been hidden.
This comment has been hidden.
I have my solution but cannot click submit because the CodeWars Pro modal is blocking the buttons. Clicking X to remove it doesn't work. Chrome Browser Version 54.0.2840.98 (64-bit).
this kata was very pretty fun indeed.
this was a fun practice kata. thank you for providing this, BattleRattle.
This one is so awesome! Thank you gugs. Most of your solutions teach me a lot.
This comment has been hidden.
This comment has been hidden.
Ruby metaprogramming says hello to other languages :D Very nice kata!
Python translation submitted, and it was really fun to create:)
This comment has been hidden.
Loved this kata. Very illustrative of the differences between JavaScript and Ruby.
What differences do You mean?
This comment has been hidden.
Amazing kata. Thank you guys.
rly enjoyed this kata
CS translation provided, with CS will be more fun, like
Kindly go through this tutorial for approving
A solution to this kata came to me in my sleep. (Admittedly it was not the most clever solution, but I passed the kata after dreaming up some code!)
Haha! those are the best dreams!
Very interesting kata. A good example on how to use closures. I'm currently learning functional programming and this was a good start. :)
This was a really nice Kata!
Damn, I'm stuck! Don't know what to do here at all. Gonna lurk around a little bit, I hope I can make this soon.
This comment has been hidden.