6 kyu
Prize Draw
242 of 7,119g964
Loading description...
Fundamentals
Strings
Sorting
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.
There seems to be a problem with the final tests in Rust (spelling?):
This comment has been hidden.
please explain the condition of the task If it is clear where the winning numbers come from, then why in the 2nd example, with n = 4, Paul won
PauL didn't won:
PauL ended in the 4th place.
Nice kata!
I think there is a problem with the button ATTEMPT for passing the complete set of 51 random tests. My code usually passes most of the random tests except 3 or 5 . Usually, the error displayed is “expected Elizabeth to equal Matthew.” On the other hand, when I manually compute the winning numbers from Elizabeth and Matthew, they are different. The same happens with the other errors. I suggest to review the random tests.
See https://docs.codewars.com/training/troubleshooting/
No reply in 4 days, and not a valid suggestion to begin with. Closing.
This comment has been hidden.
The test is fine, not a kata issue, why do you have 2 Mason there? Check how you calculate those values too:
1 mason - weight * summ of sumbols. 2 mason - index: winning number.
Unserstand, thx
Yes the problem was the value of the symbols you were using.
C fork
thanks !
In OCaml,
we
seems to have more elements thanpeople
. Which is not specified in the description and cause an error when doing we traversal to compute score.My bad, thanks.
I think there's an issue with the final fixed tests for PowerShell. I'm not doing any manipulation on character order yet some have either the test case or the value passed in as
$st
that are misspelled.That's not indicative of a kata issue, since it doesn't take spelling into account. If you think a test case is wrong then keep in mind that it only makes sense to talk about wrong answer if you include the test input.
Interesting, I just stumbled upon the same problem with my solution in Rust.
There is a problem with the tests. 4 in 104 fail and in all these cases it does not comply with the instruction: "When two people have the same winning number sort them alphabetically by their firstnames."
The cases are:
Log names: Elijah,Chloe,Elizabeth,Matthew,Natalie,Jayden weights: [1, 3, 5, 5, 3, 6] n:2 dat = Any["Matthew" "Elizabeth" "Jayden" "Natalie" "Chloe" "Elijah"; 485 485 390 207 144 51] winnums = Any[485, 485, 390, 207, 144, 51] key = 485 posall = [1, 2] outnames = SubString{String}["Matthew", "Elizabeth"] Actual Elizabeth Expect Matthew
Log names: Lily,Lagon,Olivai,Emily,Madison,Olivia,Matthew,Noah weights: [6, 1, 2, 4, 1, 2, 3, 4] n:6 dat = Any["Lily" "Matthew" "Emily" "Noah" "Olivia" "Olivai" "Madison" "Lagon"; 372 291 276 168 148 148 82 54] winnums = Any[372, 291, 276, 168, 148, 148, 82, 54] key = 148 posall = [5, 6] outnames = SubString{String}["Olivia", "Olivai"] Actual Olivai Expect Olivia
Log names: Alexander,Robert,Sophia,Michael,Lily,Samantha,Emily weights: [2, 1, 3, 3, 3, 4, 5] n:5 dat = Any["Emily" "Samantha" "Sophia" "Lily" "Alexander" "Michael" "Robert"; 345 340 222 186 186 174 84] winnums = Any[345, 340, 222, 186, 186, 174, 84] key = 186 posall = [4, 5] outnames = SubString{String}["Lily", "Alexander"] Actual Alexander Expect Lily
Log names: Ella,Ella,Joshua,Samantha,Olivia,Madison,Sofia,Noah,Mason,Avery,David,Isabella,Olivai,Lily weights: [1, 4, 1, 5, 4, 3, 3, 5, 2, 3, 4, 5, 4, 5] n:5 dat = Any["Samantha" "Isabella" "Lily" "Olivai" "Olivia" "Madison" "Avery" "Noah" "David" "Sofia" "Ella" "Mason" "Joshua" "Ella"; 425 345 310 296 296 246 228 210 180 165 136 134 80 34] winnums = Any[425, 345, 310, 296, 296, 246, 228, 210, 180, 165, 136, 134, 80, 34] key = 296 posall = [4, 5] outnames = SubString{String}["Olivai", "Olivia"] Actual Olivai Expect Olivia
There is no problem with the tests, Elizabeth comes before Matthew, and it asks who is the person ranked 2nd.
It's the same with the other tests your code fails.
...but then others like in: Prize.rank("Aubrey,Olivai,Abigail,Chloe,Andrew,Elizabeth", [3, 1, 4, 4, 3, 2], 4) #-> "Abigail" with: outnames = SubString{String}["Chloe", "Abigail"] will fail.
Then you're doing something wrong, because for that input, "Abigail" is the right answer.
Of course "Abigail" is the right answer and that's what I got after alphabetically sort SubString{String}["Chloe", "Abigail"], but if as sugested: "it asks who is the person ranked 2nd" , taking the 2nd fails.
...so I included extra lines as exceptions in order to have no errors. Maybe my aproach needs more thinking. Thanks Chrono79.
nice kata, I love to gain pain which encourage me to solve harder problem and surpass myself. thank you, g964.
This comment has been hidden.
Lovely kata, thank you g964 for great time
My solution is going through the testing phase. But I need to sort the names. For this kata, I need a codewars friend to get help from.
This comment has been hidden.
really unnecessarily convoluted.
Good kata, problem description was clear but structured poorly. Read through it and look at the tests to help understanding, if you are having trouble be descriptive in your variable names.
This kata is purposefully tricky rather than poorly written. I recommend giving it another shot rather than dismissing it immediately.
Rust tests need to verify return type, otherwise my solution works (return
Cheat
type, which equals everything).This has already been explained to you before, you are heading towards an account ban if you continue to cheat on kata.
not a kata issue.
I read and read and reread the first few lines of instructions and then just gave up. Too bad it seems like a nice puzzle for sorting. It just promises to take too long to decipher a broken description
I quite enjoyed this kata. For me perhaps a little more difficult than most other 6kyu I have done. Pays to read the instructions carefully as I omitted to include the string length in my calcuations and sat looking and wondering why my solution was incorrect.
This comment has been hidden.
Thanks!
I think it should be a 5kyu level, pretty hard for a 6kyu ^^ but nice ;)
Thanks!
The tests fail on Codewars:
" Test Failed
actual
not equal toexpected
. 'current' is not a factor "When I use "testthat" and run the exact same code in Rstudio, it works fine.
I tried several solutions without any problem.
I run your code in RStudio and I got 'current' is not a factor'. Not a kata issue.
Uh, these special edge cases were killing it for me. Still thanks for the training!
Thanks!
The test cases are inconsistent.
The first sample shows the first name which comes last is winner when there's tie in final points.
NAMES :[Elijah, Chloe, Elizabeth, Matthew, Natalie, Jayden] WEIGHTS :[1, 3, 5, 5, 3, 6] THEIR SCORE :[51, 144, 485, 485, 207, 390] WINNER :2 FINAL CONTESTERS:[Elizabeth, Matthew] expected:<[Matthew]> but was:<[Elizabeth]>
But the second is opposite of sample 1. NAMES :[Aubrey, Olivai, Abigail, Chloe, Andrew, Elizabeth] WEIGHTS :[3, 1, 4, 4, 3, 2] THEIR SCORE :[234, 74, 192, 192, 213, 194] WINNER :4 FINAL CONTESTERS:[Abigail, Chloe] expected:<[Abigail]> but was:<[Chloe]>
There is no inconstitency in the tests. Your code is certainly wrong somewhere. Please look at the top of the page to see how many people passed the kata in your language before posting issues.
PYTHON
Help me please! I don't understand what the problem is. On my computer, the same code with the same input data is executed without errors.
Code:
def rank(st, we, n):
Error:
Traceback (most recent call last): File "/workspace/default/.venv/lib/python3.10/site-packages/codewars_test/test_framework.py", line 112, in wrapper func() File "/workspace/default/tests.py", line 87, in randomTests test.assert_equals(rank(st, we, k), rankSol(st, we, k)) File "/workspace/default/tests.py", line 56, in rankSol res.append([f[i], we[i] * scoreSol(f[i])]) IndexError: list index out of range
you should read the error message:
which means you are asking for an element in the index when the index doesn't even exist
this is not a kata issue. post this with a question tag next time
I understand that since so many people have completed this task, it is most likely my fault, but I still do not understand. The error message says that the error is in the tests. I also checked the execution of my code on prints in cases where an error occurs and the code is executed to the end without problems, but the index error still occurs in the test.
Quite complicated Kata. There you have to find out relation between unsorted and sorted array's indexes. Because you need it when you have to rearrange the string array.
The part people get confused at is picking the score at n, then picking the first name from a seperate sorted array of participants with that score. The name sorting is more like a tie breaker. For example if "a", "b", and "c" are tied for 3rd, b would be 4th. So if n is 4 you wouldn't be picking a, you would pick b.
Updated to Scala 3
.
Ruby translation for updating to 3.0 + resolving the issue
I'm getting a 404 on your translation link :(
Looks like it was approved by someone else anyway :)
Yup, misstyped link, correct one is this one. Still thanks for closing out the suggestions ^.^
Powershell translation for updating to 7.2
Approved by someone.
Thank you!! I learnt a lot about the sort function. Phew!
That probably took me a little longer than it should have... but WOW!, it absolutely made me learn and understand exactly how to make
sort()
do what I want!EXCELLENT Kata ... how this only has 82% rating I just don't understand! I'd give it a VERY+ if I could!
Thanks!
Hope this doesn't get marked as spoiler. If you're having issues dealing with ties, this is something i wish i had found out earlier.
Dealing with ties by sorting in alphabetical order is mandatory it has to be done always.
The problem is that the instructions read that IF there is a tie with the prize winner, this has to be solved by sorting in alphabetical order, but this has to be done regardless two people having the same winning number. Hope this helps
Please let people try by themselves.
debugging this was a hell...
I enjoyed this kata.
Thanks to this kata, my sunday was bitter-sweet, but after a little nap, came back and solved it, the description could be a little bit misleading, but the learning was amazing!!! Thanks
In R it works fine. But Codewars sends me:
Test Failed
actual
not equal toexpected
. 'current' is not a factorWhy a factor? It has to be a character. as.factor not work...
Same problem here. When I use the "testthat" library on my machine and run the exact same testing code it works fine. It throws the same error as you posted when I run it on Codewars.
Expected "William" to equal "Willaim"
Please read the description and example carefully, and you'll know why.
yes. i had simce mistake
Can anyone explain to me (Javascript) when I try to return a property on an object with index n-1, it returns undefined in codewars but works correctly in all browser consoles?
See information below for context:
n = 4
0 { name: "Addison", winningNum: 292 } 1 { name: "Michael", winningNum: 232 } 2 { name: "Andrew", winningNum: 213 } 3 { name: "Benjamin", winningNum: 152 } 4 { name: "Jayden", winningNum: 130 } 5 { name: "Lily", winningNum: 62 } 6 { name: "Sofia", winningNum: 55 }
returning the object.name property with the the index [n] works... [n -1], however, (Since rank starts at 1) returns undefined. Perhaps not the best way to solve the problem, but I'm a bit perplexed why this is happening...
Any insight? Thanks :)
so close, i cant sort the test where all of the elements have a pair of the same winning numbers.
Translation for it is ready, please review and approve
Resolved as above translation was approved
'forgot, thx. :+1:
I honestly spent so much time on this one. Felt hard, but somehow managed to solve it. Now I feel like a wizard. xD Nice kata...
This is lvl 5 defo.
OK, one more kata and I go to sleep
not going to sleep for three hours
Hello, I don't understand why my code passes the test, but when I attemp to commit my solution one test fails: Fixed Tests expected:<Will[ai]m> but was:<Will[ia]m>
Could you send me the test that runs when "attemp" is clicked please?
Assuming you write in Java (from your profile), if you have no errors in your code, you can simply print the output (inside of your nthRank function). In order to print
n
orst
, you can simply useSystem.out.println(n)
. If you want to print the list of Integerswe
, you can iterate over it with a for loop (for (int index = 0; index < we.length; index++) System.out.println(we[index]);
). I hope this will help you to find the problem!Yes, I have done it in Java. I thought it wouldn't show the prints, thank you very much.
Now I'm even more confussed, when I run the same test locally it passes the test successfully :S
Could I send you my code? It's all with lamdas and I spend some time doing it (I'm still improving my lambdas ability)
EDIT: Now working, problem with java versions, see next comment
This comment has been hidden.
I don't think the problem is from you, but from the tests (some of them work on Java 8, others in Java 11). Good that it works now.
Way harder to understand than should be
I created a 2D array with the names of the participants and their winning numbers in descending order.
let sorted = [ [ 'Addison', 348 ], [ 'Michael', 288 ], [ 'Andrew', 249 ], [ 'Benjamin', 184 ], [ 'Jayden', 154 ], [ 'Lily', 70 ], [ 'Sofia', 65 ] ]
For the first test case where n=4 and the winner is Benjamin, I am trying to return sorted[n - 1][0], I get the error that it can't access the property [0] of undefined. However, when I console log this expression, it works just fine and prints 'Benjamin.' Also, the return statement works just fine in VSCode.
I haven't dealt with the instances where the string is empty or n is greater than the number of participants yet.
function rank(names, weights, n) { const calcSom = (name) => name.toLowerCase() .split('') .reduce((sum, ch) => sum + (ch.charCodeAt(0) - 94), 0) + name.length
}
Great kata, my 5.1Kth one as well ^O^
Node 14 should be enabled (Refer this and this for more info)
Python new test framework should be used (Refer this & this for more detail)
Ruby 3.0 should be enabled (Refer this & this for more detail)
.
Typescript 3.3 or above should be enabled, refer this for more info
Missing return type in initial solution of TS
.
Badly worded and confusing. Coding is hard enough without trying to translate a badly worded problem. I'm skipping this.
needs a rewrite on description, I understand what its asking for after 30 mins of interperting but you really just need to explain the specific input and out put and thats all, this kind of challenge dosent need narative fluff
The directions are a bit sparse. I think using the word "rank" to signify both the
letter_value
and the position in sortedwinning_numbers
could be confusing.st = "Elijah,Chloe,Elizabeth,Matthew,Natalie,Jayden"; we = new Integer[] {1, 3, 5, 5, 3, 6}; assertEquals("Matthew", Rank.nthRank(st, we, 2)); why matthew insted of elizabeth if we arrange alphabetically elizabeth comes first
Read the post just below by Chrono79.
Tried it in C++: I have problem bei dude called Willaim and William...
The Kata description says "Sort them Aphabetically": in my opinion William is higher (in decreased) order than Willaim, because they differ in 5th Letter and i is more than a... or?
The decreasing order is for the winning numbers, the names should be sorted from a to z.
After a good night sleep and your answer, the solution appeard!
tnx!
so why should i return 'Matthew' instead of 'Elizabeth' when both have the same winning numbers. clearly the instruction said 'When two people have the same winning number sort them alphabetically by their firstnames'
Because you have to return the second one. The argument for rank is 2. There are many posts about this, you can read them below.
Log {'Elijah': 51, 'Chloe': 144, 'Elizabeth': 485, 'Matthew': 485, 'Natalie': 207, 'Jayden': 390} 'Elizabeth' should equal 'Matthew'
看来你的疑惑已经被解答了^^
Poorly written instructions, I'd skip this one.
This is weight for PauL = 4('PauL' length) + 16(P) + 1(a) + 21(u) + 12(L) = 54
I'm doing this in Python 3.8 and I need to use the string module. I imported it on my computer and the solution works offline but it's not working on the site. Can we not import modules on Codewars?
You can freely use all the built-in modules. Your solution is probably wrong - post your code in a comment with a spoiler flag if you can't figure it out yourself and need help.
I've just tested, and I could import the string module fine.
.
This comment has been hidden.
This comment has been hidden.
What should I return? I can't understand clearly this Kata, but it seems easy. Can anyone help?
PauL -> som = 4('PauL' length) + 16(P) + 1(a) + 21(u) + 12(L) = 54
I took a look at the description and I immedietly skipped it
LOL, i'm not alone
I am writing this to share my frustration.
That kata itself is not difficult.
The description made it not clear what is being asked.
why is Paul selected amoung list of names as an example?
He isn't the winner. I thought he was. I was mislead and wasted time trying to understand why paul was selected.
It is explained why Paul is selected, what do you mean you're mislead?
You shouldn't return the winner, that's not what is asked.
I understood it. I already solve the kata.
but before that I was just failing to understand the kata description.
It's giving me an error in codewar platform that obje.flat() is not a method is it not supported here? because it's working fine in console
function getRank(str,weights,rank){ if(str=="") return "No participants" if(str.split(',').length<rank) return "Not enough participants" else { const splitArr=str.split(',') let arr={} for(let i=0;i<splitArr.length;i++){ arr[splitArr[i]]=Som(splitArr[i])*weights[i] } return getValue(arr,splitArr,rank) } }
function getValue(arr,splitArr,rank){ const obje=Object.entries(arr) const flatArr=obje.flat().filter(item=>typeof(item)=='number') const bool=flatArr.map((item,i)=>flatArr.indexOf(item)==i).includes(false) let res; if(bool){ res=obje.sort() return res[rank-1].slice(0,1).toString() } else{
res=obje.sort((a,b)=>b[1]-a[1])
}
function Som(str){ const newStr=str.toLowerCase().split('') const alphabets="abcdefghijklmnopqrstuvwxyz" let sum=0; for(let i=0;i<newStr.length;i++){ sum+=alphabets.indexOf(newStr[i])+1 } return sum
}
getRank("Addison,Jayden,Sofia,Michael,Andrew,Lily,Benjamin", [4, 2, 1, 4, 3, 1, 2], 8)
Not a kata issue, that method is not available in every Node version, please mark your post as having spoiler content next time.
Solved this one in ReasonML — thanks again for another kata that... was much more of a faff to complete than it had any right to be 😆! Still, at least I'm getting better at Reason / OCaml, which I seem to be finding hard mostly because of the inflexibility of the types in the standard library (I'd just like to use one
map
for everything, dammit!)I really appreciate, g964, that you have translated this kata to Reason, as you're seemingly the only author to have uploaded any Reason-language kata at all. Thanks!
Thanks
The description of this kata is a terrible mess... Please rewrite it in actual English without the story. Just keep it simple: what is the input, what is the output and why. Currently there is "PauL" used as an example, which causes more questions than given answers. Subjectively that's the most unclear kata that I did since now.
Can someone help me? I'm doing it in javascript. This is the test I'm failing, which I'm assuming is due to sorting alphabetically.
expected 'Elizabeth' to equal 'Matthew'
What data structure should I use?
My pseudocode: I store everything in an object where key is the name, value is the score. I also store the score in an array since object is unordered. I then sort the array, which I use the value (score) to find the key in the object.
Doesn't really work when the score is the same.
I really enjoyed this kata though. For a beginner like me, it's challenging enough and not so easy where I can solve with 2 loops but still think it's doable.
It's not the scores that are to be sorted, it's the candidates. So you'd want a list of candidates, and you'd want to define how to compare two candidates (a sort key).
I don't quite understand what you mean. You're sorting candidates by their scores. I stored them in an object {candidate: score}. But if objects don't have order, then how do you sort?
This comment has been hidden.
This comment has been hidden.
You passed the kata, I tried your solution many times and it passed each time so I don't understand where your problem is. Look at the top of the page: 417 people passed the Java kata; if there were problems with the tests (moreover the fixed tests are the same in all languages, passed by 3948 people) somebody would have already seen them.
This comment has been hidden.
I really wish more time was taken to write proper expectations around the result. I think more time is spent trying to understand the verboseness of the task.
Nice kata, very brain shaking !
Thanks!
Hitting attempt without any changes over and over and getting anywhere between 1 and 4 failed tests makes me think the tests are broken...
Sorry, they are not. Look at the top of the page to see how many guys passed the JS kata (886).
i know i know... those were the words of a frustrated millenial :))
Nice Kata for learning C.
Difficult but tasty.
Thanks!
My code passes the sample tests but not all the random tests. Can anybody tell me where is the problem. Thanx.
You should take a look at Python dictionaries use.
"Ethan,Sophia,Elijah,Addison,Alexander,Matthew,Abigail,Logan,Mason,Isabella,Chloe,Jacob,William,Grace,Benjamin,Michael,Lily,Aiden,Avery,James,Mia,Noah,Ava", [ 3, 4, 4, 4, 4, 1, 4, 1, 6, 3, 5, 3, 3, 5, 1, 3, 1, 2, 4, 4, 1, 3, 5 ], 2), "Alexander") case gives mecorrect result in ide and gives error it test.. JS
let albt = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] let vinNum = st.toLowerCase().split(',').map( (el,i) => (el.split(''). reduce( (acc,cur) => acc + +albt.indexOf(cur) + 1,0) + el.length) * we[i]); let lst = st.split(',').reduce( (acc,cur,i) => { return acc.push([cur,vinNum[i]]),acc; },[]).sort(([a,b],[c,d] ) => d - b ).sort(([a,b], [c,d]) => { return b === d && a.length === c.length ? -1 : 0; }); return lst[n-1][0]; }
console.log(rank("COLIN,AMANDBA,AMANDAB,CAROL,PauL,JOSEPH", [1, 4, 4, 5, 2, 1], 4), "PauL"); console.log(rank("William,Willaim,Olivia,Olivai,Lily,Lyli", [ 1, 1, 1, 1, 1, 1 ], 1), "Willaim"); console.log(rank("Elijah,Chloe,Elizabeth,Matthew,Natalie,Jayden", [ 1, 3, 5, 5, 3, 6 ], 2), "Matthew"); console.log(rank("Ethan,Sophia,Elijah,Addison,Alexander,Matthew,Abigail,Logan,Mason,Isabella,Chloe,Jacob,William,Grace,Benjamin,Michael,Lily,Aiden,Avery,James,Mia,Noah,Ava", [ 3, 4, 4, 4, 4, 1, 4, 1, 6, 3, 5, 3, 3, 5, 1, 3, 1, 2, 4, 4, 1, 3, 5 ], 2), "Alexander");
How to see the test inputs. Can any let me know as soon as possible.
Print them.
This comment has been hidden.
The alphabetical order is ascending, so E goes before J, and the 8th in the list is James.
Noted. Thank you for your help!
What don't I understand on the example test rank("Lagon,Lily", [1, 5], 2) == "Lagon")
ranks = [(54, 'Lagon'), (310, 'Lily')] 'Lily' is the second ranked name, why is 'Lagon' the desired name? No one else seems to have this problem. Any clues appreciated.
Why do you say
Lily
is the second one?These instructions are the problem. The rank needs to be decending order but that wasn't clear. it works for the Benjamin case since it is perfectly in the middle of the ranked names. Got it.
It's written in the kata description (so, at least for me, it's pretty clear), when something is not clear (for you) read it once again, sometimes the answer is already there.
The condescending tone isn't needed.
It's not condescending, it's an advice for all katas in general, I lost count of how many times I (or someone else) had to explain something that's already there, and simply reading it twice (or once, some people didn't even read the kata description and then complain about his/her code being right and the tests/description/everyone else being wrong) would do the click.
As it mentioned in the description:
"Now one can sort the firstnames in decreasing order of the winning numbers". So:
Proper OUT: 'Lagon' #(it has less "winning numbers")
the problem with these questions is not that they're hard its that i legit spend decades trying to understand the questions...i dont get an answer at the end
I have a question about last step, it says that if there is two names with same score, we should sort it by there first name, in case Matthew and Elizabeth, test case says that Matthew is the output, but why? E is coming first not M, and output should be Elizabeth, who can explain it?
If you're talking about this test case →
rank("Elijah,Chloe,Elizabeth,Matthew,Natalie,Jayden", [1, 3, 5, 5, 3, 6], 2), "Matthew")
Elizabeth is indeed before Matthew but the test asks for the one in 2nd place. Hence, Matthew is the correct answer.
I don't understantd your answer, In my case, Matthew and Elizabeth get the same score, so it's Elizabeth's win because E is comming before M.
In the next example, you have the same case : rank("Aubrey,Olivai,Abigail,Chloe,Andrew,Elizabeth", [3, 1, 4, 4, 3, 2], 4), "Abigail"), Abigail and Chloe get the same score and it's Abigail's win.
There is something that I don't understand.
EDIT : I'm a stupid monkey, I got it, sorry for my useless comment
thanks
Aiden,Logan,Aubrey,Michael,Lily,James,Abigail,Lagon,Mason,Willaim,Ethan,Emily,Robert,Jayden,Benjamin,Andrew,Isabella, [5,3,2,6,5,3,3,2,2,1,6,3,4,1,4,1,3], 7 Log [ 190, 162, 156, 348, 310, 159, 144, 108, 134, 86, 318, 207, 336, 65, 304, 71, 207 ] It should work for random tests too - Expected: 'Isabella', instead got: 'Emily'
Hmm I thought that E is before I
Whether E comes before I is one of many things to consider, why do you mention that in particular?
have you solved that issue? what is the other things to consider? in description it says that we should sort alphabetically nothing more
You're right E comes before I. Here are the results of the test case you provided, sorted →
[ 'Michael', 348 ] [ 'Robert', 336 ] [ 'Ethan', 318 ] [ 'Lily', 310 ] [ 'Benjamin', 304 ] [ 'Emily', 207 ] [ 'Isabella', 207 ] [ 'Aiden', 190 ] [ 'Logan', 162 ] ....
Isabella is the one in 7th place so the test works just fine. Maybe you got something else wrong.
Ugly Kata
I can't seem to pass the test case where Matthew and Elizabeth are supposed to evaluate to the same total value, and thus be sorted alphabetically. My issue here is that those two names don't amount to the same total value. I tore my logic apart and went through the hard way, matching chars up by their place value; I can't find a way where the two names would ever have the same value... I am operating under the assumption that both lowercase and uppercase letters are treated identically concerning value, as this appears to be made implicit through the examples given. (so "A" == 1 and "a" == 1, meaning that a downcased name is equivalent to the mixed case, or uppercase equivalent; so "Elizabeth" == "ELIZABETH" == "EliZabETh" etc etc)
First, the letters and their associated values: alpha_value = { "a"=>1, "b"=>2, "c"=>3, "d"=>4, "e"=>5, "f"=>6, "g"=>7, "h"=>8, "i"=>9, "j"=>10, "k"=>11, "l"=>12, "m"=>13, "n"=>14, "o"=>15, "p"=>16, "q"=>17, "r"=>18, "s"=>19, "t"=>20, "u"=>21, "v"=>22, "w"=>23, "x"=>24, "y"=>25, "z"=>26}
Elizabeth split into chars (downcased for ease) and valued out by char
[["e", 5], ["l", 12], ["i", 9], ["z", 26], ["a", 1], ["b", 2], ["e", 5], ["t", 20], ["h", 8]]
sum of letters:
5 + 12 + 9 + 26 + 1 + 2 + 5 + 20 + 8 == 88 # true
Matthew split into chars (downcased for ease) and valued out by char
[["m", 13], ["a", 1], ["t", 20], ["t", 20], ["h", 8], ["e", 5], ["w", 23]]
sum of letters:
13 + 1 + 20 + 20 + 8 + 5 + 23 == 90 #true
Given the names and weights for the test case
"Elijah,Chloe,Elizabeth,Matthew,Natalie,Jayden" [1, 3, 5, 5, 3, 6]
I would reason this out to be:
names_array = ["Elijah", "Chloe", "Elizabeth", "Matthew", "Natalie", "Jayden"] weights = [1, 3, 5, 5, 3, 6]
Which would mean that the respective "weights" of each name in question is 5
So based on the weights, and the totals of the characters, they come out to
different values...
elizabeth = 88 * 5 ==> 440
matthew = 90 * 5 ==> 450
Based on this step by step, I can't see where I might be going wrong with the calculation. They have different total values based on the characters in the names and the assigned weights. Why would "Elizabeth" not be ordered after "Matthew" in this context?
You should read the description once more.
did get the answer for this one?
Abishek21, elizabeth = (88 + len(elizabeth)) * 5 ==> 485; matthew = (90 + len(matthew)) * 5 ==> 485.
JavaScript
Could anybody help me, please?
My code works correctly with all basic tests except two: ("Aubrey,Olivai,Abigail,Chloe,Andrew,Elizabeth", [3, 1, 4, 4, 3, 2], 4) Expected: 'Abigail', instead got: 'Chloe' and ("Elijah,Chloe,Elizabeth,Matthew,Natalie,Jayden", [1, 3, 5, 5, 3, 6], 2) Expected: 'Matthew', instead got: 'Elizabeth'.
Both of them I counted manually and got the same result as my code. What is wrong?
Are you getting a score of 108 for PauL in the example in the description?
This comment has been hidden.
looks like this has been discussed here below and yeah, and after reading it i'm still not understanding at all-- not my "solution", but the problem.
w/e
Oh, really, it was another number.
Thanks for your comment). It helped me to find my mistake.
It's definately hardest kata of 6kyu I've completed ever. Maybe it should be defined as 5kyu?
This is by far the hardest 6kyu I've completed. Most 5's and even some 4's that I've solved are easier. Is there any consideration for regrading this Kata?
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Gave up trying to fix my code to deal with ties - this is way too hard for 6kyu
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
The
Nim
version can not be completed due to getting warnings from the test suite & receivingExit Code: 1
, despite all of the test cases passing.I changed "random" (deprecated) to "rand" so you don't have warnings anymore. But that was not the warnings which prevented you of passing... The warnings never prevent you to pass.
No; unfortunately the testing function was in a place where
check(actual == exp)
was not functioning hence the "passed" in green. In fact your solution passes all the tests except one when the given string is empty and where you have to return "No participants" (the description says "If st is empty return "No participants"."). Sorry for the warnings:-( they didn't appear when I translated long time ago and there were no complaints because almost nobody takes Nim at CW.The C test code does not adhere to the description in case of no participants. The description requires "Not enough participants", whereas the test code checks for "No participants"
Maybe you should have another look. Description sys:
As far as I can see the reference solution tests these two cases.
You're right, glossed over that!
.
This comment has been hidden.
It is not a problem; all you need is that the length of the weights is longer or equal to the length of the names so you can apply a weight to the corresponding name.
This is perfectly ok, obviously, this does not make solving the problem impossible. What I would like to say is if this is intentional (as it appears to be) than this should be stated in the problem description: "It is guaranteed that the weight array is at least as long as the number of names" or similar. There is no public test case that would call attention to this possibility.
Modified, thanks.
Thank you. :)
This comment has been hidden.
Read this
Ouh .. interesting, thank you very much !
Im hardstuck with the " When two people have the same winning number sort them alphabetically by their firstnames." , someone managed to solve this with a HashMap / Treemap ?
Use Objects and sort them
Still stuck, here is what I have so far. I tried putting the entire code into a Try Except - but it still didn't show me the test case that was failing. Passing all the basic tested up to #18
def rank(st=9999, we=9999, n=9999): try: print(st,we,n) st = st.split(',')
OP solved it, closing
Ok, I can't understand this. My code (python) works in every single instance except for where the code is telling me it's supposed to be returning Matthew instead of Elizabeth. The system isn't reporting the test parameters to me, so my only assumption is that both numbers have the same weight, otherwise this wouldn't be an issue.
Elizabeth has a total value of 97, Matthew has a total value of 97, if they're the top contenders and they're tied then Elizabeth needs to be returned, but the test keeps saying Matthew is the correct answer, and that's can't be right. This is the only test that's failing, can someone please help me understand what I'm missing here without referring me to the comments below? I've read them all, the solution isn't there.
Print the input, why are you assuming things? And this was in the comments below.
You need to return the second person, if they're tied, they should be ordered as Elizabeth, Matthew, who's the second person there?
It says to sort them in alphabetical order in the case of ties.
I have this same problem! both equal 97. both have weights of 5. both score 485.
As far as I'm aware, Elizabeth comes before Matthew when sorted Alphabetically!
Any ideas?
I'm trying to solve this with python and I am getting the following: STDERR Traceback (most recent call last): File "main.py", line 85, in randomTests() File "main.py", line 83, in randomTests Test.assert_equals(rank(st, we, k), rankSol(st, we, k)) File "main.py", line 52, in rankSol res.append([f[i], we[i] * scoreSol(f[i])]) IndexError: list index out of range
I know list index out of range is usually from calling an out of range index value on a list, like lista = [0, 1, 2] and then I try and run lista[3] but I am not really sure where this could be happening in my code. Any thoughts are appreciated!
Thanks!
This comment has been hidden.
You returned Elizabeth.
As far as I know there is no problem in the testing since 67 guys passed the C kata. Moreover I tried a few solution and all worked fine.
Update: You should read https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution.
Granted, but if the st passed is "Lagon,Lily", and my function simply processes the given arguments, how could "Elizabeth" even be a possible result of the function? As I said, it returns "Lagon" on my own system when given the exact same arguments.
Print your array "names" before your return. When I do that in your solution I get "Lily", "Elizabeth" and your return is ofc Elizabeth...
Try on your system not only that test but several tests in a row and you will see. Or add this test
at the end of the "Sample Tests". Your answer will anew be Elizabeth.
Oh, how embarrassing. All figured out, thank you for the guidance. Please ignore me! I need to study more on stack & heap memory, I reckon...
Morality of the story: don't post issues too fast:-) It tooks me time to examine your solution:-(
Understandable. I suppose I should've tested it more vigorously on my system, as I got the altered result when I did several tests in a row. I will write a template that'll help me test katas on my system more readily in the future. Apologies for the inconvenience and thank you for the help!
Thanks for your post and good luck with C:-)
Hey i got a error saying
I imported java.util.*; but it's still showing me same error what should i do?
Nevermind, i figured it out!
Hey I got the following compilation error when I try to solve this kata in ocaml
The error message doesn't really make sense to me, and I cannot reproduce it on my local machine (I passed the test and the code can be compiled locally)
Wonder if I can get any help here, thanks
I modified the reference solution so you have no more warning about "deprecated". Nevertheless I tried your solution and got:
so there is an error in your code. I tried other solutions that worked fine. Cheers!
Thanks for the help, but I still cannot figure out the error message. The line number provided does not match my source code, and the type error also confuses me as I don't have any variable with type
(int * string) array
Is there any way I can access more information about how the code is compiled and tested? For example, what does this "fixture.ml" look like?Fixture is the file with the final tests. Are you sure you're returning values of the correct type?
After spending a lot of time all I can say (it is not much but I can't do better:-(:
Sorry, I can't give "fixture.ml" because it represents the tests when you "attempt"; moreover the lines numbers are difficult to interpret because the "solution", the "preloaded part" and the "tests" are concatenated together. Maybe you could try to adapt yor solution without "open String" / "open Char".
Thanks, that actually answers most of my confusions. I will try refactoring my solution without Stdlib
Huge thanks, it turns out I don't need to
Open String
norOpen Char
,It's my first time to use ocaml to solve puzzles, and I'm not very familiar with ocaml either.
Really appreciate the help
I am very happy to see that you have passed the kata! Thanks for the feedback!
I think this kata is for 5th kyu, not 6th. A lot of work.
Agreed. I was even thinking a 4, most 5's are easier than this one.
Is there a way to flag a Kata? Because during the attempt phase the input is not shown. Therefore, it is extremely difficoult to find where the code goes wrong.
Flag as what? I've already told you how to print the input in the post below, isn't that enough to debug your code? You should really learn that if you want to program in real life. Using
print
isn't extremely difficult in any way.basically, what you've done right here is correct: a suggestion. if the kata were broken (and you can provide some evidence or reasoning for it) you would post as an issue. meanwhile, you cannot expect all kata to display everything, so you need to do what Chrono79 says, print 'em, yourself. I prefer to print strings like this:
print("st -->" + st + "<--")
so you will not miss an empty string or leading or trailing whitespace which may be critical to solving the kata. if it's not a string, simply useprint("x =", x)
. hope that helps, good luck!It is unfortunate, that the test results do not show the input. Therefore, it is very difficult to figure out where the code goes wrong.
Can't you print it yourself?
Print what ? I only get the information about the output. I do not see the information about the input during the attempt phase
print(st, we, n)
<- that. It'll appear above the test result in the Output tab.Thanks that is great.. I did not think that could work
From the question:
"An array of random weights is linked to the firstnames and each som is multiplied by its corresponding weight to get what they call a winning number."
The Example: PauL -> som = length of firstname + 16 + 1 + 21 + 12 = 4 + 50 -> 54 The weight associated with PauL is 2 so PauL's winning number is 54
Given that part 1 states that "each som is multiplied by its corresponding weight", this doesn't make sense. Surely PauL's winning number should be 108, not 54.
Did you read the sentence until its end? It clearly says:
Cheers.
Thank's and sorry, I guess the remainder of the question was hidden off screen.
Next time I will try to select the example and see if I can scroll across.
My code in C keeps passing most of the tests but fails one, returning "Test Crashed, Signal Code:11". I know it stands for segmentaion fault but this doesn't really seem right. Is there anyway I could see what the test exactly was, since there is nothing concerning this particular test in output log?
Not an issue of the kata. Look at the top of the page and see how many people passed the C kata. Cheers.
Yeah, still is there any way to see what test my solution fails exactly?
Try to print inputs.
Thank you.
I am trying to print from within my solution, but I get nothing. Nothing is printed from the tests before calling my script. It is very difficult to find the seg fault without some type of print statements.
@jchavez1992 what you printed might still be buffered when you segfault. try flushing.
This comment has been hidden.
Your code also fails in repl.it. It's a problem on how you're sorting, you're mutating the names array at the same time you use it to get the original order, use a shallow copy.
That worked like a charm! I made a copy of "names" as you said. Thank you very much for your time! I learned something today, cheers
Any clues why my code returns the correct result when checking it on the local console and the wrong one when trying to pass the test on CodeWars? It happens in the Basic test (the first one) and in several of the random ones.
Use
Question
label for things like this:With so little detail, it's only guesswork and it's very hard to help you.
Thanks for your reply. Sorry it was my first question on the site and I don't know why I thought everybody could see my code. I will post a more complete question with the label and use the spoiler flag.
I think description should mention that there are possible situations where number of weights can be more than number of participants.
Test Case Number 2: WHY ==> 'Elizabeth' should equal 'Matthew' i am calculating their values to be both 485, so alphabetically is Elizabeth 1st. i am getting 66 Passed Tests and 2 Failed, both same case as this.
Please read posts below. The question has been put and answered many times.
Rename the partial value of the instructions to something else, n is already used as a function's argument and that's a little confusing.
Something like that or whatever name not used in another part you want would be fine.
Description modified. Could you have a look? Thanks!
That's better, one last thing I would change is make all PauL's the same capitalization.
OK. I hope it's correct now:-)
For me it is. Thanks.
Hi, I'm definitely missing something, so could someone please clarify? - If n is calculated by the first name length + rank of each letter in the name, why is n provided as an argument in the function? I would think we would get the string argument, weights argument and then calculate n ourselves, using it to calculate the 'winning number'... Thanks for your help
There are two
n
s there, one should be renamed.Like that ^.
See above.
Why I'm see different result of sorting array in Chrome and site (Codewars) on some random tests? Visual Studio Code give result like codewars and I'm not understand it. Code in clear Chrome work perfect.
It's a good challenge, but the obscurity in the description takes away from it's value. The description on this kata could make a few things a little more explicit:
. The best kata's are the one's which present clear rules for answering the challenge, and the challenge is implementing those rules into code.
I am very sorry that I don't have your smartness and great quality of explanation but I don't regret not to be a native speaker. You will be fortunate if your clients give you clear rules... Regards.
I accept your apology, and thank you for the compliments to my greatness. And yes I'm fortunate, because getting clear instructions from my clients comes from Understanding English well. BTW, I'm not a native English speaker either.
I like problems with multiple element sorting. Thanks!
My program can't find the another name of a duplicate score HUHUHUHUHUHUHUHU
This comment has been hidden.
The problem is in your sorting code, in repl.it it also returns Lyli instead of Lily.
This kata hates me!!! expected:<N[ao]h> but was:<N[oa]h>
So what? These are 2 different names.
how?
Noah Naoh
Sorry HUHUHUHUHUH
nice kata,cheers !
Thanks!
Some assistance please,
For the F# test case with the following inputs: st = "Addison,Jayden,Sofia,Michael,Andrew,Lily,Benjamin", we = [|4; 2; 1; 4; 3; 1; 2|], n = 8
n = 8, but there are only 7 names?
Is this correct?
Read the description again.
Sucks, I never read the Notes.
@g964 Thanks for replying.
Hi. Can someone help me with the problem? When I run my code of this task in another place (www.codepen), I receive a correct results of incorrect tests.
Hey g964,
I'm a fan of your katas. Is there any way to get in touch with you on a 1-on-1 basis please?
regards, vish
You can go to https://gitter.im/Codewars/codewars.com and try to open a private channel.
hello, I have joined the room at the link you have mentioned but how do I open a private channel? appreciate some help here.
I opened a private channel. You should see it on the left panel: "ALL CONVERSATIONS".
Thank you. I have responded in the channel you have opened.
OK.
Are the random tests for javascript wrong? My solution passed all the fixed tests, but fails on the random ones. I tried submitting my solution on TypeScript and it passed.
It's a question, not an issue. Look at the top of the page and see how many guys passed the JS kata; if tests were wrong somebody would have already seen it. Cheers.
I am just saying that the random tests in JavaScript are producing different results than my accepted solutions in Rust, C# and TypeScript.
Please could you give some examples?
Testing Rank: st="Emma,James,Jacob,Madison,Naoh", we=[1,6,5,1,3], n=2
Expected: 'James', instead got: 'Jacob'
I lost my time... For your example: JS, Rust, C# and TypeScript give the same expected
"Jacob"
. I suspect you mutate the input string (?).Then my solution for TypeScript also would not pass, because they are functionally identical.
This comment has been hidden.
JavaScript, all tests passed, except one, where: Expected: 'Willaim', instead got: 'William'
Check that.
Thank you! Good kata! ;)
I don't think the tests in Rust are accurate. I'm fairly certain I have a working solution but I am still failing the tests and the asserts are not making sense.
Could you provide an example? I don't do Rust, but I can check the expected result with other language and tell you if it's a problem with the rust translation or it is a problem with your code.
For this test case it is expecting the answer to be Matthew but I'm getting Chloe. What is confusing me about this is Matthew is coming out to be the largest in my code. testing("Elijah,Chloe,Elizabeth,Matthew,Natalie,Jayden", vec![1, 3, 5, 5, 3, 6], 2, "Matthew"); Thank you for your help Chrono79
That test is ok, so the problem should be in your code. Check below, mmacak28's post, where I explained it (somehow) without spoiling it too much. Chloe is the second but in ascending order.
Maybe you're sorting the list in the wrong order?
Clojure kata fails on this testcase: n = 3 | we = [5 5 3 2 1 3 6] | st = "Avery,Olivai,Sophia,Michael,Elizabeth,Willaim,Liam,AsToR"
st contains 8 names, but we is of length 7. Please look into this.
Modified, thanks!
Thank you. Issue resolved now.
Kotlin translation submitted here
Approved some time ago
I can't help but wonder whether or not this is really a 6 kyu(I think it is harder than the 6 kyus i've completed), but my main criticism is that the sample tests aren't verbose enough to catch issues that would arise from not handling parsing lowercase / uppercase properly.
This comment has been hidden.
You're not doing that, check again.
you are totaly right, thanks ;)
Hi! I created Go translation of this kata. Please take a look: https://www.codewars.com/kumite/5bef24a4aef7123f4700023c?sel=5bef24a4aef7123f4700023c
Approved some time ago
There is an issue when N == Size test it expecting for "Not enough participants" result, though there are enough participants. So i tweaked my solution N - 1 like that it worked, but i think the test might be wrong.
You think or you are sure:-) Can you give an example? The reference solution returns "Not enough..." when n is greater than the number of participants. Moreover I am astonished since 164 guys passed the C++ kata and nobody would have seen that? You have (well?) solved the kata so now you can look at the tests and at the reference solution so you will maybe have a better view. Cheers.
so just like what seems to be everyone else I cant really get it to work when I attempt. It works really well for the most part but with the “William” I get an error, which leads to mistakes in the random part. Now I would like to the the parameters the attempt run on so I can fix this.
Thanks for any help!
You could print the input.
Thanks I'll try that!
I am passing all of tests cases except of one with "Elijah,Chloe,Elizabeth,Matthew,Natalie,Jayden" I get Matthew and Elizabeth with n = 485 and I dont understand why Matthew should be returned and not Elizabeth. I would be grateful for any hint
This comment has been hidden.
Thanks, it's working now
I'm not clear on the instructions and the purpose of calculating the winning number for each person, do we have to sort each winning number-person pair, and then return the name whose index= n? If someone can paraphrase the whole instruction more clearly, I'd really appreciate it
This comment has been hidden.
Thank you for this. I recommend naming the variables explicitly next time. For example naming
n
what ever that was (index_of_winner
?) andwe
(weights
?). Such short names are advised against in books such as clean code because it unnecessarily obfuscates the codes meaningThanks, that was fun
Thanks!
Upon returning to this kata, I've found out why it acts strangely in C. Sometimes, during random testing, there will be a comma at the end of the list of participants, which, if you're counting participants using the delimiting character, will make the program crash. I think it is pretty ridiculous to have to account for this, when the kata does not specify anything regarding empty elements in the list. Additionally, since the sample tests do not have any cases like this one, it makes it kind of cryptic to decipher the issue. It would be nice if this could be revised. Thanks.
This comment has been hidden.
This comment has been hidden.
Help please!
Hi, first of all, congrats for the kata, it's nice!. I've written my code and it passes most of the test (but not all). Focus on basic test, my code passes 16 of 18 tests. I've been reviewing my code for long time but I don't find the error, I need help. I write in console lots of logs in order to help me, and this is the result:
Data entry: st = Elijah,Chloe,Elizabeth,Matthew,Natalie,Jayden we = 1,3,5,5,3,6 n (position searched) = 2 letter E weigths 5 letter L weigths 12 letter I weigths 9 letter J weigths 10 letter A weigths 1 letter H weigths 8 length of Elijah = 45 weigth of Elijah = 1 winning number of Elijah = 45 letter C weigths 3 letter H weigths 8 letter L weigths 12 letter O weigths 15 letter E weigths 5 length of Chloe = 43 weigth of Chloe = 3 winning number of Chloe = 129 letter E weigths 5 letter L weigths 12 letter I weigths 9 letter Z weigths 26 letter A weigths 1 letter B weigths 2 letter E weigths 5 letter T weigths 20 letter H weigths 8 length of Elizabeth = 88 weigth of Elizabeth = 5 winning number of Elizabeth = 440 letter M weigths 13 letter A weigths 1 letter T weigths 20 letter T weigths 20 letter H weigths 8 letter E weigths 5 letter W weigths 23 length of Matthew = 90 weigth of Matthew = 5 winning number of Matthew = 450 letter N weigths 14 letter A weigths 1 letter T weigths 20 letter A weigths 1 letter L weigths 12 letter I weigths 9 letter E weigths 5 length of Natalie = 62 weigth of Natalie = 3 winning number of Natalie = 186 letter J weigths 10 letter A weigths 1 letter Y weigths 25 letter D weigths 4 letter E weigths 5 letter N weigths 14 length of Jayden = 59 weigth of Jayden = 6 winning number of Jayden = 354 [ { name: 'Matthew', weigh: 450 }, { name: 'Elizabeth', weigh: 440 }, { name: 'Jayden', weigh: 354 }, { name: 'Natalie', weigh: 186 }, { name: 'Chloe', weigh: 129 }, { name: 'Elijah', weigh: 45 } ] Expected: 'Matthew', instead got: 'Elizabeth'
================================================================ I hope someone can help me because I follow the figures until the last array (sorted) and I don't understand why "Matthew" is expected in position 2 in this test. I assume the kata is correct and I'm wrong, so I'll be grateful if someone can help me. Thanks in advance.
Length of Elijah is 6 and you have to add that to the sum of the letter values before multiplying it by the weight. Check the example again:
PAUL -> n = length of firstname + 16 + 1 + 21 + 12 = 4 + 50 -> 54 The weight associated with PAUL is 2 so Paul's winning number is 54 * 2 = 108.
Add the length of the name onto the sum of the values of all its characters, and times that by the weight. It looks like you are getting some values mixed up or something.
Got it!!! Tons of thanks Chrono79 and Avanta for your help!
Good day
Input: Addison,Jayden,Sofia,Michael,Andrew,Lily,Benjamin 4, 2, 1, 4, 3, 1, 2 n=4
Output:
This is incorrect test? Or maybe i've got logical mistake somewhere?
Please look at the top of the page and see how many guys passed the C++ kata. When you ask for something don't post an issue but a question.
The numbers for Jayden and Benjamin are wrong.
For those who think your solution is correct make sure reorder your rank by name if two or more people have same score. Stuck on there for a while
Hey, I have a problem, I run my code on local and it works perfectly for all cases, but when I tried to run it in this page it doesn't work, any idea why?
There is no problem with this kata! 955 guys passed it.
Thanks, I had a problem with ".compare()" function, it indeed works
I am unable to complete this kata in C. My program runs all the sample tests, as well as any tests I run myself outside of this. However, during random testing, it gets through (on average) 30 tests before one just segfaults the program and fails. It gives me absolutely no way to fix the issue, as I cannot reproduce it locally and it doesn't tell me what input it tried using that crashed the program. It doesn't seem to follow any pattern, it just will sometimes get tripped up and crash. I cannot complete the kata.
There seems to be a problem with the test for the alphabetical order of the winners... "Matthew" does not come before "Elizabeth" in case both have the same points.
Nice kata. Thank you.
Thanks!
Hi. May you can help me with test module? My code has passed all basic test, but when I want a atempt code I saw:
STDERR: ValueError: ....
That not possible in my solution. What to do, that pass the problem?
P.S. I'm sorry, if you can't understand me. My english skill is low, but I will fix it. I'm promise
Hi! Can you help me please? I don't understand an example. "#Example: names: COLIN,AMANDBA,AMANDAB,CAROL,PauL,JOSEPH weights: [1, 4, 4, 5, 2, 1] n: 4 The function should return: PauL" But: C O L I N (3+15+12+9+14 + 5) * 1 = 58 A M A N D B A (1+13+1+14+4+2+1 + 7) * 4 = 172 A M A N D A B (1+13+1+14+4+1+2 + 7) * 4 = 172 C A R O L (3+1+18+15+12 + 5) * 5 = 270 P A U L (16+1+21+12 + 4) * 2 = 108 J O S E P H (10+15+19+5+16+8 + 6) * 1 = 79
So, sorted names: Colin, Joseph, Paul, Amandab, Amandba, Carol. n = 4. So, answer is Amandab!!!! Why you wrote that answer is Paul??
Have you solve this issue? I have the same problem.
No, I had not resolve this issue.
g964, could you answer the question please?
I don't want to be unpleasant but did you see this part of the description?
thank you very much. I missed the word "decreasing"
Interesting problem, but I voted it down because of a lot unnecessary annoyances - e.x.
234 Aubrey 226 Elizabeth 213 Andrew 192 Chloe 192 Abigail 74 Olivai why its abigail ? why abigail is higher than chloe ? (since c > a ) dunno whats wrong here, help
Hard to answer if you don't show the whole test set, if it is this one: rank('Aubrey,Olivai,Abigail,Chloe,Andrew,Elizabeth',[ 3, 1, 4, 4, 3, 2 ], 4 ); You have miscalculated Elizabeth rank (not that it matters in this case), and even then Abigail should be before Chloe because of this: When two people have the same winning number sort them alphabetically by their firstnames. So A goes before C.
st = "Elijah,Chloe,Elizabeth,Matthew,Natalie,Jayden" we = [1, 3, 5, 5, 3, 6] n = 2
//If A goes before C in the previous answer, I dont understand why Matthew is the right answer here where Elizabeth's winning number = Matthew's = 485..
Read the first post (mmacak28) answer, he asked for the same test and I already answered there.
Read the instructions really carefully, there's a lot going on. The bit about adding the length of the array to the name's score before multiplying by the weight is easy to miss.
The length of the firstname is added to the sum of these ranks hence a number
n
.PAUL -> n = length of firstname + 16 + 1 + 21 + 12 = 4 + 50 -> 54
length of firstname
= 4 not 3And random tests will fail (e.g. C#).
Because ranks are numbered from 0 in tests solution.
This contradicts to the condition.
There are no error in the tests, 729 guys passed the kata (81 with C#) as you can see at the top of the page.
Length of firstname is numbered from 0 in random tests. But description says count from 1. Length of PAUL is 4 not 3. It's not a problem with sample tests. But a big problem with random tests. Here small example.
st = "Matthew,John,Bob"
we = [16, 33, 70]
If length is numbered from 0.John = 1683
Matthew = 1552
Bob = 1540
If length is numbered from 1.John = 1716
Bob = 1610
Matthew = 1568
Best C# solutions calcs the score with length which numbered from 0.
I think you could read again the description:
Ranks are numbered from
1
, not firstnames or names length.Sorry. My mistake.
The frustration is real. For the first time, I struggled to understand a kata description.
Would appreciate any help. My logic:
sum
of letters per namesum
sum
by corresponding weight (we
) - get thewinning number
At what point should I engage the 3rd argument
n
?Description says:
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
I could not agree more. The description does not make any of these details clear.
This comment has been hidden.
../home/codewarrior/spec.ts(1,1): error TS1084: Invalid 'reference' directive syntax. ../home/codewarrior/spec.ts(2,1): error TS1084: Invalid 'reference' directive syntax. For typescript.
This bug is rather usual at CW. You correctly write it but it is badly saved... Fixed, thanks!
This comment has been hidden.
Already mentioned
it was a difficult description for me. It would be nice, if you add result array
I think that also in PHP there're some issue regarding the sort order of the cases with more than 1 result,
In one case I obtain "Elizabeth" and "Matthew" and the right one was "Matthew" (So inverse alphabetical order) but in another test with "Abigail" and "Chloe" the right one was "Abigail" (So alphabetical order).
Can be that there's some mess in the test at this point, with the reverse order I'll pass also all the standard test under the exercise but during the submit there's no way I can find the right sorting.
There is no error in the tests. Look at the top of the page: 58 guys passed the PHP kata. Don't post an issue if you are not sure of your code, post a question otherwise you mke the author lose honor:-(
This comment has been hidden.
I wish the problem statement would be more detailed in describing how the winner is chosen if there are equal ranks. Without checking the discussion thread and test cases, I would not figured out what was wrong in my understanding of the problem.
In general, the kata is fine and requires you to understand what is the best way to represent the participant records.
Sorted Elizabeth and Matthew alphabetically as both 'joint' first winners with 485, means elizabeth comes first, and matthew therefore second.
This testcase is wrong!?
st: Addison,Jayden,Sofia,Michael,Andrew,Lily,Benjamin / we: 4, 2, 1, 4, 3, 1, 2 / nth: 4 Expected: Benjamin Error. Expected Benjamin but got Addison
Sorry but no tests are wrong.
Wish this kata had better examples and explanation.
Hello, I'm not realy good in English, so can u help me to understand, what is the "n" in input data ("name, name,.. ,name", [weight, weight,.., weight], that n). what should i do with this array: [Addison] => 292 [Jayden] => 130 [Sofia] => 55 [Michael] => 232 [Andrew] => 213 [Lily] => 62 [Benjamin] => 152
Is it the position in rightly sorted array?
Yeah its the position in the rightly sorted array, but the rightly sorted array is from top to bottom so [Sofia] => 55 [Lily] => 62 [Jayden] => 130 [Benjamin] => 152 [Andrew] => 213 [Michael] => 232 [Michael] => 232 if n is 4 then Bejamin is the pick
(JavaScript)
Hey I tried to make this kata but when the solution is evaluated with randoms say me that the name is wrong, i checked manually and the solution is correctly
Example:
Testing Rank: William,Aubrey,Michael, [3,1,6], 2
Solution:
[ 348, 258, 78 ] [ 'Michael', 'William', 'Aubrey' ]
Result:
✘ It should work for random tests too - Expected: 'Aubrey', instead got: 'William'
Note: The problem is only with randoms
I don't understand what happened. I ran your example with the random tests solution and it gives the result as "William":
Test.assertEquals(refRandomTestSol("William,Aubrey,Michael", [3,1,6], 2), "Aubrey");
(false result "Aubrey" to see if we get the correct "William")returns: Failed 1
Expected: 'Aubrey', instead got: 'William'
this shows that the good result is effectively "William" with the refrence solution used by the random tests.Maybe you should try again. If you want you can give your solution (mark it with spoiler) and I will try it. 49 guys passed the JS kata. I am afraid your code modify the input. It happens oftn with beginners but it is very bad practice. Tell me, please.
This comment has been hidden.
In that line:
we[i] = (names[i].length + names[i].toLowerCase().split('').map(.........;
you are modifying the input arraywe
so the program will go on with a bad arraywe
... Bad practice, I told you:-) You should use another array to collect your results.ok thanks, I´m going to correct that
(Python) Hi, I´d like to know, what is the test for this result: ✘ 'Chloe' should equal 'Abigail'
Print the input.
Ive completed this Kata but I can't see other peoples solutions. It says I have not completed it!
Not a bug of the kata but a CW bug! Report as a bug: Forum -> Bugs.
I'm not sure what his point is with receiving n. The other things with receivng and working with the string and array I understand.
I'm hoping to get some clarity as I appear to be having issues producing the correct output when there is more than one name with the same winning number.
In the description, you state: "When two people have the same winning number sort them alphabetically by their firstnames."
To clear up any confusion, I modified my code so that the output returns the first name that starts with a letter with a lower rank ("A" = rank 1, "B" = rank 2, etc.), basically in alphabetical order. When that didn't work, I changed it to return the name with a leading character that ranks higher, but I got errors there as well.
As a last resort, I'm posting this comment to see if I can get some clarification on "alphabetical order".
Maybe you should have a look at: https://en.wikipedia.org/wiki/Alphabetical_order.
I know what alphabetical order is. Try reading my comment again and see if you understand the problem.
I am sorry but I don't understand your problem. Moreover no need to downvote my post, I am also able to downvote yours...
Here is the focal point of the issue:
"I modified my code so that the output returns the first name that starts with a letter with a lower rank ("A" = rank 1, "B" = rank 2, etc.), basically in alphabetical order. When that didn't work, I changed it to return the name with a leading character that ranks higher, but I got errors there as well."
Basically, using both alphabetical and reverse alphabetical orders both yield errors. This is for instances where more than one participant has a winning number. Does this clarify what the problem is?
It is not only the leading letter of a name you should take into account but the whole name.
So do you mean the sum of the ranks of each letter of the first name? Or do you mean that the order of precedence goes from the first letter, then descends down to the last letter? (an example of the latter is something like "William" and "Walliim")
Hey g964, I admit I did downvote your first reply. The reason is because it came off as dismissive and a bit condescending. I gave what I thought was a specific and pointed inquiry on what was expected of in the kata. In any case, I'll probably try out a few different formulas to see what works.
You said:
I though Wikipedia will give you better than I could gave. No dismissing and no condescending.
Yo I think one of the test case is wrong (Ruby) Below are the results I got after submit (run tests step was ok) Shouldn't it be rank 2 Elizabeth? How the hell it is expected to be Matthew? I printed both n and the array values out to check. 4 [["Addison", 264], ["Michael", 204], ["Andrew", 195], ["Benjamin", 136], ["Jayden", 118], ["Lily", 58], ["Sofia", 50]] ✔ Test Passed: Value == "Benjamin" 2 [["Matthew", 450], ["Elizabeth", 440], ["Jayden", 354], ["Natalie", 186], ["Chloe", 129], ["Elijah", 45]] ✘ Expected: "Matthew", instead got: "Elizabeth"
Your answer to: rank("Elijah,Chloe,Elizabeth,Matthew,Natalie,Jayden", [1, 3, 5, 5, 3, 6], 2) is false. You should have somethink like that: [["Elizabeth", 485], ["Matthew", 485], [".... The tests are correct. THe fixed tests are the same in all languages and 200 guys passed them.
a
What does that mean?:-)
I was stuck on this exact test case with the same results.
If anyone else reads this and thinks "this guy is right - there's an issue," just go back and read the instructions carefully! There's a small detail you probably overlooked.
Thanks for your post, I see it as an encouragement!
But wait, they have the same winning number (485) and alphabetically, E comes before M?
When I tried to submit my code, the fixed tests failed with an strange message "✘ 5". Does not seem like I break the test since nothing like "Expected: <>, Actual: <>" was printed. Would be great if any hints could be given.
This comment has been hidden.
Really good kata! Thanx!
Thanks!
I would really like to get this kata solved but it's impossible without getting any help on my question regarding C# test case. I'd truly appreciate if someone could help with this. I can post my solution here if someone tells me how to do it so that the code formats correctly here.
Like I said my problem is with this test: test1 Expected string length 6 but was 40. Strings differ at index 0. Expected: "Sophia" But was: "Names and weights array lengths not even" -----------^ at RankTests.test1 () <0x416e9610 + 0x00717> in :0
I made some console logging and in that specific test case st parameter has five names (Sophia,Robert,Abigail,Grace,Lagon) but we parameter has six items. One of my checks verifies that both must have equal amount of items (if they don't "Names and weights array lengths not even" string is returned). Does the st parameter miss one name or does the we parameter have one weight too much?
First: please don't post that as an issue since it's not a problem of the kata but a problem of your code. Do as you did last time, post it as a question. Then: nobody said that
st
parameter andwe
parameters have the same length.we
can be longer thanst
. Finally: your test must fail since instead of returning a first name ("Sophia") ofst
you are returning a string "Names and weights array lengths not even" of length 40 and so you gotStrings differ at index 0
. If I am not clear enough, tell me.Thanks for replying. As I'm a newbie here I don't know how long it normally takes to get a reply to a question. I waited for a month and thought that maybe reporting as possible issue I might get some kind of answer. Sorry for that.
In the description it is mentioned: An array of random weights is linked to the firstnames and each n is multiplied by its corresponding weight to get what they call a winning number.
That led me to a conclusion that for every name there's one weight. If there's not equal amount of weights how do I know which weight is associated with which name?
Like I said I'd be happy to post my solution code if you tell me how to do it.
There is a weight for every name if there are more weights than names; take the weights in the same order as the names. Moreover your answer should always be a (first-) name and nothing like "Names and weights array lengths not even". You can post your solution between two series of three backticks, one series on a new line, your code below on a new line and on a new line three new backticks. You can google "markdown" to better know what to do with backticks. Anyway I won't have enough time to look at your code:-(
"There is a weight for every name if there are more weights than names; take the weights in the same order as the names." Yes, that's what I was doing in my code. I implemented the check in first place as I wasn't sure if there was enough items in we array for all names (guess I was a bit too overcautious) :)
I removed the check and got the kata resolved. Thanks for your help!
Thanks for your feedback
Hi! I was able to do the sample test run successfully but got this one on submit:
test1 Expected string length 6 but was 35. Strings differ at index 0. Expected: "Sophia" But was: "Names and weights array lengths not even" -----------^ at RankTests.test1 () [0x00000] in :0
That seems to have been triggered on my check for names array length and we array length (both should have equal length). I thought for each name there must be an entry in we array. Am I wrong?
I would post my C# code here but it seems some parts of it don't display correctly (at least in preview mode).
OP solved it, closing
When runnning test all passes well, but when submitting solution "unknown error" occures on C#
It's not a problem of the kata but a CW problem. Please have a look at https://bkaestner.github.io/codewars-rules/#what-is-an-unknown-error.
Seems I'm doing something wrong. Details specify: "When two people have the same winning number sort them alphabetically by their firstnames." But when I do this a test fails (because it expects reversed order). I change the code accordingly and the test passes. But then another test fails because it expects alphabetical order.
Please could you give (correctly formatted) what you get when a test fails? Give only one or two examples and tell which language. Thanks!
Sorry, I´m new here. I get the same issue in java and in python, the example:
names:
[Elijah,Chloe,Elizabeth,Matthew,Natalie,Jayden]
weights:[1, 3, 5, 5, 3, 6]
n:2
.After following the description, both
Elizabeth
andMathew
have the same rank. And ordering alphabetically, the answer should beElizabeth
. Still, I get:Fixed Tests expected:<[Matthew]> but was:<[Elizabeth]>
As I mentioned, maybe I'm doing something wrong :(
Thanks for the help!
Which rank are you returning?
I'm returning rank 2, since:
n: 2
This comment has been hidden.
I remembered after quite some time that I had this pending, so I tried today with javascript and all worked well :)))) Thanks a lot
I'm running into the same problem in Python where it seems certain test cases conflict. Reading the kata, I interpret the problem the same way you were originally, that Elizabeth should be returned since the winning numbers for Elizabeth and Matthew are equal and E precedes M alphabetically. Accomodating that solution by reversing the sort order when test case fails, in order to return Matthew, will of course cause another test case to fail upon submission. Was it ever confirmed if the test case is incorrect in Python?
The tests are the same in all languages, 24 CW passed in Python, sorry but there are no error in the Python tests.
Hi,
I'm having the same issue as @jkapler.
On the same test, my code is returning
Elizabeth
as it has the same winning number asMatthew
, and rank 2 corresponds to their winning number. Sorting alphabetically the firstnames givesElizabeth
as ultimate winner.What did I understand wrongly in the instructions?
Since you are refering to jkapler I can only repeat what I said:
and far later jkapler answered:
The tests are the same in all languages. 29 completed in JS and 31 in Python.
Hi, Thanks for your answer, as it helps me to point where I misunderstood the instructions.
In my initial code, I was first sorting the player by winning number, taking the nth winning number, and in case of two players with the drawn winning number, then only I sorted them alphabetically and take the first one. So:
But this is wrong. According to your answer, I've understood the correct order is:
I've update my program and now all tests are running fine. Thanks :-)
Good job!
Python:
'William' should equal 'Willaim'
Typo?Not a typo! A typo would have been seen since long ago. Don't take the habit of putting an issue before knowing if it's a problem of your code or of the kata!-)
Ah, I now see it was an intended test with two equal name scores. Perhaps you should change the name Willaim to something else with the same letters (Mailliw) to make people less prone to make the same assumptions I did, although that is by no means necessary. Not a lot of people had completed this kata and since it is available in all languages so I wrongly assumed it was a typo.
oh yeah this is a pretty cryptic test result
This comment has been hidden.
This might be an interesting test case to add.
Could seem a bit vicious:-)
That looks kinda bullshit, when your program runs through all available test without issues, and even runs through test you wrote yourself, but crashes on the hidden ones. After 30 mins you start thinking that hiddens are fucked up.
Which language?