6 kyu
Odder than the rest
139 of 315JohanWiltink
Loading description...
Puzzles
Algorithms
Recursion
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.
Puzzling to figure out and rewarding kata.
Literally cannot understand any sentence of this kata's description. Really wish this site was actually codewars and not puzzles for people who studied mathematics at university...
It's not that there are 8000 other katas to solve...
Thank you mr replyguy, I am very well aware.
This comment has been deleted.
This comment has been deleted.
I wouldn't consider the concept of odd and even numbers as university level math but ok.
Something doesn't look right with this kata
I wish I can understand it 😂
good kata!
python new test frameworks
That invalidated several existing solutions, which were actually wrong ( or slow ). Strange they weren't caught earlier.
That is a great kata!
LC translation.
Uses a custom numEncoding
NegaBinaryScott
, which uses base-2
but is otherwise equal toBinaryScott
. All negative, zero and positive integral numbers can be encoded, and the encoding is unique if the invariant holds. There is no-0
.This kata contains what we love:
can someone explein the description and what should i do at this Kata(What is the task) i dosent understand this description
Please read existing comments. If you still don't understand, please just skip the kata.
The description was written as it is on purpose; things are not spelled out in detail intentionally.
Yeah, this sucks, I'm sorry.
It's a really nice idea, but made extremelly annoying by the tests and unclear description.
Now I may leave, knowing that this has added nothing to my knowledge and I'll never get back this time, thanks :).
You'll be back .. o_O
Or not, which is fine too. I never thought it would be this divisive. To me, it's just elegant, but people really stumble over the concept.
@dfhwze was right. here I am.
As I received the notification, I decided to give this kata another chance, and I'm glad I did.
At the time of leaving that comment, I had simply gave up and looked at the answers, which didn't really make things much better. I hadn't really understood how to rank negative numbers and the fancy and clever solutions I had seen didn't help much.
Now, coming back to it, with more time and patience, I can see why you chose to make this kata; it is indeed quite elegant. I can now say that my previous remark, saying I didn't learn anything from it, is false, in fact, this did lead me to address quite a gap in my knowledge (I wish I could elaborate, but I don't want to mark this as a spoiler).
I still stand by the tests being annoying. I've never liked having to deal with if the maximum is repeated, return None, it just felt like having to add more lines of code for something mostly unrealated for the problem at hand. One could have just returned the first maximum and the learning you get from the kata would be the same. But I suppose this is mostly a personal matter, and I understand why you chose to proceed this way.
On the description, I still believe it's unclear, but it falls on a sort of dark spot, where there isn't much to do. It reminds me of one of Cat++'s kata's where people kept complaining about the description, but it was a hard choice between a suscinct description and a spoon fed one, where they opted for the former and I believe you did the same. While I don't love this description, I wouldn't be able to come up with something better, so I can't blame you for it.
This may sound like c*** sucking just because you did a translation for me, but I do genuinelly want to retract my previous statement. Even if I was 100% right, which I wasn't, the tone and passive-agressiveness were just unnecessary.
I was having a bad day and took it out on your kata. I'm truly sorry. I hope other can appreciate it as well, even if it takes them a second shot.
If you feel special because I did some translations for you, I have some bad news: you're not special. I have over a thousand translation by now ( with over 800 of them approved ). :P
But I'm happy you now see in the kata what I saw in it when I made it. :]
If you find the tests annoying, there's a sequel with less annoying tests.
There's actually a reason the specs are what they are.
Look at this solution. It doesn't calculate oddity as a number, like almost everyone does; it progressively filters candidates. It's the first solution I wrote ( because this kata started out as a problem, not a solution. and I actually wrote it in Haskell of course, but that may not be as readable to you ), and it's what the ultimate specs were based on.
With this approach, it makes sense to require a unique solution ( well, it did to me :] ), and that's what the spec ended up being.
That's indeed a very nice solution, and yes, JavaScript or Python are way more readable to me than Haskell. I see now why you chose to do it the way you did.
The sequel has a way different feeling than this one. Indeed it's less annoying, but with a harder oddity calculation.
This kata was extremely frustrating, but whith all its traps (including the somehow bad english), I think it is close to what you may encounter in your life as a programmer in a big company. So it the end of the day, t was a good experience.
I found the description for this Kata to be a little tough to make sense of, and after reading the comments I see that I'm not alone. I have re-worded the description slightly so that (at least for me) it makes more sense. Whether or not the author decides to use my description, I hope that it will at least be helpful for others. I also hope that this does not come off as a harsh critique of the Kata, as it was enjoyable to solve. My suggested description is below.
Integrals numbers (i.e. integers) can be even or odd.
For a given number, n, even numbers satisfy the equation n = 2m, while odd numbers satisfy the equation n = 2m + 1, where m is also an integral number. Now, some odd numbers can be more odd than others. An odd number's oddness can be determined using the above definition recursively, where a number is more odd if m is also odd. Even numbers are, of course, the least odd.
Task
Given a finite list of integral (not necessarily positive) numbers, determine which number is odder than the rest. If there is no single such number, return Nothing, null or the appropriate empty value for the given language.
I appreciate the effort, but I'm not changing the description anymore. I do hope people who don't understand it find this though, and I sincerely hope it helps them.
Writing the description for this kata has been an exercise in frustration ( for everyone, not just me ) from the day it was published. I have no illusion any one description will suit all solvers and me ( I don't want to trivialise the kata by spelling out everything, which is the only way to satisfy some people, and anything else fits in some arbitrary position on a sliding scale. I'd like to let it rest. I'd have liked to put it to rest four years ago.
nerd
proud nerd
After reading all comments and having solved this kata, I would have to agree with the kata author that ALL information required to solving this kata is in the first paragraph of the description.
This comment has been hidden.
Added the
recursion
tag. Thank you for the suggestion.Codewars needs a better range of options than just Very, Somewhat, and None. At a minimum, the addition of "this is infinitely dissatisfying; the mere existence of this Kata has made my life worse".
This comment has been hidden.
Surely it is a real hint? I do not see how it would fool users?
This comment has been hidden.
It was intended to be a mouse-over hint. Rendering may be iffy on mobile. :[
;)
The intro text is badly written and the premiss not clear.
What is concretely badly written?
For some reason, the kata has the
puzzle
tag.Look, I'm sorry, but this description's a mangled mess. I know you're trying to be clever but cleverness is the enemy of education.
Great and original Puzzle Kata. Thanks @JohanWiltink!
Great kata. Listen to this while finding a solution.
Real life coding challenges are defined whith less clear requirements most of the time.
It is even possible to extend this by thinking that 18 is odder than 24.
I could not stop hearing in my head "Ground control to Major Tom..."
Why 0 is odd?
Read the posts below asking the same.
The description is hard to understand, am I missing something?
No. You'll actually have to read it, and think, and maybe try some things.
The description could have been written in pseudocode with endless examples, but it was not, on purpose.
The kata has surprisingly low "joy" percentage - two hints - analyse "-1" very very deeply and why author of the kata mentioned about recursion.
Fun fact: I was writing the kata and I stumbled over
-1
myself. I had not even anticipated that behaviour.The description already mentions both those things, but the low joy percentage may be explained by people not being used to "deep" consequences of simple instructions. Go is also a less popular game than football. :]
Anyway, thanks. At least I had fun composing it.
According to the Factor tests, a single 0 is expected to give 0 as the oddest number, whereas according to the definition, 0 is even, is not odd, so certainly cannot be odder than the rest, as only odd numbers can be odder. In my opinion therefore 'null/Nothing/false' should be the expected answer, not 0.
This is the expected behaviour. You misunderstand "odder than the rest".
( See also @chrono's question thread, and for more explanation @b1ts' suggestion thread, below )
No.
Don't blame it on misunderstanding on my part (or blaming others for just not reading well enough), or shift it to other threads, you just wrote an ambiguous description, and you don't want to or can't solve that, while nonetheless marking such issues as resolved. That's dishonest.
You specifically describe that "some odd numbers can be more odd than others" (i.e. 'odder') and "Even numbers are just not odd" (hence can also NOT be more odd than others i.e. 'odder') and "determine the number that is odder than the rest" and "If there is no single such number, no number is odder than the rest; return Nothing, null or a similar empty value."
So, according to your description, only odd numbers can be odder, never even numbers. Furthermore, you instruct to determine the number that is "odder than the rest" in a list. In itself that description is already inconsistent for less than two numbers. (Compare for instance with the 'less than' relation) But even if we ignore that, in the list { 0 }, there is no such number, because even numbers can never be odder. Then you describe, that if there is not a single odder number, Nothing/false should be returned. There is no single odder number, hence Nothing/false should be returned.
Your move.
"Even numbers are just not odd" means that even numbers' oddness always equals
0
, not that it's unknown/undefined. The oddness of0
is0
, there're no other numbers in the list whose oddness is>= 0
so the result should be0
.That is not what the description is saying. "Oddness" is not even defined.
The problem is that the term "odd" is redefined. Normally, an even number is not odd, so an odd number is kind of "odder" than an even number (that is, it can be assumed so in non-strictly-logical contexts). Here, the definition of odd is updated, so it can be argued whether prior knowledge is applicable. So after "Even numbers are just not odd" there's a question if odd is odder than not odd or there's just no relation. So I guess it can be understood either way...
I am not willing to change the description, and I have already added the
puzzle
tag.Please just vote
Unsatisfied
, and stop arguing.Even though the desription is not clear what was meant, I believe the author is, in this instance, not at fault.
0
is odder than all of[]
because it's vacuously true. But I know you are not all logicians, so let's see what some programming languages have to say:@dramforever But we're assuming here that
0
isn't in the domain, so it's more likemaximum [id]
->No instance for (Ord (a0 -> a0)) arising from a use of ‘sort’
.Except
a0
does have anOrd
instance. And0
is in the domain. Somaximum [id]
will returnid
.Whether 0 is in the domain is discussed above and is still unclear, I was only saying that the vacuous truth didn't seem to solve the problem in case the relation wasn't defined for 0.
I don't disagree. The way I read it, 'Even numbers are just not odd.' means 'If x is not even, then x is not odder than anything'. As I said 'the desription is not clear what was meant'.
I can see that the author wants to encourage logical thinking, but making everything vague isn't working and is never going to work...
Fortunately, nothing isn't anything.
If the description isn't clear, please suggest a better one. Please keep in mind: no pseudocode, no endless examples, and examples limited to input and output.
The description isn't clear, there's no if. If I finish the Kata by deducing the actual problem by basically looking at failed examples, I'll give it a try to come up with a better description.
This comment has been hidden.
Apparently you know the One True definition of "odd". That definition precludes comparing oddness, because it only allows for odd and unodd. So when the description starts talking about "more odd" and "odder", shouldn't you be triggered to start thinking outside the box?
I appreciate your suggestion, but I'm not taking it. I'm not going to spell out the task like that.
Apparently you think you can "informally" create your own definition of odd, despite the whole of the world thinking otherwise. https://mathworld.wolfram.com/OddNumber.html
That's not called "thinking outside the box", usually people use a less flattering description for that.
Your description really doesn't make sense:
Suppose we have two odd numbers, n1 and n2, such that n1=2m1+1 and n2=2m2+1. So far so good. When exactly is one "more odd" than the other?
"Now, some odd numbers can be more odd than others: when for some n, m is more odd than for another's"
Mathematically speaking, if you say "for some n", you fix n. If you have two numbers, n is not fixed, but different. The sentence therefore doesn't make any sense. What's left is to try to infer what exactly is meant by looking at some examples. Unfortunately, in the language of my choice I only see very little examples.
If you want to improve the description, at least write it down mathematically sound.
You're not supposed to read it strictly mathematically. The example tests are to the best of my knowledge the same in all languages, and they are intended to be.
And in short, I don't want to improve the description. I have no intention of providing a pseudo-code solution in the description, and it's got a
puzzle
tag. Closing.You're not supposed to read it "strictly" mathematically? Sorry, but that's a lame excuse, if you employ mathematics to describe the problem. And I'm not the first one to remark the description is just unclear.
Please consider modifying the description to include some of the following
2m + 1
is odder than2k + 1
if and only ifm
is odder thank
; otherwise neither of two numbers is odder than the other'This is a super fun kata, I had a few ideas and they all worked but had to be modified somewhat when I actually tried them. This actually fun kata could be so much better if accompanied by a good description.
Super fun..gem of kata :)
Thanks. :]
Generally, this kata is not getting much love - to me, you're a gem of a code warrior!
Well, it is pretty clear what happens with positive integers, but when it comes with negative .... -1 is more odder then -31. Why? I we count to 0, -31 has 5 "points" and -1 has 1 "point".
-97 is more odder then 71. why? -97 has 1 "point", and 71 has 3 "points".
So we can think that all negative numbers are more odder then positive.... No. 3 is odder then -3.
-65 is more odder then -95. Why?
You're counting "points" wrong.
n = 2m+1
holds for negativen
just as for positiven
.Thanks, Solved it!
I think this one deserves the 'puzzle' tag. If the chaos in discourse isn't enough, the ambiguity of description is calling for it :>
I realise it looks simple when you understand it, but getting to that point isn't clear-cut, and the hint gives more questions than answers :D
Isn't there anything else that can be done, without spelling out the solution in pseudocode or having solvers reverse engineer endless examples?
This is not intended as a puzzle.
But the only question that did not result from not reading the bloody description was if integral numbers had anything to do with antiderivatives.
I may just give in and add the
puzzle
tag. But I feel I may then as well remove the description entirely.OK, thank you for your suggestion, and I'm not taking it.
Still no suggestions at all how to improve the description.
This comment has been hidden.
Sorry for not giving a clear example, been quite busy lately, but
fenring76
expressed very well what I wanted to say :P I strongly echo points #1 and #3. It just felt like one of 'thinking and testing' katas, hence the suggestion.(1) Thank you for your suggestion. Unfortunately, I consider that pseudocode, and I have no intention to specify the problem that way. I'll just add the fscking
puzzle
tag and hope that gets it over with. ( My patience is wearing a bit thin. )(2) and (3) What is the maximum of
[5,3]
? What is the maximum of[5]
? What is the maximum of[-Infinity]
? ( Just so we're clear:5
,5
and-Infinity
. ) If all you have is a hammer, everything is a nail.Related, what is the factorial of
0
? Why? I'm not asking for an odd number, I'm asking for the number that is "odder than the rest". Alice has murdered more people than anyone else in the room. Have a look at the behaviour of JS.some
and.every
on empty lists; it is mathematically sound. If you think it's nonsense, we'll just have to disagree. ( Also, I'll have to think you're wrong. Sorry. )Would it help to suggest to think of "even" on a
0
or1
scale, but "odd" on a gliding scale from0
to .. well, figure that out? If that is part of the confusion, I'm willing to clear that up. That's about as far as I want to go though; if the description makes sense after you've solved the kata, it wasn't wrong when you had not yet. It may be vague, but I really, really don't want to spell everything out and have people follow a recipe instead of think. ( And I'd also like to avoid people reverse engineering examples, and giving the psudocode in examples. )(4) Is it really so hard to apply
n = 2m + 1
to any negative number? Or just the one from the hint? ( That tripped me up for a minute when composing this kata; I had not anticipated that behaviour. ) Assuming negative numbers are, or will behave, the same as positive ones is .. just a wrong assumption.(side) I'll have a look at your solution and the
[0,1]
thing. Thanks for the heads-up.@fenring: Well, you definitely had a right idea when you wrote that solution.
I don't do Python, but I wrote a similar one in JavaScript, if you can read that, and in Haskell, if you're feeling masochistic.
And then I actually forked your solution and wrote Python. And it worked! :]
The big difference is the initial value for
odd_value
. Setting that to-1
means you can just use logical values elsewhere. I haven't factored outlistToMaybe
like I did in JS and Haskell ( I couldn't have, either! Not enough Python. :P ); what I mostly did was take special cases out, because they weren't so special after all. ( Perfection is achieved, blah blah. We're closer to perfection. :)Your solution indeed fails
[0,1] -> 1
( the fork passes it ); that testcase, or something like it ([ 0, any once odd number, possibly some even numbers ]
), is generated effectively never randomly. I'll just add that as a fixed test ( 11 times. ugh ).If nothing else, a
puzzle
tag will get us all to shut up. :DIn any case, fun kata, thanks. I'm off to rewrite my solution.
I hope so .. though I did empathically not intend to write a puzzle.
You're welcome, and happy coding ^^
why 39 is odder than 31? 39 - 39,19,9,4 -31 - 31,15,7,3,1
31 or -31?
I transforme negative to positive numbers, they should have the same odd order. for n<0 in my oppinion should be n=2m+1 or not?
n = 2m+1
holds for negativen
just as for positiven
. So,No.
It would be helpful to have more samples, especially input consisting of arrays of different sizes.
I am getting the distinct impression people just don't want to read the description and prefer to reverse engineer examples.
Thank you for your suggestion, and I'm not taking it.
If anybody has specific suggestions how to make the description text clearer, I'll be happy to hear them. Please keep in mind the description is meant to be actually read, and spelling out the solution is not my favourite way of having a clear description.
Sorry, I don't even understand the subject.So Sad! QAQ
Agreed, I have no clue what is being asked. Also... What does n represent? What does m represent? Does integral mean anti-derivative or a number that is an integer?
@Johan could you also explain what it means by "odder"? That completely stumped me.
"Odder" means "more odd" - odderwise, see the description
n
is the integral number itself, that is, the integer ( no anti-deriving here )m
depends on the particularn
you have in mind - see the descriptionSo, essentially for each iteration the n becomes the resultant m of the last iteration?
That's extremely ovbious, how can something be more odd? That's the ambigous problem of the description, for me
"Recursively."
Yes.
Odder: "when for some
n
,m
is more odd than for another's. Recursively."Sorry, I still don't understand. "more odd" does not make sense to me.
This comment has been hidden.
A million is a lot. Right?
A gazillion is a lot. Right?
Now compare their "lotness" - their size.
You can't ( gazillion isn't an actual number ), so we invent some way to compare them anyway. The outcome will depend on what we invented; there isn't a priori an obvious way.
3 is odd. 5 is odd. Compare their oddness. Normally, it's an either / or, black / white, odd / even. All odd numbers are equally odd. But we can invent something non-binary, fractional if you will, and compare their oddness anyway.
This comment has been hidden.
Aha. So this kinda is a puzzle, then, right? :P You have to figure out how to do this "comparing oddness"... :yum:
Well .. there are some strong hints in the description ..
But hey, aren't all kata essentially puzzles?
This comment has been hidden.
Appreciate your trying to help.
If people want to solve the problem, they can do those steps themselves.
Apparently you missed a notification -- Ruby translation EDIT: Also CoffeeScript translation
No, I didn't. I just have very unreliable internet access ATM. I'll have a look when I get home.
Both approved. Had to fork Ruby for merge conflict. Ta! :]
Maybe it's just me, but why should
[0]
return0
?0 is odder than all the other numbers there.
.
Python translation
Approved. Thanks!
Oh no... I made a mistake (my reference solution was calling the user's solution), please approve this fork.
In that fork, you took the example out of the description.
I've just edited the kata directly.
How in the world did I do that? I have no idea what I did... :/
CodeWars apparently went back to the original description for you.
None
was gone as well ( see the diff of the fork ).Never mind, it's fixed now. ( I hope. :P )
Codewars just acting up again... :/
Having recently started with publishing JS katas using chai for testing, I recommend wrapping each individual test case in an
it
function. This way subsequent tests continue running even after the first failed test. If you keep track of failed tests with a counter that terminates any further test runs once a failure threshold value has been reached, it can allow users to get a better understanding of why their code failed by examining more than one test at a time.This is a general suggestion, not specific to this particular kata.
Point taken.
If the description is so unclear that people will resort to testing by example, I do hope they will ask for the description to be clarified though. What did you find unclear and how would you suggest to improve it? ( Descriptions are not intended to be guessing games IMO. Unless they have the
puzzle
tag. :yum: )At first glance I wasn't clear on what was meant by one number being "odder" than another in the context of this kata, but the Description does define it adequately.
OK, thanks. I was a little worried there; you weren't the only one to find it confusing.
I thought it was confusing too...
The Description should include the test constraints so users can plan how to write their solution. This kata appears to require some level of performance, but does not indicate how performant a solution needs to be.
This comment has been hidden.
Ok, confirmed it's not a matter of performance. The task wasn't entirely clear, so I had to infer based on test results for clarity. Marking resolved.
This would really benefit from some more useful examples in the description that illustrate how to compare two numbers whose 'm' is odd through a few recursions -- especially since the tests don't display so it's hard to see what's failing with your code.
Do you really think I should spell it out like that? Does the
[1,3]
example not make that clear ( enough ) ?I may not be objective here - I know the solution - but I have trouble seeing how people fail to understand this. Which is the usual author's myopia of course.
Would it help to add a
[3,7]
example with just the solution, or should I write out the recursive steps? The latter feels like completely giving away the solution ( and this is not intended to be an 8 kyu ); for the former, you can print inputs in the fixed tests.This comment has been hidden.
OK, valid points.
How odd are even numbers? Well, not. But some might be more partially odd than others. ( That would throw off the bit-shuffling people, but that's their problem. :P ) However,
It's a fun thought, and there may be a sequel in there, but for this kata I'd like to stick to only ranking odd numbers as just "odd" or even more "odder", and not rank even numbers on their oddity. I'll add a line on that somewhere.
But I'm hesitant to dissect how
7
is more odd than5
, because I don't want to give solvers a description in practically pseudocode, and it follows from "even numbers are not odd." Also, reminding people that0
is even really is overkill in my opinion. If that helps you, you're just not my target demographic.If you want to see inputs, outputs and expected values, just print them from your solution. If you fail a test, the expected value is shown. ( It is, isn't it? ) ( And if you don't fail,
expected == output
:)This comment has been hidden.
This comment has been hidden.