6 kyu
Find The Parity Outlier
21,511 of 222,528obnounce
Loading description...
Algorithms
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.
This comment has been hidden.
I have two pieces of code on my machine (one iterative and one recursive), both of which work perfectly well in all cases. However, weirdly, the recursive one fails on the test provided here, even though the arrays for which it fails actually work just fine on my computer. No clue what the issue can be.
Without seeing the code we have no clue either.
This comment has been hidden.
heyy why does it work when i try but doesn't when I attempt?
Failed asserting that null is identical to -3523.
and when I try it passes all the tests???
When you hit "test", your solution is only run against the sample tests that you can see at the bottom of the code editor. When you hit "attempt", your solution is run against a much larger set of tests that aren't visibile to you. You can always print the input to the console to see what the inputs are though.
Thank you a lot, I was not aware of that!
8kyu
This comment has been hidden.
Maybe you misunderstood the task. The parity shouldn't be based on just the first element, it could be any element (or all of them really).
Any suggestions on how to fix this?
Uhh, I'm not sure. Don't focus on the first number. You could count how many even and odd numbers there are, and go from there.
This comment has been hidden.
Please don't post solutions in Discourse, it's forbidden.
i tried the append function CORRECTLY and there was an issue with it
The problem isn't with append, you logical conditions are wrong. That's why append isn't called at all.
Java: I have done this problem on an IDE and it runs perfectly. I've inputed all different scenarios, and I still end up getting the expected result. My test over here passed, but when I try to attempt, I am getting an error. Is anyone getting the same problem by any chance?
You're phrasing this a bit oddly - "the same problem" - yeah, other people have written incorrect solutions and have failed tests. But knowing whether other people have failed tests, that's not useful information, so you probably mean something other than what you said?
I have tested my code with all possible scenarios and consistently received the expected results. My concern is that while the code runs perfectly in my IDE, it fails upon submission. I’m curious if anyone else has experienced a similar issue. Hope that clears it up for you :)
Producing right answer for some cases and wrong answer for other cases doesn't seem concerning to me. That's normal for incorrect solutions.
well, the tests are pointing out some scenarios where wrong answer is being produced. did you test those?
This comment has been hidden.
.
I got the result
Did you? And did you hit "submit"? Because your profile says you solved 0 kata so far.
The tests after submission should have all even or odd numbers except one (outlier) but seems to have multiple.
int[] array = {2, 6, 8, 10, 3, 3, 2, 6, 8, 200, 700, 1, 84, 10, 4, 1, 17, 6, 8, 10, 6, 12, 24, 36, 36};
This is one of the inputs. 3, 3, 17 are all odd. Should be only one.
I cannot reproduce the test case you're showing. It looks like you're showing an input of multiple tests combined.
Try changing your logging method to something like:
It should become clearer after this.
https://www.codewars.com/kata/5526fc09a1bbd946250002dc/discuss#5e77cfb4641432003621d6f8
[Kotlin] I am assuming there is atleast one solution exist in the given testcases. As it was given there will be atleast 3 numbers in the given input.
In my program trying to Kotlin's builtin function integers.find() returns null only if its not found.
one of the testcases must be wrong.
I am too using Kotlin and am using filter and I am getting a list of size 0. :( What am I doing wrong. Pls help. I am specifically getting error under Test fixed thing.
Hi, i'm new in this universe, I got this messege with complexe test : Expected: 1, instead got: 0 I understood that there is case that the code doesn't work but how can I get the complexe array to test them in local myself ?
maybe you can console log the array somehow somewhere so the array shows up in the logs when the test case fails
thanks a lot !
Hey guys, anybody got a tip on how to optimize the search?
Im using js
You don't need to optimize your solution. It just runs into an endless loop if the outlier is negative.
Thanks man
Hi I am doing this on Lua, and I have a problem with this question. So I am getting multiple odd and even numbers when I use the table "integers" and I'm wondering if that is even the right table to use in this situation? :0 *It's most likely my falut
It was my fault but I suceeded (: check out my solution if you'd like :D
This comment has been hidden.
There is no such fixed test, your observation is incorrect. Which is to say, you are printing something other than the fixed test or in some other way misinterpreting what is happening.
One might (I would) argue that the test framework is producing misleading output. But it's also in no small part got to do with how you are displaying the arrays - you can't tell where one ends and another starts when you produce no output between arrays, instead continuing where you left off.
I think there's a bug in this challenge. Expect 6 to equal 17? Idek how that would be possible. Any ideas (js)?
There are >64,000 correct JS submitted so far; it is extremely unlikely that the tests are bugged.
I also can't get your solution to fail. Perhaps you solved your own problem already?
The error message just says that you returned 6 when you were supposed to return 17
in dlang: tests work, but when attempting to get the solution, it gives me an array with only odds or only evens.
It's not true. Your solution has a (somewhat subtle) bug.
Bugs in your solution are not a kata issue.
This comment has been hidden.
the math.
try this test:
values = [2, -6, 8, -10, -3, ]
your code returns
-1
for this test, but clearly the answer should be-3
This comment has been hidden.
C:
fork fixing those
Merged.
python new test framework
Approved
This comment has been hidden.
I think it's because you're only looking at index 0 to determine if it's a mainly odd or even index.
This comment has been hidden.
Don't post solutions in Discourse please.
This comment has been hidden.
This comment has been hidden.
hello all.. in "More complex tests" - i get error - "expected 6 to equal 17".. why that?.. tnx! (I write in java script)
Read this: https://docs.codewars.com/training/troubleshooting#print-input
Dont forget, this is Vector (not array), and it can contain negative numbers
This comment has been hidden.
This comment has been hidden.
The code you showed above is invalid, it introduces UB due to use of an uninitialized variable (
result
is uninitialized and not written to, if thearr
is empty). The passing tests are a result of handling the UB by compiler. It is difficult to write tests in a way to protect against such problems (it's UB after all), and I am not sure if this issue can be universally fixed.This comment has been hidden.
Please use proper code formatting when posting blocks of code.
Your solution has more than one problem:
c = sizeof arr / sizeof arr[0];
is wrong. It;s not how you get a size of a vector, and it returns wrong results.{1, 3, 0}
?You need to fix this bug. It's not a kata issue.
Thank you very much for timely help! I'm just learning and don't know how significant are the differences between array and vector. Kata is good for practice.
This comment has been hidden.
This comment has been hidden.
Please use the spoiler flag and appropriate formatting when posting code. See https://docs.codewars.com/training/troubleshooting#post-discourse
You're not returning the appropriate value:
The error messages you're getting also clearly indicate what you're doing wrong.
thanks for looking into it, i'll use spoiler flag from next time. I have fixed it, the problem was I was returning an array not the value so I returned array[0] and array2[0]
This comment has been hidden.
No random tests in C#
Assert.AreEqual
should be useddone (had to fix the author's solution too)
All tests passed BUT 1 should equal 2 What it's mean?
That your code returns 1 instead of 2. Print the input: https://docs.codewars.com/training/troubleshooting/#print-input
The error is not in my answer. When I press Attempt, it says: Well done dude, you passed the tests perfectly, but 1 should be equal to 2 (this is written on a separate line). This moment is not specified in the condition. I don't understand what he wants from me.
There is an error in your solution, it fails for this test case:
test.assert_equals(find_outlier([1, 2, 3]), 2)
Where does it say that " Well done dude, you passed the tests perfectly"?
OP solved it, closing
'expected +0 to equal 1'
Anyone can help?? Couldn't understand this fail.It works on my machine lol
your code is wrong because it halts as soon as it finds an even number, I suggest you re-read the directions more carefully. Also, it can only
work on your machine
in this case becauseyour machine
lacks sufficient / correct test coverageThis comment has been hidden.
Hello, @arthur2001
(I didn't have a query, I was resonding to the
question
posted by @eeryz)I have already solved this kata in eight languages in a variety of ways, including recently a method with an early break, but thanks for your input nonetheless!
expected:<3> but was:<0> What does it means? can you help me?
It means that your code returned
0
but the correct answer would have been3
.I made some progress but I still need to figure out the solution where I can return the even or odd number not the module of the number.
I am implementing with Java but looks like the testcase "test" does not follow the description. There are more than 1 odd and more than 1 even numbers at the same time, or I missed something? Anyone help ? Ty
Cannot confirm, all tests in Java have exactly one parity outlier.
hey yall, I implemented a slotion that works with when I click test. when I attempt to submit the solution some tests fails with output: any one got any idea? testBasic Failed asserting that -1 is identical to -44. Completed in 0.53ms testRandom
Hello makarovirsoy,
Maybe you copy you code and send it here so that people in the community can see what it is you are trying to do and help you out.
The description should be clarified.
It should read something like: The array is either entirely comprised of odd integers and a single even integer or entirely comprised of even integers and a single odd integer.
Currently it reads: "The array is either entirely comprised of odd integers or entirely comprised of even integers except for a single integer N."
If one reads that "or" as exclusive, it means that the only time there will be an outlier to return is in the case of the array containing mostly even integers.
how do i post my solution so it can be seen by evevryone?
Your solution is now visible on "Solutions" tab, and you can grab a link to it and share the link.
This comment has been hidden.
i'had some problem with if..else, but brute forced it anyway. :)
This comment has been hidden.
Hey @Philosophist - regarding the "fastest speed" feature for katas, it is a topic that has been discussed quite a bit: there is a dedicated Github page/issue where you can see the various comments:
https://github.com/codewars/codewars.com/issues/959
in particular this explanation by @kazk (site admin) here:
https://github.com/Codewars/codewars.com/issues/959#issuecomment-612690341
there are also many well-informed comments by advanced users explaining some of the difficulty/pitfalls of software testing (I learnt a lot from reading the thread, as I'm not very knowledgeable about this area).
Happy reading!
I need a line to do this task. :)
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
3 None should equal 3 Log 11 None should equal 11 Log 160 None should equal 160
wth my program is doing what it's supposed to do , can someone explain me this ?
return the result instead of print it
i just discovered it , what's the difference between them two ?
This is the way.
(the site tests your function output to pass the kata)
Help, whata kinda test is that?
Test1
Test Failed
Expected: True
But was: False
https://docs.codewars.com/training/troubleshooting/#print-input
thx
This comment has been hidden.
https://docs.codewars.com/training/troubleshooting/#print-input
Thank you for your answer! Turns out the tests are wrong. In the directions for that exercise we have: (...) The array is either entirely comprised of odd integers or entirely comprised of even integers except for a single integer N.(...) but in the textFixed log I get that input is: 2,6,8,10,32,6,8,200,700,1,84,10,417,6,8,10,6,12,24,36 in which there are two odd integers. Moreover I get a message saying: expected:<17> but was:<6> and there isn't a 17 in that input! The rest of the input is even so how come the answer is 6? I would be glad for helping me further with this issue. Or maybe changing the exercise if it is ineed with some errors.
The tests are fine, you're printing the input of more that one test after the other there.
Thank you. That was a headscratcher for me. I am really thankful for your help.
It gives the expected when i compile it and run in my machine but in the codewars it returns 0? why
It's extremely unlikely that your code returns a different result on your compiler with the same input.
See there if you can find some helpful tips: https://docs.codewars.com/training/troubleshooting/
Hi! I think I have solved the exercise correctly but when I try to send it I get the following error when executing the code with a very large list (10000000)
"Maximum buffer size reached (1.5 MiB)"
This usually happens when you have left a "print" statement (or whatever the equivalent in your language is - displaying to console/stdout etc.) somewhere in your code.
Try removing anything that logs output to screen, it should work then.
Hi, I passed the test but when I try attempt it shows "No value present", someone know what that's mean? Because arrays have lenght of at least 3.
Which language, what's your code? Read this: https://docs.codewars.com/training/troubleshooting
Ok i Fixed my problem, It's because I used modulo and it's working diffrent for negative numbers
D translation
approved
Updated Scala 3 translation
.
This comment has been hidden.
Please read this: https://docs.codewars.com/training/troubleshooting/#post-discourse
This comment has been hidden.
This comment has been hidden.
Why cant you check the number if it's negative?
This comment has been hidden.
Just put odd = [] and even = [] inside the function and it will do the job.
If the input array is like this
int[] integers = new int[] { -1721, 169, -32127, -81, 1014, -641, };
Then some of the solutions in the list give an incorrect "outlier" and some of the solutions throw an exception.
The last element of your input array is "" - this could throw an exception in some cases.
No, that's a typo because I shortened the array. Take this correct input array int[] integers = new int[] { -1721, 169, -32127, -81, 1014, -641 }; and try test solutions https://www.codewars.com/kata/reviews/56fc1564f8e03b4b9a000027/groups/57606272b2a8d607ee0005d0 https://www.codewars.com/kata/reviews/56fc1564f8e03b4b9a000027/groups/576e7cd74c3204ffb0000635 https://www.codewars.com/kata/reviews/56fc1564f8e03b4b9a000027/groups/621af629f201850001f1f72f return wrong outlier 169
https://www.codewars.com/kata/reviews/56fc1564f8e03b4b9a000027/groups/5bf3b3feff398649e90006d8 https://www.codewars.com/kata/reviews/56fc1564f8e03b4b9a000027/groups/59621eff72266767b3000042 throws an exception System.InvalidOperationException
and some other solutions
This comment has been hidden.
Factor translation
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
if your question is why not return
evenNum
, it's becauseevenNum
is...well an arraythe kata requires you to return only the integer
Thatmakes sense haha thnx
my code returns the right numbers, but the codewars platform is saying at() is not a function
what gives?
The at() function is in Node versions 16.6.0 and above, which codewars doesn't have
do the program has to work for either odd-numbers array or both odd-numbers and even-numbers array?
The kata would make no sense if the numbers in input had all the same parity.
i have sloved it in 3 hours lol
This comment has been hidden.
This comment has been hidden.
Tests test expected [ 0, 2 ] to equal 1 Completed in 4ms Completed in 8ms
lol really? the outlier in this array is 1?
Why are you returning an array?
Whenever I attemp any code, a time-out error appear to me.
Execution Timed Out (16000 ms)
Can anybody help me?
Hi. This is not an issue (= a bug in the kata), but maybe a question. You need to find a more efficient approach.
Test Results: OutlierTest test expected:<-3> but was:<2> Stack Trace Completed in 8ms Completed in 19ms
I can solve a one issues if even i put hte chekker to that my solution return nothing, but all another tests is accepted. Language Java 11. How can present my code for check where i do wrong?
Hi. Your code not working is not a kata issue. An issue is a bug in the kata. You may find some help in the documentation: https://docs.codewars.com/training/troubleshooting/
This comment has been hidden.
Print the input.
It would be nice some test case where inputs array contains hundredthousands or millions element.
SyntaxError: Unexpected end of JSON input
Copy your code, click reset, try again (see if that error is gone), paste your code, try again (see if that error is back). I can't reproduce it.
This comment has been hidden.
That's a problem with your code, print the input to analyze why it fails. Read this: https://docs.codewars.com/training/troubleshooting/#print-input
This comment has been hidden.
As you can see from the message, you return a
NaN
, but the expected value is an integer (105313274). Are you sure you initialize your variables correctly? For examplelet myValue
instead oflet MyValue = 0
.This comment has been hidden.
This comment has been hidden.
or I misunderstood the task, or there are errors.
Testing for -121544474,101718745,-9164305,38739403,108381521,663195,-142162057 expected 101718745 to equal -121544474,
Testing for -31201857,-198725082,-135449818,76231552,-61346266,170374456,-187096998,-52840102 expected -198725082 to equal -31201857
Testing for 16532554,-174960306,-128761317,162885038,148383756,-47331116,-20826474,-85229744,150678222,56060694,-197391596,-143951026,-12608354,67716376,161471306,-33156290,-10481932,-160271554,-30552070,132707812 expected -174960306 to equal -128761317
Simple tests expected 0 to equal 3 Completed in 2ms More complex tests expected 6 to equal 17
I think you misunderstood the task. Each input is an array (or other collection depending on language) of numbers. Among those numbers, either 1 will be odd and all others will be even, or 1 will be even and all others will be odd. You have to return the odd one out.
I understood the same way, above I gave the text of the failed tests, they show that it is expected not quite what you and I understood from this task, almost all the tests pass correctly for me, but these tests do not work as I expected.
Okay, in that case:
This means that your code returned 101718745 as the answer. That was incorrect, as -121544474 is the only even number of the set. The same goes for all of the other errors you posted above.
Expected
x
to equaly
means that your code returnedx
and it should have returnedy
Not a kata issue.
This comment has been hidden.
Check out other solutions in Solutions section and you can make the same question there under your code. Please don't post solutions in Discourse.
Thanks! Still getting to know the rules and culture in here - will stick to the Solutions and discuss there in the future :)
I really Enjoy this Kata :}
My code is failing the first test but I think the first test is incorrect. It should be returning -10 but the code compares it to 3.
Please mention the language next time, it's C#, let's see:
The only odd number is 3 and the other numbers are even, the right answer is 3.
This comment has been hidden.
Yeah but what's your suggestion?
This comment has been hidden.
None it seems. Please don't post solutions in Discourse.
This comment has been hidden.
My code works on all the tests when I run it on my machine in an IDE but it doesn't seem to work when I test the Kata on here? Any help?
I'm having the same problem
did you figure out what was causing it?
language?
I'm using Javascript
This comment has been hidden.
Thanks, I noticed this comment and resolved my first 6kyo kata !
Why doesn't the count method work if it's a negative value? like you'll just return 0 not a negative number in the test cases
This comment has been hidden.
cuz 11 % 2 == 13 % 2 but 10 % 2 == 4 % 2) think about
OP solved it, closing
This comment has been hidden.
If you're not sure why something is happening, post instead as a
question
. Anissue
is reserved for when there is a provable problem with the kata.Make sure you know your input, have you printed and done type checks? Also, this may help: Troubleshooting-your-solution
I'm using "keep_if" and I'm returning the correct value, only it's still in an array, i.e. a single integer in square brackets []s. How do I get rid of them?! Cheers
pop?
That's just returning a wrong number. I assume that my using 'keep_if' isn't mutating the array and the 'pop' is just removing from original. I might need a new approach. Thanks though!
where should i start im a noob so i dont understand anything.
Start with white katas (8 and 7 kyu) and read the docs: https://docs.codewars.com/
Im new too, but how i plan on learning is watching videos on the very basics of the language of my choice (mine is c# but python is probably the best to learn from). Then once you have the very basics down, like variables, loops, functions etc, then do the white katas. When ur solving problems, you should have a word doc or notepad open to write down how you would solve the problem by breaking it down into steps. This way if u get stuck, you can just figure out that one step, rather than trying to figure out the whole problem at once. Once again, im new too so if anyone more experienced has a better way to learn please share. I could use the information too lol.
COBOL translation.
approved
Can we assume that [2,1] returns 1 , in case both counts are equal we can give added weightage to the odd being the outlier?
No. Please read carefully the description.
Yes sorry, my Bad
I apologize if this is the wrong area to post this - I'll redirect if needed. After clicking attempt, the following test case failed: [3, 7, -99, 81, 90211, 0, 7]. My solution suggested the answer is 0, which is in fact the correct solution. The test case expected 1 for the solution. So whatever generates the tests isn't working perfectly.
That particular test case is a fixed one, and not random. I can confirm that this test actually expects
0
to be returned, and not1
. Is it possible you're reading the test result incorrectly? I checked in python, not sure about the other languages. Python also has almost 42,000 solves, so I'm guessing the problem isn't with the tests.Haha it's always possible that I'm misreading it, but I don't think that's what's happening this time (I apologize if I am lol - and further, the numbers, as you point out, seem pretty convincing, so it wouldn't surprise me if I'm wrong). I added some code to print out relevant info and pasted the result below.
0 should equal 1 Log input is: [3, 7, -99, 81, 90211, 0, 7] solution is: 0 solution's type is: <class 'int'>
Are you sure that the
0 should equal 1
isn't referencing the test above the one that you're talking about? The input for that test is[1,0,0]
and the correct answer for that test is indeed1
.The
x should equal y
will appear below the log for any test that you fail, not above it.Well this is embarassing. That's exactly what happened. Thanks for your responses! :)
No worries, it happens to everyone at some point!
This comment has been hidden.
Your solution can run into issues when the array contains duplicate values. I'll let you figure out why that might be exactly. I would also suggest maybe taking a different approach altogether. Not to be mean, but 3 nested loops are probably not the best solution to this problem.
I am passing all tests but one. The one I am not passing says "expected 4 to equal 2." If I got an even number and the expected number is also even, wouldn't this mean there are two even "outliers" and that the test is faulty? Please let me know if there is something I am not understanding about this test.
Print the input, without it, there's not much we can say.
OP solved it, closing.
im getting right results when computing, but expression doesn't want to pass. :/
Hopefully this can help you: Troubleshooting Your Solution.
This comment has been hidden.
No, your code must be returning undefined instead of 1, could you copy and paste the exact error message?
test expected undefined to equal 1
The first value is what your function returned (undefined), the expected value was 1. Read this: https://docs.codewars.com/training/troubleshooting/
Thanks, i'm new to codewars and haven't done unit testing in a while. forgot how the format was. I appreciate your help!!!
When I click on TEST my code passes the test successfully but when I click on ATTEMPT I still get an Exit code error EXIT CODE(1), I have read https://docs.codewars.com/training/troubleshooting/#test-attempt but I couldn't solve that. Does anyone know what the problem is?
can't offer much help without knowing language/your code snippet
ATTEMPT contains randomised inputs to check that you are not hard coding the solutions from TEST
When I click on TEST my code passes the test successfully but when I click on ATTEMPT I get an Exit code error. could someone help me out?
read this.
This comment has been hidden.
Not a kata issue. Don't use input functions like cin, write a function with signature
int FindOutlier(std::vector<int> arr)
instead and return the result.You can ask questions on CW discord or read this article for tips: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution
but if the array have a different kind of number, what i had to return?
I don't understand how to create methods.Do I need to create them separately. I try but it gives error. But the solution is correct.
Like that () {
public int test1();
public int test2(); }
OP solved it, closing
This comment has been hidden.
You write them yourself. After solving a kata, you can see how other coders solved it.
When checking if a number is odd or even, taking the absolute value before the check seems safer.
This comment has been hidden.
Not a kata suggestion, please don't post solutions in Discourse.
sorry
Not sure why test 2 is failing. IT works perfectly fine in VS when using the same array from the test. 1 and 3 working fine.
I use binary recursive search and it works well almost all the time. I passed 21 tests and 11 are failed. Maybe its because of negative numbers or because big amount of numbers I don't know... I can share my solution just leave a comment and the way to contact you
This comment has been hidden.
The message does not mean that input array was
[1]
. It's difficult to tell without seeing your code, but most probably means that you return[1]
(an array with a single element) instead of1
(a number).Ok thanks, Ill check it out. I guess I returned the array instead of the element indeed
This comment has been hidden.
Noice kata!
This comment has been hidden.
You should post the code in spoiler so we can help, closing &&
I passed the test but the attempt return error, any mind !!
Failed asserting that 2 is identical to -3523.
When you click TEST your code is run against basic tests. When you click ATTEMPT your code is run against usually more complex tests as well as random tests. So, if you're not passing, check the error messages to debug your code. If your code is not working, you may post as a
question
. Anissue
is reserved for when there is a provable problem with the kata itself.Thanks
Good task. I flexed my brains well. I had to remember mathematical logic =)
Code runs fine in my IDE, returning 0, but here it tells me it returns 5. huh...
Function works perfectly, it can pass the tests, but on last few tests, it times out. Should there be a limit set to array sizes?
No, there should be no limit set on array sizes.
If your solution times out, you need to improve it and make it able to handle large arrays.
See here: https://docs.codewars.com/training/troubleshooting/#timeout
Thank you! I see where I went wrong! Thanks!
anyone else mad confuzzled rn lol
jk i figured it out <3
Everything would be fine, but...
2 should equal 3
consider that the array is indexed from zero insted of one.
This comment has been hidden.
This comment has been hidden.
Please don't post code (even if it doesn't work) in the discourse. Use the
spoiler
flag if you must.Your solution is returning the wrong answer (or answering the wrong question). Read the task again and figure out what exactly it is you're being asked to return.
its easy it should be in kata 8
expected:<-35> but was:<4>
But how can I know which example it refers to?
Print the input, it'll appear above the test result.
This comment has been hidden.
OP solved the task, closing
This comment has been hidden.
Please don't post solutions in the discourse.
[2, 4, 0, 100, 4, 11, 2602, 36] Should return: 11 (the only odd number) -> This is wrong, because in this array 2 and 11 are odd numbers
Review your definition of odd number, 2 is even, not odd.
I think I mixed up all here. I do not read with attention and I thought it would be an find-primes exercise. Thanks, Chrono79. Maybe an exercise like these for further lessons would be nice, too: given an array, find an only prime between non primes, or an only non-prime between primes.
I have error when attempt full test: expected:<-44> but was:<-1> But test array is {1, 1, -1} -1 is correct value
The fixed test that expects
-44
as result is ok, and there is no fixed test with that input, are you talking about random tests? Please read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution#print-input"You are given an array (which will have a length of at least 3" and then i wasted hour looking for my mistake i did not make, to finaly waste next hour looking for exceptions to make correct attempt. I learned no c# skill but improved "codewars attempting skill "
"Traceback (most recent call last): File "main.py", line 3, in test.assert_equals(pyth, 3) NameError: name 'pyth' is not defined" Even if I didnt have that kind of code in my answer why I got this error? Thank you
This comment has been hidden.
Please read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution This is a
Question
, not a kataSuggestion
. It's also explained there what you're doing wrong.This comment has been hidden.
Well, test your solution with
It should give a 2 but yours gives 1.
Also
Should give 1 but yours gives 0.
Look at your outlier variable at each step and compare what it should be in your mind vs. what the program does. Printing it to console for debugging helps.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Edit: problem solved
thanks for the reply. yeah the problem was in my solution actually. I fixed and submitted it.
Great! for future reference this shouldn't be marked as an "issue" but as a "question".
will keep that in mind! :)
A warning is just that, it won't prevent a correct solution from working. But those warning should be fixed tho.
All warnings have now been eliminated from the C translation of this kata.
My program passed the test but failed attempt. Why?
With that much information, impossible to know, read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution
same problem here. I do doing the Kata in C?
I was suspecting the test fixture but the bug was in my solution. for me it worked eventually
It's so easy and I can't image why somebody can not handle it.....
I always get the same error even tho i pass all tests on my local server..
Parse error: syntax error, unexpected '<', expecting end of file in /home/codewarrior/run.php on line 4
I've succeeded with this kata in Python and repeated just the same algorithm in JS. It passed simple tests, but failed all the suite. Is this kata about algorithm as labeled?
If you mean that your two solutions behave the same way then you could try the failing tests on both solutions and see if they really do respond the same.
Hi Natan, I did it other way by figuring out what kind of number to go for, etc. instead of simple 3-liner as in Python. Even that failed to pass all the test suite. I noticed it fails when trying to cath negative odd, so putting Math.abs() everyhere worked out. I finaly did it, but to my big surprise the most promoted solution appears to be the same 3-liner as mine in Python.
This comment has been hidden.
Python's % is modulo, javascript's % is remainder.
Indeed, it does not. Do you have idea why?
Hint: try to recreate failing test case locally (see here how to get failing input) and debug through it in your IDE.
This comment has been hidden.
Closing the question, please mark your posts as having spoiler content when they do.
This comment has been hidden.
That's not valid python syntax, it did not work in vsc. If you're trying to unpack into a tuple, that would be:
*listb,
(parentheses aren't part of tuple syntax, but the comma is.) But your function isn't supposed to return a tuple anyhow, so that still would not work.thank you for the reply, i've been programming for only three weeks now so still trying to get the hang of things.
I've done the task but what bothers me that in a description the author says that an array can be big. A part of my solution was using for loop which means linear looping, which doesn't suit well with big arrays. Maybe somebody could give me a hint for a better performance solution.
I don't believe there are solutions better than O(n) here (I guess O(n/2) for the average case if being specific).
I think that at a minimum all solutions will require you to iterate through at least as many elements until you reach the first "only odd" or "only even" number (so on average n / 2 elements - hence my comment above).
I suspect the "big arrays" requirement would have been to eliminate more complex solutions - e.g. O(n.log(n)) or O(n^2).
Does this answer your question at all?
OP long gone, closing
This comment has been hidden.
I know you want to help, but this is a spoiler.
how did you guys do this problem because I keep getting stuck
This comment has been hidden.
Hi Mawi23, you should know it is forbidden to post your solution, anyone can see it on the dashboard. I have added the spoiler tag.
ohh okay I am new to this and I didn't know
This comment has been hidden.
You misunderstood the task. You need to find the outlier, which can be odd OR even. You should read the description again.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Currently it's difficult to help because your solution is difficult to read. After you post it properly, someone could take a look.
This comment has been hidden.
Your solution has a bug and it does not pass even sample tests. Did you try to run your solutions with the same inputs as sample tests? It should fail for you also locally:
Not a kata issue.
i tested it locally with all sorts of arrays and with every single one it worked. could you give me a hint as to what i did wrong?
edit: after loading the file in irb again, somehow it stopped working. now the function returns nil for each array i pass it. i understand i made a mistake. can anyone help clarify what it is?
Please try it locally also with array like
[0, 1, 2]
and check if it indeed returns1
. I see no way for your solution to return correct result for such input.Your function returns
nil
when it reaches its end without encountering anyreturn
. In other words, execution of your function does not enter any of yourif
s and skips them, effectiely returning no value.thanks!
I believe i done it. Following how it said there will be a "Single" number thats different. It kinda stressed this but i passes the test and ran the attempt and it failed. I printed out each integer of the array and there were multiple even and odd numbers. No way i can return a "only" number. Is this kata broken?
No, it isn't. You probably are printing several inputs together.
This comment has been hidden.
This comment has been hidden.
Not a kata suggestion, and please don't post solutions in Discourse.
This comment has been hidden.
Your solution fails if it's invoked twice in one test run.
you have to consider edge cases like when len(list) = 0
anyone know how about to go on this question please help me
This comment has been hidden.
This comment has been hidden.
I have the same problem. I run it in mi IDE and give me the same.. wtf??
make sure you return and not print
Why is this test wrong?
0 should equal 1
{3: 'odd', 7: 'odd', -99: 'odd', 81: 'odd', 90211: 'odd', 0: 'even'}
Any ideas?
Thanks in advance!
This comment has been hidden.
There's some problems with your code:
question
label. You should read this FAQ for basic troubleshooting tips.This comment has been hidden.
Simply return odd[0] or even[0] if you have a list and you need the first and only element of it.
what is meant by none should equal 1 here ?
you're probably not returning anything from your function so double-check that
Rust translation awaiting approval.
This comment has been hidden.
Please, don't post solutions in Discourse like that, it's forbidden.
Sorry, I didn't know about that! I'm going to delete. I thought This space is to talk about solutions.
Don't worry, it happens. You can't delete the post, I've already marked it as having spoiler content.
To talk about your solution (or any other solution) use Solutions section, and remember to mark your post as having spoiler content there too if your post has spoilers.
Normally Discourse is used to report Issues with the kata/tests, suggest some improvement, or ask questions when you can't solve the kata.
Ok. Thank you.
This comment has been hidden.
Is there any way to view the tests that run when pressing "Attempt". I am using Java, and passing all tests, however when pressing "Attempt" I am getting an ArrayIndexOutOfBoundsException and I understand why. However, I can't see that test case that fails, and this is bothering me. Unforunately, the stacktrace only points to the line where the exception is occuring but not at which given value.
If your language is Javascript, then type-console.log(integers) at the very beginning of your function; as the fist line of your code or just print the value at the beginning to see which arrays are being passed into your function.
This comment has been hidden.
why cant i use starred expressions?
This comment has been hidden.
I pass the sample tests, but, when I try to submit, it fails. Can someone help me to understand what's wrong with my code, please?
Task completed but failed :( WHY ??? Working code
Pick one. Or rather, prove it.
This comment has been hidden.
Please mark your code as having spoiler content next time (I already did), and format it so it's readable :P
I don't see you returning any result in your code. You should return it, not print. Also you can hit 'test' and read the error messages on the left which tell you what's happening.
OK :)
i am using java it passes the sample test case but when i try to attempt it fails. when i printed the inputs they were {2,6,8,10,3,2,6,8,200,700,1,84,10,4,17,6,8,10,6,12,24,36} why are there more than one odd numbers? and why is it expecting 17 as answer?
That is not the input of a single test, there is more than one there in the same line.
ohh got it thanks
This comment has been hidden.
I tidied this up (and converted it to C#) and it worked for me, not sure what's wrong when you run it.
OP solved the task, closing
this is a general question:
I am passing the sample test but not the full test. How do I go about reaching the correct solution? If I could see the tests I can understand why I am failing but all I see is the expected and actual output.
I have attempted to read the stack track but to me it is gibberish(because I do not understand it).
I am not saying there is an issue with this kata however, I would greatly appreciate any advice/assistance because I run into these issues regularly.
Try printing the input and figuring out why. I don't know why your code doesn't pass, you don't even say, but your code can be wrong or be inefficient and then only passes the sample tests and not the full suite.
I didnt say because I do not want to give away possible solutions.
I will print the input not sure why that didn't occur to me. Thanks.
You won't be giving away possible solutions. If you click this checkbox:
then it will hide your comment from people who haven't solved the kata.
So easy for 6kuy
It might've been harder in the language it was originally posted in.
This comment has been hidden.
SPOILER FLAG PLEASE ! (I added it myself)
Also, your incorrect code is not a kata issue! Post a
question
next time please.To answer your question, your solution is 1 character from being correct. Try double checking what you want to compare.
Well, i have compared the size of each list by using List.Count(), so i have thinked about problems about output. The problem is i cant put any breakpoints to track the value of arrays, so i am thinking about converting using List.ToArray(). UPD: i get it now, i just woke up and done in early in the morning, thanks.
Well done! Keep in mind that you can always do basic debugging by using
Console.Writeline()
to track variables. (putusing System;
statement at top if needed)This comment has been hidden.
This comment has been hidden.
really good solution thnx man
Looks like u alr solved it~~
This comment has been hidden.
Not a kata issue, it's a problem with your code, print the input, analyze what's wrong with it and fix it.
This comment has been hidden.
I have done a solution for this kata and it does pass the tests. When I'm trying to run attempt, it throws an error for the test. Can someone help me? Its for Java
Having here the same issue. Have you been able to resolve yours? And if so, would you like to discuss it in a private channel or something please so that we don't spoil the solution?
Same issue in swift 5.0. Is there any way to send array without scope in function :\ ?
What exactly is the problem? Do tests crash, or you see some red assertion messages about failed test cases?
What do you mean by " Is there any way to send array without scope in function"?
This comment has been hidden.
.
One of the tests under Other_Tests is a array with two elements when the instructions say only arrays with three or more elements will be entered.
Remember to state the language when you find a problem, it's easier to check/fix it that way.
C++
I was able to pass regardless, but the tests should be in line with what the instructions say the expected input with be.
which test was it? can you tell me the values? because unless within the last 2 hours someone has changed it, there are no arrays in C++ with ony two elements
I saw one with values like { 1, 00 }. Looks like it might have been a typo, having missed a comma.
yes, the test is {1, 0, 0}
Check the issue created by OrdoFlammae below, he already mentioned this problem.
This comment has been hidden.
well, (just for starters), while I don't speak swift, I would suggest a method that only iterates the array once.
This comment has been hidden.
OP solved the task, closing
This comment has been hidden.
My thoughts exactly.
This comment has been hidden.
The log appears above the test result, you're confusing the log of one test with the result of the previous one. No test of the "more complex" ones expects 6 as an answer, are you sure?
Whoops!! I will check again.
The instruction said that the length of the array should be >= 3,
However there're no test to determine that array meets these requirements.
Do you think it will be a good decesion to add such a test ?
It's saying you they'll have that size, not that you have to validate that.
Hi everyone. Anybody knows, is it correct assertEquals(3, FindOutlier.find(exampleTest1)); ? We have exampleTest1 : int[] exampleTest1 = {2, 4, 0, 100, 4, 11, 2602, 361}; And right answer wiil be 11. Am I wrong?
If those are the sample tests for Java, the value of exampleTest1 isn't that:
int[] exampleTest1 = {2,6,8,-10,3};
Click reset and try again.
Thanks. It was usefull. I done it :-)
TypeScript Translation
Please review and approve
This comment has been hidden.
Then it's a problem with your code, not a kata issue. You can see it fails the sample tests too. For things like this use
Question
label instead. Check your code inside the brackets, aren't those 2 the same?Go transtaltion available for review.
Hi @obnounce, could you share with me the test case which the right outlier is -44?
Why is this an issue? Can't you print the input?
This comment has been hidden.
Issue
label should be used when the kata has a problem, when the problem is in your code, useQuestion
instead.NOTE: This is directed towards the author of this kata, @obnounce.
The test output is messed up in some cases. The reason for this can be traced back to line 9, where the if statement is. This statement queries if the VALUE of the last element in the list is the same as the VALUE of the element that it is on. This can produce some weird output (especially since the cone variable is never reset). Here are some sample weird outputs.
test_for({1, 0, 0}, 1) Testing for {1, 00}
test_for({3,7,-99,81,90211,0,7}, 0) Testing for {3, 7-99819021107}
The way to fix this is to change the if statement so that line 9 looks like
if (i == arr.end() - 1) cone = "";
This way, the if statement is comparing ITERATORS, not VALUES.
what language?
C++
done
This comment has been hidden.
Not a kata issue, it's a problem with your code, print the input, see for yourself why it fails. And mark your post as having spoiler content next time.
Python. Attempt stage: all tests are passed, except this one " 0 should equal -9223372036854775807 " and I can't see the initial list to check my code.
have you tried printing the input?
thanks for idea. but I found an issue: console
import math print (math.fabs(-9223372036854775807)%2) 0.0
PyCharm: https://clip2net.com/s/42YI9QB
what's in this comment does not match what your pycharm image shows
pycharm result = 3 pytho console = 0
expected = 1
I can't speak for your pycharm difference, but I know you will get the expected
1
if your parentheses are in the right placerowcased, can I send you my code for this kata?
you can post it as a reply on this thread, just mark it as a spoiler
This comment has been hidden.
okay i get what you did here, but first off best not to repeatedly use fabs AND indexing AND % 2 six times for
[0]
, four for[1]
, and twice for[2]
. but what I really want to know is: what prompted your use of math.fabs() over abs() in the first place ... ?thank you, rowcased with abs code works properly. google advises me to use math.fab )) as regards my code I know it is not optimal. I hope when I will be 2 kyu or higher it will be better ))
you are welcome. by the way: you should KNOW WHY math.fabs was the wrong choice. if you can't explain it, go find out. (I didn't know until I looked it up so I could help you). You owe it to yourself to do this research and know the difference.
I just solved this challenge and it's the first time ever that my solution is the shortest one. :)
This comment has been hidden.
It's been already mentioned below, and when they're both approved there is nothing to do.
Also, it should be marked as an issue. But it is duplicate comment anyways so doesnt matter
IQ Test was also created several days after this one
Julia translation
This comment has been hidden.
Okay, well this is just code. This does not have to be approved. Just click attempt on the bottom when coding and it will tell you if you have passed :).
PS: I don't believe true or false output is needed for this task. Rather the outlier number.
Not a kata suggestion.
Add [0,2,-1] to tests, it will filter alot of currently accepted solutions.
.
This comment has been hidden.
Not a kata suggestion, and please, don't post solutions.
En Java:
When I tried returning integers (to see what was in the integers array in the test), it gave me: expected:<3> but was:<[I@7d3a22a9>
It is thus not only filled with non-integers, but also it has 2 even numbers and 2 odd numbers. Unsure how can anyone resolve this.
You can't print an array in Java like that, that's why you see that.
Java has two categories of types: primitives and references. An array is a reference type. When you print the array, what you are seeing is a reference which the JVM uses to locate the object in memory. It has nothing to do with the contents of the array.
To see the contents of the array, you can loop through and print the values. They will show up in the test log.
IMO we shouldnt limit the number of outlier as it currently is.
That would be great if we change the definition of the outliers to : smaller group of elements that dont follow the remaining ones' characteristics.
In case there're 2 groups of exact 50%, both are outliers.
What is you guys' opinions?
Nobody's going to change the task now.
be aware of the high voted "solutions" in this question. They are just workable in the very loose condition provided in the test cases of this question. aggregating the whole list of odd number and even number is short but expensive.
PHP:
Would need someone to check this and correct it if ever...
Fixed the first one, can't find the other, are you sure that's happening?
no idea! x)
Well, AFAIK that doesn't happen anymore, so I'll mark it as resolved.
This comment has been hidden.
I think the
assertEquals()
in the test case have the parameters inverted. First one is the expected and second one should be the result of ourfind
function.confirmed. Closing here to raise as issue.
It was a cool challenge worth solving. Liked it
I've seen some very clever and concise solutions! But as I read the really concise ones, they require reading the whole input. The question states that the input might be very long! For best practice, I'd like to see solutions that can exit as soon as the answer is known, without reading the rest of the intput.
This comment has been hidden.
I think there is a simpler way: for any integer[i], just check its sum with [i - 1] and [i - 2] for an odd number, since the array size is at least 3. We cannot use i + 1 because of the last integer would have out of range problem.
im using c++.the output window says expected 2 actual 0 but when i copied the code and tested it on the sample tests on an offline ide my function worked fine.
Some incorrect solutions pass all tests in Scala: https://www.codewars.com/kata/reviews/5bf33eaef8c527c2d4001f8c/groups/5bf3cb9429354d2b7b000bfc fails at
List(-1, 1, 0)
.Good catch! I've created a fork including your suggested test case. Not sure what action is needed next for it to be applied.
Scala translation available for review.
This comment has been hidden.
Hi,
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.
And for your current problem, did you check what are the inputs/outputs to try to debug your code on your own?
cheers
Kotlin Translation Please, review and approve
This kata is very, very similar to "IQ Test" kata (6 kyu). Is there a way of deleting "IQ Test" (because it has less people that solved it) without people losing honor points?
This is not a reason to retire a kata.
Please, Approve NASM Translation
Approved.
Great! (*)
This comment has been hidden.
Issue not specified.