7 kyu
Four/Seven
1,798 of 4,545beniolenio
Loading description...
Puzzles
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.
Nice one though you understand it was really easy at the end.
What a great kata, the one kata everyone should try!! Such a simple ask and so many variety in solutions, Really human brain is Awesome.........
This comment has been hidden.
.
For LC: To make things worse, because all asserts are written in a single
it
, it's impossible to see which assertion failed. I do not think that's acceptable.LC issue? Passing Sample Tests, but during Random Tests I get : "expected 7 to equal +0" (??)
Raising issues when one doesn't know is something yet irritating coming from a newbie. What should it be coming from you?
Come on, 7 should equal 4 according to specs, hence it seems something is wrong with the random tests. I scanned some of the other comments in here, it seems there was a bug in the test code for other language versions, swapping the reported arguments, that might be the issue for LC too. I cannot judge that from the sample tests.
Expected 7 to equal +0
means you should have returned0
but your code returned7
. This doesn't give you the input. Not an issue.After some experimentation, it indeed has to do with error reporting, which for LC is the JavaScript test framework. Executing
assertNumEql (a, b)
reports errorexpected a to equal b
ifa!=b
. In the case of LC, the assertion is written adassertNumEql (function (a), b)
, leading to the confusing error message, where the first reported argument is the result of applyingfunction
to argumenta
, which argument is not reported at all.I'll leave the issue to improve error reporting towards the user. I'm not sure how this is typically handled in JS, so this issue can be closed if that's too much too ask.
To make things worse, because all asserts are written in a single
it
, it's impossible to see which assertion failed. I do not think that's acceptable.It is the same in a great amount of katas (and languages). I agree this is really bad and should be improved; when possible the input should be given in failed tests logs; and I would personnally consider it mandatory in languages where printing anything is hard or impossible. Though, this issue is very different from the one you raised initially (and I could not believe you didn't know the meaning of similar failure messages since they are very common on CW).
For me it's the first time encountering any JavaScript error messages... That's why I was a bit careful to not strictly label it as an issue with the Kata, but possibly with the reporting. Maybe I should have been more clear.
Ok. Though, there is a common sense rule: when you are not sure or don't understand something, don't raise an issue, but ask a question. It is possible there is actually an issue behind (once it is clear, then it worths raising an issue for something), but most of times it is not the case. A huge amount of argued issues are mistakes from OP.
Wow. After completing this and seeing the other solutions I can confidently say that I was overthinking this one. It was fun tho. Great kata!
C# translation
Approved by someone
LC translation
Approved by someone.
Honestly no idea how i solved this. Lol. Condifence boost. :D
This comment has been hidden.
I don't speak Haskell :( Is there a way to notify JohanWiltink who posted the Haskell Translation?
Commenting on the original translation suggestion would have worked - the OP gets a notification for that. I did not get one for this, but have been notified through Discord.
The current test is
loc `shouldNotSatisfy` isInfixOf "|"
- essentially'|' `notElem` lineOfCode
.I'll gladly take suggestion on how to fix the test elegantly, concisely and without false positives, because relying on whitespace around it is not foolproof, and searching for
"|"
but not"||"
is not immediately obvious to me.Thanks so much! Please resolve this issue once you've fixed it.
It's not the most elegant fix, but it's a fix. Closing.
We'll deal with
Control.Arrow.(|||)
when someone asks for it. :/I passed with a solution that actually would not work if n == 10.
The "random tests" are not really random in Python, JavaScript, Java, and PHP.
Stop resolving issues without fixing them (or even understanding why something is wrong).
Even according to you, I would have only done that one time, but I didn't because this is a non-issue. I use the random functionality of each language to generate a random integer to test. You seem very convinced that there's an issue, yet unable to explain what in particular is wrong.
FArekkusu is pretty much able to explain what is wrong, he just prefers leaving users puzzled and clueless ;)
BTW, he's right. Your random tests are not random. They always expect 0.
I already provided a code example that shouldn't pass and clarified what was wrong below, but...
Test cases are locked in python. I edited the others.
they aren't locked for PU with 10000+ honor. Wht are the changes to do?
This comment has been hidden.
PU = Power User (CW users with more than 6000 points if memory serves).
Also, what does it mean to be a mod on codewars like you and Blind4Basics?
We make a million bucks a year (then I woke up). Nothing special, at least for me, we have some more responsibilities than the rest of CW users.
Some info on organization of community: https://docs.codewars.com/community/moderation/
Interesting. I wasn't aware that moderators existed—only admins. I'd like to become a moderator at some point. I'm certainly on codewars enough. I've been using codewars since 2017, but I lost my original account because I lost access to the email address associated with the github account. Still need someone with high enough honor to edit the python tests btw.
Can any of you please edit the python test cases? I've posted the full edited python test cases code above so you can just copy and paste it into the python test cases input. I cannot do it because I don't have 10k honor.
Actual and expected values are flipped in Java and PHP.
I can't figure out how to change what each test displays in these two languages. It is just displaying the default for each test framework, so if the default for each test framework is wrong, there's not really anything I can do about that.
Java and PHP use Expected - Actual instead of Actual - Expected order in the assertions (that's how those testing frameworks work, there is nothing wrong with that), so in PHP:
And in Java:
Thank you! I'll fix that.
It's still not fixed tho, you should only resolve an issue report after it's been fixed.
Could you swap sample tests too?
Log number =7
expected:<21> but was:<4>
wtf? by condition it should be 4 if number was 7
looks like java test output is flipped. this is an issue.
This comment has been hidden.
Hi @aviral_gupta14, you should know it is forbidden to display your code like this because people who have not done the kata can see it. I have added the spoiler tag. Also, use proper code markdown to make the code legible.
Your code works other than for the fact you are returning the string 'False-y', simply use the value
False
itself, not a string, because that string will evaluate to as truthy.Also, it is a bad practice to override the built-in
dict
, so use something other than that for a variable name, because otherwsisedict
will no longer work in the way in which it was built in to Python.Soory for that sir i am not aware it that we are not allowed to show our code. Thanks for your help i really aprecite your help.............................. ...........
The "random tests" are not really random in Python, JavaScript, Java, and PHP.
At least in javascript, couldn't they expect a wrong result too?
Indeed. But it seems that author simply forgot to generate a new number on
4
or7
, because the expected result is hardcoded to be0
.randInt never returns 4 or 7. check the definition. And what do you mean not really random? It uses the random functionality of each language.
My bad about randInt, hadn't check your definition. Check this solution: https://www.codewars.com/kata/reviews/5ff915f245ef420001b27754/groups/5ffcfa45803c080001286509 why don't you allow 4 and 7 in random tests? I think he meant the input is random but the output isn't.
I have no idea why that solution works. What am I missing? I don't allow 4 and 7 in random tests because I've already tested for them, and It's simpler and makes no difference at that point whether or not I hard code it to expect 0.
This comment has been hidden.
Ah, so it does make a difference whether or not I hard code it. I'll fix it.
This comment has been hidden.
Ok. I've done it...
I really this kata due to its difficult and challenge of the solution which could be in a various way. I personally think this kata could upgrade to 6kyu at least. For those who have some experienced with programming. I mean not for the beginner.
Absolutely not. A kata is as hard as its easiest solution. Also, kata can't be reranked.
It is common problem in CodeWars. Me as a newbie found it super super Hard, and it demoralize
This comment has been hidden.
Python expects any falsy result, JS expects only 0, PHP says "return
0
", but expects any falsy value. What is this?Languages are different, and I originally wrote this kata in python, for python. I wanted to say False-y and not 0 because in many other languages, functions only have one return type. Therefore, I wanted one to be able to return either False or 0, (because of this it made sense to just say any false-y value).
If php accepts any false-y value, then there is no way to test for equality to 0. The test framework wouldn't allow it. I am literally asserting that 0 is equal to the solution's result in that case. I can change the wording of the kata, if it really means that much to you, but the kata seems just fine to me.
It doesn't make any sense at all. You could ask for
0
(as you should have done to make this kata consistent in every possible language), and it would work exactly the way you wanted.Haskell translation
I wish I could approve this, but I'm not sure how to merge the description with the recent javascript translation I just published.
I've forked it. This should be approvable.
Perfect. Thank you!
This comment has been hidden.
I love this kata. Could you make one for 6kyu?
I like this one, I'm going to look up more "puzzles" in the future. That being said, it feels like it's inescapable from feeling like a "cheating smartass" when solving this, since conditionals are not totally out of the question. Just "if". At least, going by the answers, that's how it seems like.
Approved
This kata is doomed to end up as a mess of translations with unenforceable requirements and tests full of holes created by clueless translators. Things like eval, preprocessor, escape sequences, aliases, macros, available across languages and translators not knowing about them will turn it into a task of "please, don't do this" :/
Plenty of other katas do things like this. If you find a flaw, point it out and it'll be fixed. That's why there's a beta process.
That's exactly what I mean: plenty of kata try to do this, and they fail miserably. No kata I've seen does this correctly, but maybe I am yet to see one :)
But as long as you are able to take care of translations with improper tests not being approved (also after the kata gets out of beta), or your idea is to make the kata easy and accept possible workarounds (however, eval being blocked suggests otherwise), then ok, the kata is good.
No just kidding, it's still the most terrible kind of a kata :)
Thanks.
The idea isn't for the kata to be hard, it's for people to get creative. Doesn't matter what it's ranked. I wish I saw more kata like this. Very few go for making a fun game instead of a boring problem.
Some people will go for the easy points; others will play with it as intended. It's not the usual kata, but it can be a nice playground.
I've done something similar, entirely without enforcing the specified limitation even ( because it was plain impossible there ) -
$DEITY
had to kill some puppies, but a lot of solutions did comply with the restrictions and some were really elegant.Holding this to the same standards you would a "normal" kata may not be justified.
This comment has been hidden.
This comment has been hidden.
Some user came up with pretty clever solution using
eval
. While it is really cool, I feel like it goes agains the spirit of this kata. Maybe you should prohibit using ofeval
too?I completely agree. Sorry to the user that did that before it was prohibited :/
I really liked this kata, but for the first couple of minutes I was trying to figure out what
false-y
was in the description and in the test-cases. Could it be a typo?Maybe it would be better:
P.s: I apologize if i don't understand the terminology (or slang?) i'm not from an English-speaking country :-)
"truthy" and "falsy" are not a slang, it's more of a terminology used in languages where some non-boolean values can be implicitly coerced to a logical value of
true
orfalse
.For example, in Java there's no such thing, because only
boolean
expressions can have logical value, so you cannot write, for example,if(number % 2)
, you need to explicitly writeif(number % 2 != 0)
. In many languages though some expressions yield a non-boolean value, but it can be implicitly converted to such. For example in Python, empty list, zero, or None are converted toFalse
when used as a logical value, thus they are "falsy". Non-empty list, or numbers other than 0, can be implicitly coverted toTrue
, therefore they are "truthy" values.That being said, the requirement of returnin anything as long as it's falsy is kinda poor one and looks like (much too) literal translation of some code golfing task. In Python, you have explicit
False
, so why the requirement of "return anything as long as it's falsy"?Thank you very much, @hobovsky, for a very complete and clear explanation!
I also join the question why not explicitly return
False
, instead of "falsy"-value?It would look like a good practice.
To be honest, because I wanted to have a function that only returns ints, but I understand if someone would want to return False instead, or just leave out a return for a
None
, which is also false-y. Therefore, this requirement.