Solutions Grouping
About
This site will make an attempt to group similar solutions together so that they may be voted on and discussed as a group. If you have any feedback on how this process can be improved, this is the place to talk about it.
Discuss:
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
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Translation missing: en.models.comment.label_info.forum_topic.none
-
No Label
- Cancel
Please sign in or sign up to leave a comment.
It seems a strange design decision not to include the run-time in which a solution performed, ideally, corrected for server latency.
It would make the most sense for the solutions that performed the best on the same data set to be grouped at the top of the list, would it not?
Given the nature of algorithmic complexity, it is feasible for 10,000 lines of code running an O(n log n) algorithm to run blazingly faster than 10 lines of code written in O(n^2)
Please consider posting the time in which a solution completes along with the solution itself. Surely this would be enormously popular, and also help people to determine which coding styles actually produce tangible results.
Code to Joy
It's already been considered and you can read this issue to see why it's not likely to be introduced: https://github.com/codewars/codewars.com/issues/959
Hello moderators, can you please delete my THIRD refactored solution (for kata "Upside-Down Numbers - Challenge Edition"), cause i accidentally submitted it and it doesn't nearly contain any changes. I know also that it wont be schown in public solutions, but it takes too much space in my own solutions tab.
Thank you.
Hi,
Moderation tools aren't there for that purpose, sorry. You'll have to cope with it. ;)
Ohh, that hurts :-). Thanks for quick response.
Hi, I complete this kata(https://www.codewars.com/kata/551dd1f424b7a4cdae0001f0). It showed both in my completed and unfinished kata list. Could it be removed from the unfinished list and stay on the completed one?
Is there a way I edit the solution I submitted? It was not clean and I am a little embarrased.
You can submit a new one, but the old one will stay. You need to get over the embarrassement just like every coder does at some point. After some time, pro coders just don't care anymore :)
okay, thanks! XD
The exact same thing happened to me! I was trying to edit mine as well but apparently you can't. sucks!
how to live with that embarrassment ;_;
Hi! I have no idea. Help me to solve the recursion.
We need to draw tree with recurcion. The tree class like:
Input: (a, b, (c), d) Output:
Input: (a, second, (abc, y, (x, 7), uuu, (8, 9, (10, 1)), abcddcdba) Output:
Hey there! Can any1 give me a hand on this code?
function highAndLow(numbers){ // ...
numberList=numbers.split(' '); var result=""; var max=numberList[0]; var min=numberList[0];
for(var i=0; i < numberList.length; i++){
} result=max + " " + min; return result }
You shouldn't ask here, it's offtopic. Use that kata's Discourse.
I'm trying to solve this problem https://www.codewars.com/kata/563b662a59afc2b5120000c6/train/php in php and I arrived at a solution that passes the tests but at the time of sending it as an answer it does not accept:
function nbYear($p0, $percent, $aug, $p) { $year = 0; do{ $upYear = ($p0 * ($percent/100)) + $aug; $p0 = $p0 + $upYear; $year++; } while($p0 <= $p); return $year; }
I do not understand
What do you mean by 'it does not accept'?
@Gabr13dev: in what is that related to "solutions grouping"?? => use the discrouse section of the kata you're working on to ask for help.
umm.idk where im at and what is going on and what does KATA mean.someone help???
I hope that this is the correct place to ask. If not, I am sorry for the hassle. On the 8 Kyu kata "Sum of positive," you are to get an array of numbers and return the sum of all of the positive ones. I tried this:
function positiveSum(arr) { return arr.filter(e => e > 0).reduce((a, b) => a + b); }
It worked using node in VS Code, but in Codewars, I received a TypeError.
Could someone please tell me what I have done wrong?
Don't ask kata-related questions here, go to the kata's discourse and ask their plss next time ~~~~
And read this to clarify your doubts ~~
I am sure that link answers my question...somewhere?
Nevertheless, I appreciate the reply. Sorry about posting in the wrong area.
Hi, I have this code, and I have a problem in the output
it should print string or number intersection between the two sequences.
but in my code it skips [hi], and i don't know why and only printing:
How can i add my own class(Java) to the Kata?
I'm currently trying to solf the TVRemote(wrap). I already solved it in python but i've been trying to solve it in JS. When I call the main function with the exact same test words that fail, it logs the correct answer but the test says it is logging a different answer. I'm still very new to JS and can't figure out what else I can do since all of my logs come back correct. Any help is appreciated. My code is below. I called the first function with the first test that fails so you can see difference in what is logged.
Hello internet friends,
Any help with the following Python problem would be greatly apreciated. In my own IDE this seems to return the correct result but fails on the test. Thank you.
This is the problem:
Digital root is the recursive sum of all the digits in a number.
Given n, take the sum of the digits of n. If that value has more than one digit, continue reducing in this way until a single-digit number is produced. The input will be a non-negative integer.
Examples 16 --> 1 + 6 = 7 942 --> 9 + 4 + 2 = 15 --> 1 + 5 = 6 132189 --> 1 + 3 + 2 + 1 + 8 + 9 = 24 --> 2 + 4 = 6 493193 --> 4 + 9 + 3 + 1 + 9 + 3 = 29 --> 2 + 9 = 11 --> 1 + 1 = 2
and here is my soloution :
def digital_root(n):
Please use that kata's Discourse: https://www.codewars.com/kata/541c8630095125aba6000c00/discuss/python and mark your post as having spoiler content when it has code like this. Here it can't be marked and it is offtopic.
Can somebody help me to solve this problem in Python or give a little hint, PLEASE! I have an idea how to do it but just not working... Thank you!
In telecommunications we use information coding to detect and prevent errors while sending data.
A parity bit is a bit added to a string of binary code that indicates whether the number of 1-bits in the string is even or odd. Parity bits are used as the simplest form of error detecting code, and can detect a 1 bit error.
In this case we are using even parity: the parity bit is set to 0 if the number of 1-bits is even, and is set to 1 if odd.
We are using them for the transfer of ASCII characters in binary (7-bit strings): the parity is added to the end of the 7-bit string, forming the 8th bit.
You are to test for 1-bit errors and return a new string consisting of all of the correct ASCII characters in 7 bit format (removing the parity bit), or "error" in place of ASCII characters in which errors were detected.
Examples
Correct 7 bit string with an even parity bit as the 8th bit:
"01011001" <-- The "1" on the right is the parity bit.
In this example, there are three 1-bits. Three is an odd number, and the parity bit is set to 1. No errors are detected, so return "0101100" (7 bits).
Example of a string of ASCII characters:
"01011001 01101110 01100000 01010110 10001111 01100011"
This should return:
"0101100 error 0110000 0101011 error 0110001"
This reads like "do my homework for me". You are asking for a lot while having only written a single sentence. You might very well have a legitimate question, but you can't phrase it this way. What you might do instead is to ask about whatever you need to know to continue solving it yourself. Whatever you do ask, you need to be putting more effort into it than the effort required to answer you. You're also asking in the wrong place. This would go to the Hamming kata (and without pasting the instructions because they're already there) - except this text does not match that kata so you're probably on the wrong site altogether.
I am sorry if I phrased it too vaguely and demanding, it's my first day on this website, so I dont know the rules here yet. I was just wondering if anyone has done this question before. I was thinking to solve it this way: store the input in a list, split the integers, but then I got stuck on how to get if there is an even or odd num of 1s. I did not mean to put it 'Do my homework for me' way.
@Blinky_32 :
This is an elementary problem so one need to know where you're stuck in this(what is the problem in just counting the numbers of 1 in the splitted chunks?) and the programming language in which you're attempting this
Oh, my bad, did not think about solving it that way. Thanks a lot and sorry for being annoying!
...don't worry too much about it. It's not much of a problem when one person does it. There are however a whole lot of persons on the internet and this cannot be how we communicate.
No, of course you did not mean it the way I describe it. The problem arises when someone reads it and has to figure out what to do with it, that's when it gets that effect.
It's not a moral judgement. It's unworkable, that's all.
That's much better. What you're saying then, is that you have some list containing 1s and possibly other things. You could make a new function which accepts such a list, and returns that count. It would be a new problem to solve which would help you with your first problem. Whenever you find a subtask like this - making a function for it is a great idea.
def digital_root(n):
This was my solution to the digital root problem, this is not the most efficient solution. Can anyone post more efficient solutions to this problem?
You're not supposed to paste solutions here.
def create_phone_number(n):
This was a solution to the phone number problem, but I believe there are so many more efficient solutions, help me improvise this solution.
You're not supposed to paste solutions here.
Hello , Please some one help me to solve this problem :
Les équipes d'acrobates font partie de la culture marocaine, elles jouaient dans les marchés traditionnels pour distraire les gens. Une des scènes les plus incroyables est quand ils se mettent debout les uns au dessus des autres pour former une sorte de pyramide.
Une pyramide de hauteur L est formée de la manière suivante : Une personne au sommet se tient debout sur les épaules d'une autre personne, qui elle tient debout sur les épaules de deux autres personnes, puis 3 et ainsi de suite.
On souhaite savoir quel est le nombre d'acrobates qu'il faut pour former une pyramide de hauteur L.
Input : 2 6 3
Output: 16 4
On topic:
Can anyone help me with the code of rotateArray(data,n) some of test cases seems to fail. Here is my code in Java:
Thank you
Ask in that kata Discourse, here it is offtopic and your post can't be marked as having spoiler content.
can anyone did the persistence program
int findOdd(const std::vector<int>& numbers) {
}
When I test this code in Qt with sample arrays it returns the correct value, but when I execute it here it doesn't. Any ideas why.
Off-topic??? Use that kata's discourse section to post such questions.
I am newbie in Python. can someone help me with the correct code of this?
"Find films whose actor_3_name is Omar Sy and actor_1_name is the person from Armageddon."
The dataset is found here: https://www.kaggle.com/carolzhangdc/imdb-5000-movie-dataset
#my code:
import pandas as pd data = pd.read_csv("movie_metadata.csv")
data[data.movie_title.str.contains('Armageddon')] & data[data.actor_3_name.str.contains ('Omar Sy')]
...but I got an error.
Use the
and
keyword for logical AND in Python (&
is a bitwise operator, not want you want here).Please help me !!
#include <stdbool.h> #include <stdio.h> #include <stdlib.h>
bool xo (const char* str) {
return count;
return countY;
if (count == countY){ return true; } else {return false;} }
I dont know if it's too late and you've already solved it, but chars in c are marked by single quotation marks: ''. Having: "" means you're trying to compare strings, which you must use strcmp for. str[j] is a char so your comparison should be with a char.
Hi, guys! Is problem-solving improving your brain or thinking? What do you think?
Hello everyone. I am new to all this. Trying to learn JS. and i am stuck with a task: I need to find return an array of numbers [1, 2, 3, ..., n]. So my function fillArray(5) suppose to return [1, 2, 3, 4, 5]. Can someone help me please
how to view my solutions?
Go to https://www.codewars.com/users/andry5bb/completed_solutions
Hi! create function weekdays(date1 in date, date2 in date) return integer language plpgsql as $$ begin .... Why ERROR? function weekdays(date, date) does not exist ! Help me please!
Valid Braces: I passed the tests but not the full test suite because of this: Failed asserting that false matches expected true. What the heck does that mean? I know my solution works but maybe I didn't provide something else that I'm not aware was needed. Please advise. I'm new here. Thanks.
Hello! I have posted 2 solutions by mistake. Now I can't find a way to remove one of them. Any help? Thank You!
As for time being, solutions cannot be removed. Now you have two :)
You cannot remove solutions as of now, perhaps this feature will be implemented in the future as a feature request of doing so has been made here
Hello! I solved the 'Sums of Parts' question, but I cannot find my solution when filtering by 'My Solutions.' When I go to the 'Solutions' section of my profile, I see that solution, but unlike my other solutions, there is no 'Discuss' option to the right of the Refactor option. Additionally, when I go to the 'Stats' section of my profile it says that I only have 10 Total Completed Kata while in my solutions it says that I have 11. I do not understand why my last solution (Sums of Parts) has been accepted in some parts of the website and not in others. I would appreciate any help, thank you!
It's a known issue which reappears from time to time: https://github.com/codewars/codewars.com/labels/issue%2Fsolution-not-shown
It's noted and waiting for its turn to be fixed.
Hi, I have an issue with "Sum of Digits / Digital Root" question, I believe my code is correct, but it won't let me through (says "None should equal 6"), my prints are showing I'm reaching exactly that, would appriciate your input :) def digital_root(n): str_num_arr = split_num(str(n)) print(str_num_arr) sum = 0 for num in str_num_arr: sum = sum + int(num) print(f"sum is now {sum}") if len(str(sum)) == 1: print(f"len is now 1 for {sum}") return sum else: print(f"sum len is different than 1, sum is {sum}") digital_root(sum)
def split_num(num): return [digit for digit in num]
Convert string to camel case
def to_camel_case(str)
arr = str.gsub(/[_-]/," ").split(" ") final =[] arr.each_with_index do |char,i| if i==0
final << char else final << char.capitalize! end end return final.join("") end p to_camel_case("the-stealth-warrior") p to_camel_case("The_stealth_warrior") Hi , in repl and vs code , my code produce the result but still fail in attempt at code wars , is it bug or something ,any suggestion from senior , i just started at codewars.Thanks.
Offtopic...?! Use kata's discourse section to ask for help. But read this before posting.
Hey I use the ClassicModels database. ClassicModels is a fictitious company I want to make basket of goods analysis: A common retail analytics task is to analyze each basket or order to learn what products are often purchased together. Report the names of products that appear in the same order ten or more times. I have no idea for sql qeury. Someone can help me?
How to join a clan?:(
as i know, u can join after 6kyu, but not sure
Go to "Account Settings" and write the name of the clan into the "Clan" field.
How to create a clan???
Go to "Account Settings" and write the name of your new clan into the "Clan" field.
[Honest Question here]
Why are all the top kata solutions so 'hackery'? Like good job for getting it in one line, but who would ever want to read or debugg THAT code??
Is hackery code a lower kyu thing? Is it a codewars thing? Or, and I really hope this isn't true, but is it maybe an industry-wide phenomenon?
I'm a n00b, so if the above opinion is seriously wrong for some reason, by all means, please correct me. It's just that so far, every single resource I've used to study has hammered on the importance of readability, following the style guides, using proper, easy-to-understand names for things, etc.
And as a learner especially, it'd be great if I could wrap my head around the top answers without having the decrypt the freaking variable names first.
Depends on your knowledge and habits. In some time (weeks? months?) when you'll be familiar enough with your language, you'll get them and most of them (not all) won't look like "hackery" things anymore. Then you'll just go: "yeah, good..".
A code that is considered best practices (if that ever actually can mean anything...) by beginners will generally be considered crap by an experienced users and vice versa. And you'll get all the intermediates too.
Thank you for replying! I will stick to the books' guidelines for now then for my own sake (don't break the rules until you've mastered them and all that), but would you mind explaining a bit more why an experienced programmer might like a different style more?
It could help me understand the solutions better if I knew where the experts are coming from.
Cheers
Mostly, more chars is more reading, more to decipher, ... And actually more to maintain too.
So when you're comfortable enough with the language, so that you almost read (simple) codes like you'd read a book, you don't wanna see tons of variable declarations, morover if they are 10 chars or more long each time. That doesn't ofc mean you use only single chars identifiers, but there is an underlying idea about something like... "if you use this variable at only one or two contiguous places, there is no need to call it
indexInTheStringIWannaIterateOn
" -> it'd just be annoying and distracting.(It's pretty caricatural, ofc... Like, "less chars" used has a mantra will lead you to garbage code too. Anyway, at some point there are other matters at stake, that are far more important than the compacity of the code or the number of chars. Like the structure of your code, the decomposition into how many functions, articulated together this or that way, ...)
Anyway. No truth in there. Just ideas and a lot of personal tastes.
Ok, wow, thank you once again for your comprehensive reply! Your reply really gave me some insight from a broader perspective.
I'll make sure to keep it in mind and try to aim for such a level of fluency myself :)
One of the mistakes Codewars made in the beginning was thinking that you could divide code up into "Best Practices" and "Clever" and the internet would be able to agree on what those meant. The internet doesn't agree on anything, especially code.
If it were to be redone (and this hopefully will happen one day in the near future), a rubric would be given and users could rate on things like Readability, Edge Case Handling, Reusability, Efficiency, Coding Conventions, etc. All of these aspects are what would be considered maintainable/best practice - but everyone weights them differentely.
What you find readable may not be what someone else finds readable. You might see functional gibbersh in someone else's solution while they may see object-oriented madness in yours. You may think something is better because it is more easily extendable later while someone else may think you should always keep code concise and refined only to exactly what it needs to be for right now, and think anything more is pre-mature optimization.
Different companies, different industries, different technology communities, they all tend to have different philosophies. Ruby thinks more ways to do something is expressive and therefore better, Python considers that completely against their values.
So don't take any up-voted solution as the end-all be all, you will need to figure out what makes the most sense for you, your style, and the people that you will be working with.
Noted! Thanks for replying as well, and I would definitely be in favor of more rating categories.
I actually found myself 'looking' for them intuitively when I recently joined the site.
Another thing I noticed that you also mention is the difference between languages and the fact that just because someone is solving a kata in Python, that doesn't mean they know or care about Python conventions. Especially in the earlier kyus I assume, since they might be used to their other languages' conventions more.
Take that together with how programmers at different levels have different priorities and the fact that a 3rd kyu in Java might have decided to take up a new language and solve some 7th kyu katas first, and you have a beautiful mess of all kinds of solutions.
Anyway, I'll just keep all this in mind and go at it step by step.
Can anyone help me understand why I'm still seeing quotation marks around the entire sentence? If I remove the quotations from the last line it results in a syntax error. Thanks in advance!
#Defining "quotable" as a function. def quotable(name, quote): return '{} said: "{}"'.format(name, quote)
quotable('Michael', 'Practice makes perfect')
Hi Michael, Your code does not output quotes around the entire sentence.
For example, if you put:
print(quotable('Michael', 'Practice makes perfect'))
the output is:
Michael said: "Practice makes perfect"
in line 3 of your code, you need the single quotes to let Python know that you are returning a string. The double quotes are contained within the single quotes and treated as text by the interpreter. Strings will always be surrounded by quotes in Python (single and double quotes can be used interchangeably throughout your code but aesthetically, you may prefer one or the other in a string).
Hi Micheal, Your code has no output. You never call the
print
function.Hi!Two of my kata's have this problem "Execution Timed Out".I'm starting in programming and I want to get better on it. Guys , does anyone have any tip or place that can I learn about this? Pleeeeeeeeeeeeease somebody help me!! I start looking solutions , and one of my mistakes is using two "for" interation in very very big number's .So, any tip is welcome!
I need faster algorithm. Problem - to leave only the last occurrences of each element in the sequence; the remaining elements must be removed from the sequence. Thank you. Given: 1 2 3 3 2 1 4 1 2 0 Answer:3 4 1 2 0
why are you posting here??? nobody even knows what you're talking about. => post in the discourse section of the related kata.
i am very new to Codewars. Hope this question is appropriate for the forum. I ran the Attempt test cases for The Hunger Games – Foxes and Chickens using Java.
For Random Test 1 Here is my result before/after (farm/farm2)
followed by the Before/After from test case. //farm = C....C.C[..CCC..C.....C..CCCC.CC.CC....C.CCF..F.CCC..CCC.C.F...CC.C.....F..C.CCF..C....C..C..CCC.] //farm2= ........[..................................F..F............F............F......F.................] //Before:C....C.C[..CCC..C.....C..CCCC.CC.CC....C.CCF..F.CCC..CCC.C.F...CC.C.....F..C.CCF..C....C..C..CCC.] //After: C....C.C[..................................F..F............F............F......F.................] the After includes the "C"'s outside the brackets which to my understanding should be "."'s correct?
For onlyChickens test case here is my before/after log followed by the test case results. farm =.C..[C.]..C....[C]..[C..] farm2=....[C.].......[C]..[C..] expected:<.[C..[C.]..C]....[C]..[C..]> but was:<.[...[C.]...]....[C]..[C..]> my result seems ok and the test case result has unmatched [ ]'s
appreciate the help to clarify. Thanks
Please, post this in that kata's Discourse, not here.
ok thanks
Hello when I leave a problem I haven't finished is it gone forever or will I eventually recieve it again?
Actually based on a post below I didn't realize I was posting off topic.
I have problems with the traning in python. Several times it says to me I m wrong when my code works at home and log show that I obtain the right results. For example for the "Who likes it" : Test Results: Basic tests Log 'no one likes this' None should equal 'no one likes this' Log 'Peter likes this' None should equal 'Peter likes this' Log 'Jacob and Alex like this' None should equal 'Jacob and Alex like this' Log 'Max, John and Mark like this' None should equal 'Max, John and Mark like this' Log 'Alex, Jacob and 2 others like this' None should equal 'Alex, Jacob and 2 others like this' Random tests Testing for Sylvie, Daley Wong, Quincy Rosenkreutz, Sylia Stingray, Nene Romanova, Brian J. Mason, Linna Yamazaki, Largo Log 'Sylvie, Daley Wong and 6 others like this' It should work for random inputs too: None should equal 'Sylvie, Daley Wong and 6 others like this'
etc...
Someone can explain to me where i do a mistake?
thank in advance
Your function should return the result instead of printing it.
Thanks Chrono79 I misread the details and i was printing the result instead of creating the string. problem solved
Why not post it on kata's discourse? This is completely off-topic...
sorry but i am completly new here I did not see the kata's discourse part before you talk about it. For me the "soluce" part of the forum looked to be the right place to ask my question Btw perhaps a little tutorial how to answer to train exercices and description of other features could be good A wiki exists but it s not a tutorial.
How to press Esc to normal mode in codewars ?
The speed of the solution should be added, because some clever solutions may not be quick, they are just using very obscure programming concepts - efficiency is very important with code.
There should be another solution upvote category - readability. Some solutions are very hard to read. When writing code it is important to make sure that humans can easily understand what you are writing.
Hello, anyone can help me solve this task
Google has offices in several locations. Currently we have an interviewee that is in the Google office on locationA and he has passed his first interview, so now for the second interview he needs to get to locationB. Find the fastest route to get there and return the number of steps. Input Method signature: int fastestRoute(int[] from, int[] to, int locationA, int locationB) • from - an array of integers. • to - an array of integers . The i-th pair (from[i], to[i]) means that there is a path from location from[i] to location to[i]. Constraints: • from and to will have between 0 and 50 integers, inclusive. • each integer in from and to will be between 0 and 50, inclusive. • Expected execution time is below 10 seconds. Output An integer giving the number to steps to get from location A to location B. If it is not possible return -1. Examples • fastestRoute([0, 0, 1], [1, 2, 3], 2, 3) returns 3 since to get from location 2 to location 3 the path is 2 -> 0 -> 1 -> 3, which is 3 steps. • fastestRoute([0, 1], [2, 3], 0, 1) returns -1 since it is there is no path from location 0 to location 1.
At least attempt it...
If you fail after trying post it in the discourse section of said kata.
Hello, I am trying to solve the Kata is prime
I keep getting this error "Your function shouldn't just consider any huge number as prime"
My solution is:
function is_prime(int $n): bool { $num=$n/6; $result = $n > 1 && (($n > 1 && $n <= 3) || ($num < round($num) ? (6 * (round($num)) - 1 == $n ? true : false) : (6 * (round($num)) + 1 == $n ? true : false))); return $result; }
Please tell me what am i doing wrong
Don't write here, use that kata Discussion, and mark your post as having spoiler content.
//
Expected: "a\n b\nc" But Was: "a \n b \nc " So, i tried to delete this space by all ways i know, and nothing! Rest of tests are completed. How can i delete this spaces before i return a string?
Write in whatever kata that is, own discourse section.
Hi, a question regarding the test cases: After you pass the sample tests, you see the tests results and the failed ones appear like: '4' should return '3', but I cannot see what the test case is, and when I click into the discussion of the kata I see comments like "I cannot pass the number 14 in test cases". And I'm like... how do they see that? Is it possible to know?
Ask in that kata, how is your question related to the topic "Solutions grouping"?
It's not kata specific, but sure, I'll ask everytime I see it, sorry
General answer, print the input to see what it is.
It's language-specific. But the general answer is to log the input. So for example, in python, you'd use
print(argname)
. Some katas log all inputs by default, but most don't.Hard Sudoku Solver:
Run into issue, where the kata says the offered sudoku puzzle is NOT solvable ... my code solves it ... and thus I can NOT pass?!
I verified the puzzle and my solutions and can NOT find why it is rejected ... it only happens in 1 - 3 cases (RANDOM) per ATTEMPT.
Any clues, suggestions?
e.g:
PUZZLE: [[3, 4, 7, 9, 0, 0, 0, 8, 0], [0, 1, 0, 8, 0, 0, 0, 5, 0], [0, 0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 5, 0, 0, 0, 0, 8], [0, 0, 0, 4, 0, 8, 0, 0, 0], [6, 0, 0, 0, 0, 3, 0, 0, 0], [0, 7, 0, 0, 0, 0, 0, 0, 0], [0, 8, 0, 0, 0, 5, 0, 3, 0], [0, 5, 0, 0, 0, 4, 2, 7, 9]] Solution: [[3, 4, 7, 9, 5, 1, 6, 8, 2], [2, 1, 9, 8, 3, 6, 7, 5, 4], [8, 6, 5, 2, 4, 7, 9, 1, 3], [7, 3, 4, 5, 6, 2, 1, 9, 8], [5, 9, 1, 4, 7, 8, 3, 2, 6], [6, 2, 8, 1, 9, 3, 5, 4, 7], [4, 7, 2, 3, 1, 9, 8, 6, 5], [9, 8, 6, 7, 2, 5, 4, 3, 1], [1, 5, 3, 6, 8, 4, 2, 7, 9]]
Yes, don't post here, it's unrelated, use that kata discussion. And if it is the 2kyu one (there are 2 katas with the same name):
So I guess you've found one solution but there is more than one.
Hi, I'm new here and do not know where do I write the solution for the kata. I see description of the task, but do not see any window where to enter my code. Anyone to help?
there should be a big blue button on the top right thats is labeled "TRAIN" click on it :)
Great!, I'll try. Thank you so much! I'm eager to start, but just do not know how :)
Hello, I am trying to solve the Kata Sum String as Numbers. The problem I get is that the code I wrote as a solution works in Visual Studio but for some reason on the platform I get an error on the same code
Can anyone please advise what could be the reason.Thanks!
The first step to help you with your problem is posting in that kata discourse, not here. There you can post your code using markdown formatting and marking your post as having spoiler content.
I am trying to solve this Kata: Matrices II: Serious mathematics
I tried to solve it in my IDE (intelliJ) and I tried to write some test cases in the main method and the code could pass all of them. So, I have thought the code is working, but when I have uploaded the code and submitted it it could not pass the tests. I am still a beginner in terms of programming. I hope someone can help me out and advices and tips are really appreciated since I am willing to learn.
public class Matrix {
}
Hi guys
Im trying to do the phone Directory kata in Swift. The problem is how should i use regex?
the range method of strings works good in examples but i have syntax problems too. im stuck
Please, write in that kata Discourse, here this off topic.
Is there any way to group some Kata's in list and suggest them to my friend?
If I select a task I have already solved how can I see my solution?
Go to the solutions, under "Show Me", click "My Solutions".
Thank you very much!
unable to post solution . I have created my account and also received challenges but unable to identify where to post the solutions. anyone please help me.
kata page -> "train" button -> code in the upper left window -> attempt button (bottom left). And if you pass all the tests -> "submit" button (the attempt one, but it becomes green if success)
any tips to make site more mobile friendly
Is there anyone who want to organize hackaton? If yes reply this comment. We will choose set of problems and solve them together via hangouts and discussion
Is there a way to delete one of your own solutions?
What does the "link" button do? When i click it I see my solution but then what can I do?
No.
It gives you the link for that particular solution when you want to share the link, let's say, to report an issue with the tests.
I passed in 3 of the tests here but failed in one, wonder how to fix it function isValidWalk(walk) { //insert brilliant code here var directions = ['n', 's', 'e', 'w']; var home = 0; var isValidWalk = 10; var walk = [0,0,0,0]; for ( var i = 0; i < walk.length; i++){ if (walk.length === 10 && walk.length >= isValidWalk){ return true; } else if (walk.length < 10 && walk.length < isValidWalk){ return false; } else if (walk.length === 0 || walk.length > 10 || walk.length < 0){ return false; }
} return true;
}
Not sure how (relatively new on this site), but it seams a my solution was somehow cloned, which was then grouped together in https://www.codewars.com/kata/reviews/5bcea1400b96aed875000523/groups/5c831842d611800001535265. Seems not fare, since it appears that both variations are identical (which is practically impossible if solved fairly!)
How about to (atleast) show who did it first?
So far on my experience with codewars in the last 6 months and completing close to 200 challenges of varying difficulty, I've observed several instances where solutions are not grouped together when they virtually identical in structuring and functionality. To visually represent what I'm referring to, I'll use two fictional examples for a simple problem: count number of even ints in array (using Python).
In my opinion, examples 1 and 2 should definitely be grouped together. However, in most examples that I've seen, they would potentially be treated as entirely separate from one another. There is no functional difference between "++" and "+=", and changing the names of variables does not change how the solution works. Usually, the solution grouping system seems to be good at grouping together solutions with different spacing, or different variable names within a method/function, but argument variable changes and functionally identical ways to reach the same result are often treated as different. I believe I've also seen whitespace or even comments make my own solutions not group with other virtually identical ones.
I would propose at the least improving the system to treat any variable (including argument variable changes) as irrelevant when it comes to grouping, and categorizing similar operations or methods that function identically as being the same. The second part would take significantly more effort to implement, but I believe it would be possible by measuring the execution time of the code, and grouping them if they are identical (creating some flexibility to account for server delays). The execution time would not group them alone, but would contribute to some form of "similarity score". If that similarity score was high enough, they would be grouped together.
Something similar to my proposal may already be in place, but it just seems like virtually identical solutions are rather frequently not grouped together. For myself at least, a lot of the enjoyment from lower level katas come from creating "best practices" or "clever" solutions, so it can be disappointing when a situation similar to the demonstrated one occurs.
Not sure if these topics are actually monitored actively. If it doesn't receive much attention, I'll post this as an issue/suggestion over on the codewars github. IMO it should be considered an issue rather than a suggestion, as the current solution grouping process frequently does not work as intended.
EDIT: Noticed a typo on the method/function name, it should be "countEvens" on the first example, not "countEvents". I seem to be unable to edit the post itself after creating a reply. Just wanted to mention it here to avoid confusion, that was not intended to be part of the example. Also for the second example, "for x in intArray" should be "for x in ints".
i have to find an integer which appears an odd number of times in an array. what am i doing wrong.help!
public class FindOdd { public static int findIt(int[] a) { int odd,b; for(int i=0;i<a.length;i++) { odd=1; b=a[i]; for(int j=i+1;j<a.length;j++) { if(b==a[j]) { odd++; } } if(odd%2!=0) break; else continue; } return b; } }
Don't post code here, use that kata discourse and mark your post as having spoiler content.
Also worth noting that when you post this code on the respective kata, use the tilde key (`) three times to start a code block, and another three times at the end. You can optionally include the language used after the first set of tildes to have highlighting enabled. Using code blocks makes it much more readable.
I have passed 28 tests but failed 4 tests for - "Playing with digits" kata. I don't find the correct solution anywhere on the site. Wanted to check if the correct solution is available after attempting a kata or no?
Don't post code here, use that kata discourse and mark your post as having spoiler content.
i have passed 26 tests but 6 tests are failing plz tell me what am i doing wrong
this is my code of "Split an array" kata...
function split(arr, prop) {
//ceate an array
let returnArray = [[],[]];
//iterate through all the object in the array
for(let i = 0; i < arr.length; i ++){ //compare the prop
}
Write in that kata's discussion, not here. And mark your post as having spoiler content there (can't be done here).
I can't find kata's discussion... (And not only I)
In kata "Are they the "same"?" I dond't understand:
[2, 2, 3] [4, 9, 9]
True should equal False
why False? 4^0.5=2, 9^0.5=3
You can use navigate to kata discourse from description page, solutions page (even if you haven't solved the kata), and from the trainer (button next to
unlock solutions
button).Concerning your question: the arrays are not the same:
Hi, My name is Michele and I want to improve my coding skills. I do feel like an idiot because I cannot find the right solution for the challenge, Unwanted dollars, and I have been busy with it for a while now. My sample tests passed 10 and failed 0 but yet it is not approved. Woud you please direct me?
Thanks in advance
Write in that kata's discussion, not here.
I have tried, and did not succeed. How should I do that?
From the kata's description page, there should be 3 tabs: Details Solutions Discourse <- This one From the trainer: Discourse <- The third button below Sample Tests
And for that kata: https://www.codewars.com/kata/unwanted-dollars/discuss
My programme work on sample test but in the Attemp my programme work on 93 cases and failed in 28 cases but I wanted to know what are those cases. Is there any access to see what are those cases where my programme is not working? I wanted to see those arguments.
Write in the kata discussion next time, this has nothing to do with this:
Use
console.log(varName)
where varName is the value you want to check.Hello guys! I am working on C. I have a problem. How can I sort array's elements with even indexes in increasing order and the elements with odd indexes in decreasing order. For example: If the array is { 10 , 5, 2, 7, 3,9,11 , 6, 8, 13} then after sorting it should be {2, 13,3,9, 8, 7,10,6,11,5} . The result of printing should be as: 13 9 7 6 5 2 3 8 10 11
Try to use 2 arrays, one for the even indexes and other with odd indexes, then, join both in a final index using a for, do you want what i mean?
Don't discuss katas here, the comments can't be marked as having spoilers. There is a discussion section for each kata.
hey guys! i'm a relatively new Python programmer (and just a new programmer in general) and I'm new to codewars. I was trying to solve the Centuries kata and used this as my answer but it keeps saying that it won't work and that "n" was referenced before it was defined. I don't see why this code wouldn't work. Can anyone help me out? Thanks! -tomahawkgirl
Edit: i used the correct indentations but they won't show up in this comment
def century(year): year = str(year) if len(year) == 4: if year[2:4] == str(0) + str(0): n = int(year[0:2]) else: n = int(year[0:2]) + 1 if len(year) == 3: if year[1:3] == str(0) + str(0): n = int(year[0]) else: n = int(year[0]) + 1 return str(n)
Please use that kata discussion (here your post can't be marked as having spoiler content). As for indentation, check this
Ok thank you!
I think I know the problem with your program. You can't have 2 if statements one after another.
Taking an example from yours;
if len(year) == 4: if year[2:4] == str(0) + str(0): <----- Potential Problem.
And you can't have if statements with else statements. It's like true or false.
Please, don't discuss code here.
cat + one potatoes = cat fat
I have potatoes and one cat
Hi, I am trying to complete https://www.codewars.com/kata/counting-sheep-dot-dot-dot/train/csharp
I keep getting a syntax error. Any help would be great as I am pretty new to c#.
My solution:
using System;
public static class Kata { public static int CountSheeps(bool[] sheeps) { //TODO int sheepCount = 0;
} }
Don't post here, use that kata discussion, here the posts can't be marked as having spoiler content.
The equivalent solutions in upper case and lower case in SQL are not grouped together but should be.
I'm trying to do https://www.codewars.com/kata/string-repeat/train/java
I'm having some problems that the string just keeps repeating and never stops. I added the "i" into the print to see what's going on and it keeps resetting to 0 when it reaches the repeat number
public class Solution { public static String repeatStr(final int repeat, final String string) { int i = 0; while (i<repeat) { System.out.print(string + " " + i); i++; }
} }
4 a output is: a 0a 1a 2a 3a 0a 1a 2a 3a 0a 1a 2a 3a 0a 1a 2a 3a 0a 1a 2a 3
Please, don't paste code here, it can't be marked as having spoiler content, use the kata discussion for that.
it's safe to paste code on a discussion of the actual kata, but not in a general forum?
Yes, if you mark your post as having spoiler content it will only be visible to people that has already solved the kata. Also, read what this thread is about, it has nothing to do with a problem with your code for a specific kata.
I see now. Apologies :)
everything is confusing in this site. just signed up I could not change a picture profile!! codes not clear how to contribute is not clear everything is flying here
Connect your GH profile; change the pic on the GH profile to update it.
Im new to code wars. Ive recently successfully attempted some kata challenges. For one i submitted it and realised i didnt clean up my code and i tried to refactor the solution but it made a copy. I now have three solutions to the same kata. How do i remove a solution? Thanks in advance
I got this Algo during a tech screening can anyone eleborate on how to solve!
//input let array = [ { skill: 'css', user: 'Bill' }, { skill: 'javascript', user: 'Chad' }, { skill: 'javascript', user: 'Bill' }, { skill: 'css', user: 'Sue' }, { skill: 'javascript', user: 'Sue' }, { skill: 'html', user: 'Sue' } ];
Expected Output
var newArray = [ { skill: 'css', users: ['Bill', 'Sue'], count: 2 }, { skill: 'javascript', users: ['Chad', 'Bill', 'Sue'], count: 3 }, { skill: 'html', users: ['Sue'], count: 1 } ]
Hi!
I was trying to solve a kata but not able to understand how the following result is coming in?
https://www.codewars.com/kata/56a5d994ac971f1ac500003e/train/javascript
testing(longestConsec(["wlwsasphmxx","owiaxujylentrklctozmymu","wpgozvxxiu"], 2), "wlwsasphmxxowiaxujylentrklctozmymu")
As far as I understand the kata, it should result "owiaxujylentrklctozmymuwpgozvxxiu"
Can anyone please explain? Thanks.
Ask in the discourse section of that kata, here is not the place. Also read the similar questions and answers posted there, it has already been explained several times.
I was grouped with code that is worse than mine. Not that it broke my heart, but it is sad.
Here: https://www.codewars.com/kata/5715eaedb436cf5606000381/solutions/java/
Write a program that receives a number and then a comma-separated circular list (without repeats) and responds as quickly as possible to whether a number belongs to the list.
Example:
Input: 5 2,3,4,0,1 Output: no
Input: 4 2,3,4,0,1 Output: yes
Input: 3 4,6,11, -1,1,2,3 Output: yes
Have you read what this topic is about up there?
Hello everyone, was wondering about magic rectangles specifically constructing their elements; if possible would love some elaboration on this topic or some helpful resources
i can't find the Unlock Solution button?
Good afternoon, I am a new guy here. Tryin to improve my sql progress, so my first kata is
"to create a SELECT statement, this SELECT statement will use an IN to check whether a department has had a sale with a price over 98.00 dollars"
...
There is a Discourse section for each kata, this should be posted there, not here.
You are going to be given an array of integers. Your job is to take that array and find an index N where the sum of the integers to the left of N is equal to the sum of the integers to the right of N. If there is no index that would make this happen, return -1
Hey guys, i need help with Game of Go kata, have the same task in my js course, i have spent few days and still my progress is miserable, maybe somebody can get any similar solutions?
Is it frowned upon to refactor your code with other people's ideas?
Nope. Also it's preferably done by forking other's solution as a kumite.
Hello, My name is Danyshman. And i am superman!
Joke or serious, I know a fella from the UK who's mother gave him Supermans's birthname. lol poor fella
i participated in a kata. And when i finish the i got this error
"Process exited prematurely with a SIGFPE signal"
What does it mean
http://lmgtfy.com/?q=SIGFPE
Please, read what this topic should be about:
If you want to discuss some kata in particular, there is a Discourse section for each one.
I trying the duplicate_encode kata for Python.
Despite all test are ok, when trying the final attemp it gives me an error in the last test, it returns:
My code is:
I do not have feedback of the input that gives error. Can someone help me please?
Thanks.
The problem is that you are iterating through the characters of the lowercase version of your original, uncertainly cased string, and then checking how many times each of these lowercase characters appear on that original string. It's easy to see where this goes wrong.
Adding this to the beginning of your function should fix it:
ERROR for problem https://www.codewars.com/kata/coordinates-validator/train/python
it passes sample tests but fails at attempt .gives the following Error some please help me finish the problem
Test Results: Example Test Cases should return true for valid coordinates (7 of 7 Assertions) STDERR: Traceback: in in is_valid_coordinates ValueError: could not convert string to float: '- 23.4234'
|||| MY CODE |||||||
code:
def is_valid_coordinates(coordinates):
Hi everyone, What am I doing wrong? Problem: https://www.codewars.com/kata/take-a-number-and-sum-its-digits-raised-to-the-consecutive-powers-and-dot-dot-dot-eureka My code: http://www.wklejto.pl/506442
Hi, I'm doing Shakespearean Tug of War (https://www.codewars.com/kata/shakespearean-tug-of-war) and my program works for 6 fixed tests but the 7th one fails and then some random tests too. The team is correct but the number not. Any hint on what I might be doing wrong?
Hello everyone i just begin improve my js coding skill ,can anyone join me.We can teach each other
Am exactly doing the same...in my intermediate level
would you like to join my team,lets discuss some problem together.And make some difference.
Você recebe uma matriz (que terá um comprimento de pelo menos 3, mas pode ser muito grande) contendo números inteiros. A matriz é inteiramente composta de inteiros estranhos ou inteiramente composta de inteiros pares, exceto por um inteiro inteiro N. Escreva um método que leva a matriz como um argumento e retorna esse "outlier" N, nao conseguir resolver
Hello everyone. I just started this problem.I have no idea where to start. Codeacademy.com did not help.
Hi. We have opposite problems. I have a solution but in the meantime I can't find the problem again. You have the problem but not the solution.
Codecademy is super basic, I completed it all in a day without really reading instructions. till I stumpled on this site LOVE THIS SITE. projecteuler is also a nice site but it is limited on how much you can do per day. another site which I get stuck on for hours (not litterally) I can just stay there all day is Khancademy
Hi, I've a solution to a problem and I'm new at this website. Would you please tell how do I submit this solution? Thanks luca
I have a problem with my code. It is my first assignment so maybe I'm doing something wrong with the return value. I really don't know. The program is written in C.
ASSIGNMENT: If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Finish the solution so that it returns the sum of all the multiples of 3 or 5 below the number passed in.
Note: If the number is a multiple of both 3 and 5, only count it once.
CODE:
int solution(int number) { // code here int k; scanf("%d", &k); int a = 0; int b = 0; int c = 0; int d = 0; int i = 0; int j = 0; int sum = 0; if(k % 3 != 0 && k % 5 == 0){ a = k / 3; b = k / 5; for(i=1; i<=a; i++){ c += 3 * i; //printf("c u koracima = %d\n", c); } for(j=0; j<b; j++){ d += 5 * j; //printf("d u koracima = %d\n", d); } sum = c + d; } else if(k % 3 != 0 && k % 5 != 0){ a = k / 3; b = k / 5; for(i=1; i<=a; i++){ c += 3 * i; //printf("c u koracima = %d\n", c); } for(j=0; j<=b; j++){ d += 5 * j; //printf("d u koracima = %d\n", d); } sum = c + d; } else if(k % 3 == 0 && k % 5 == 0){ a = k / 3; b = k / 5; for(i=0; i<a; i++){ c += 3 * i; //printf("c u koracima = %d\n", c); } for(j=0; j<b; j++){ d += 5 * j; //printf("d u koracima = %d\n", d); } sum = c + d; } else{ a = k / 3; b = k / 5; for(i=0; i<a; i++){ c += 3 * i; //printf("c u koracima = %d\n", c); } for(j=1; j<=b; j++){ d += 5 * j; //printf("d u koracima = %d\n", d); } sum = c + d; } //printf("a = %d\n", a); //printf("b = %d\n", b); //printf("c = %d\n", c); //printf("d = %d\n", d); //printf("sum = %d\n", sum); return sum;
}
Would you be so kind and review my code? What am I doing wrong?
Hi, I have a question about finding the length of the longest substring in the given string s that is the same in reverse. As an example, if the input was “I like racecars that go fast”, the substring (racecar) length would be 7. My code is follow and I don't know where is wrong, How do I do this?
def longest_palindrome (s): for i in range(len(s)): for j in range(len(s),i,-1): n = s[i:j] if n == n[::-1]: return len(n)
Hi, I have an array containing a number of values of different types. The task is to move all of the zeros to the end. The problem is that I can't distinquish a zero value '0' from a boolean value 'False' when comparing them in a cycle. So actually this is my question. How do I do this?
I'm guessing you're talking about python? Well, first of all, you should post this under the discourse of that kata, not here :P To make sure it is not False, you can do
if x is not False:
python? if(val==0 and not val==False) return blabla pseudo can be done many ways.. thats not a spoiler is it
kata: https://www.codewars.com/kata/55c6126177c9441a570000cc/train/javascript
condition: When two numbers have the same "weight", let us class them as if they were strings and not numbers: 100 is before 180 because its "weight" (1) is less than the one of 180 (9) and 180 is before 90 since, having the same "weight" (9) it comes before as a string.
Test.assertEquals(orderWeight("2000 10003 1234000 44444444 9999 11 11 22 123"), "11 11 2000 10003 22 123 1234000 44444444 9999")
why do we expect that the order will be 11 11 2000 if 2000 is before 11 in argument and why 10003 is before 22? can't solve this kata cause of the strange instructions
Try not to post whole code solutions here, there is no way of flag them as spoilers and are shown on the Home's Discussion block. Discussion about a particular kata solution belongs on that challenge solutions tab (they're only visible to people that already solved that kata). Thanks.
ok I will take care of it. but i this problem i am not able reverse the the particular word in doing so my whole sentence is reversing. plzz help i am not getting solution
Post in that kata discussion, also without code formatting (check code block in the link) https://github.com/Codewars/codewars.com/wiki/Markdown-Formatting Python code is not readable.
def spin_words(sentence): # Your code goes here word = "" sen = "" for i in sentence: if i != " ": word = word + i if len(word) >= 5: r1 = word[::-1] sen = sen + r1 else: sen = sen + word
def spin_words(sentence): # Your code goes here word = "" sen = "" for i in sentence: if i != " ": word = word + i if len(word) >= 5: r1 = word[::-1] sen = sen + r1 else: sen = sen + word
Hi, I did the Valid Parentheses challenge, where you're supposed to write a function that tells whether a bunch of parentheses are grouped together correctly. () should be true, )( should be false, ()) should be false, etc. I solved the challenge, but I like to look at other peoples' answers to see how I could've done better. I don't understand how the top answer works successfully. Here is the code: function validParentheses(parens){ var indent = 0;
for (var i = 0 ; i < parens.length && indent >= 0; i++) { indent += (parens[i] == '(') ? 1 : -1;
}
return (indent == 0); } When I try to think through it, it seems like the code would return )()( as true, even though it's false. However, when I ran the code it correctly returned it as false. Can someone explain to me how the code works so that the proper result is returned in this case?
Take a look at the loop condition, it exits if indent is less than 0.
I am doing the XO Kata and I dont know why this doesnt return true for the string xoxo I understand why it wont work for capital letters, I havent implemented that yet:
maybe what you want is to compare srt.charAt(i) with 'o' and not 'y'?
Typical.. I put 'y' instead of 'o' as the question specifies haha, thanks anyway
I'm doing the Bingo Card kata. I did use Random class. However, it says "The same number appeared on more than 30 of the 100 cards on the same spot, are the cards random? Expected: False But was: True"
Having each square 15 posibilities and 5 places to be, it doesn't seem weird to get the case of sharing the same spot when you test with 100 different ones.
If I did random the numbers, how can I fix this problem? Thanks!
I did that kata yesterday, and spent a fair amount of time reading up on best ways to randomize stuff. From what I read, math.Random is actually pretty bad at randomizing stuff.
That being said, I did see kata solutions using random which were accepted. How many times did you try submitting your answer? Maybe try again? Otherwise, there's probably something else wrong. If you console log your array a bunch of times in a row, you will probably see some patterns. 1 number out of 15 being in the same spot in a column 30% of the time is wrong; any number being in a column at all only has a 33% chance (and 25%-ish for the middle column).
At the end I just made the Random object global and it worked!
Hello to all CodeWarriors I wrote code for Gap in primes (in Python). It passes all sample tests but unfortunately I can't submit the solution because of server time restrictions for code execution. It works pretty fast on my slow computer and sample tests take about 100ms. Could you help me to find solution? Is it codewarior's bug or I need fixes in my code
Hi,I just learn python for a few days.But,I can't understand this function : def primeInRange(n1, n2): for y in range(n1 + 1, n2): if(isPrime(y)): return False return True when you use isPrime() to find whether there is a prime number between n+1 to n2-1,isPrime() will return True,but why you return False again? Maybe you can change this function and try again.
Your code that's checking for primes is very inefficient, and not nearly fast enough to pass the tests. They're checking for many, many primes.
Hey All,
I am hoping to get some feed back on my code for the Sum of Digits Kata, my code only passes 2 of the tests and fails the other four and I am not sure why.
My code
function digital_root(n) { var all = 0; var m = n.toString(); var t = 0; for(var i = 0; i < m.length; i++){ all = m.charAt(i); t += +all; } return(t); };
Test Results: Test Passed: Value == 7 Expected: 6, instead got: 15 Expected: 2, instead got: 20 Expected: 9, instead got: 108 Expected: 9, instead got: 27 Test Passed: Value == 0
Thanks!
Hi, length is not a function it is a var from the string. Try it with: m.length
for(var i = 0; i < m.length; i++){ //code }
change t += all; to t += parseInt(all);
Not understanding hamsterme. Got all test cases but having issues with random input. Not sure what the question expects. Solution expectation explaination missing large chunk of well... explaination.
Hi,
I'm working on "Its all backwards" and in my console it gives the correct output, but when I validate it in the Codewars console it does not pass the tests and it is giving different answers than I see in my console.
What gives?
me too with "Playing with passphrases"... :(
Hey, welcome to Codewars!
You need to return the final output instead of printing it directly to the console. When you return a value, the value is retained and can be tested for equality with the testcases. All Katas on the website work by returning the final output.
Also, every Kata has an automatic discourse page where you can post Kata specific issues and questions directly to that Kata page instead of the forum page which is for general topics.
Is there a way to view your previously solved Katas? Thanks!!
You can go under Kata/Completed in your profile to see all completed katas. If you want the code, you can open an already completed kata and choose "Past Solutions" in the left side with Instructions and Output. Solutions/Completed on your profile also work.
Thank you very much!
Digital root strangeness. My code is returning an undefined even though the console.log(n) call shows the proper value in the variable. Not sure what the problem is. Thanks for any and all pointers.
// add the digits of the numbers together, return the final sum function digital_root(n) { console.log(n); if (n <= 9) return n; else{ // use recursion! var numString = n.toString(); var stringArr = numString.split(''); var toNums = stringArr.map((e)=> parseInt(e)); var sumNums = toNums.reduce((acc, curr) => acc + curr ); digital_root(sumNums); } }
console.log(digital_root(16));
Please can you post Kata-specific problems on the discourse page for that Kata instead of the forum which is for general topics. Each Kata has an automatic discourse page in which you can mark your comment as a question, which means it's easier for me to help (since it's easier to find). Also, since this is a forum page, I can't mark your comment as a spoiler, meaning people can look at your code and use it themselves, however on the discourse page I can hide your solution.
Your code is returning undefined because that is the default value when nothing is returned. Change
digital_root(sumNums);
toreturn digital_root(sumNums);
. You need to return the final value in order for the value to be retained, all you are doing is calling the function without returning the answer. This means nothing is returned, therefore returning "undefined".Thanks for your answer, AcesOfGlory. Very helpful. I am (obviously) new to Codewars, still learning the interface.
Hi! I'm trying to code a simply javascript reverse/ mirror function and it's my very first practice for Javascript so I'm a little lost.. I'm not sure how to read the sample tests and I'm sure my code is working fine. Can someone help?
const mirror = str => {
var temp = "";
for (var i= str.length - 1; i>= 0; i--){
temp += str.charAt(i);
}
return temp;
};
Sample Test:
const assert = require('chai').assert; const style =
style="display: inline-block; transform: scale(-1, 1)"
; const log = m => console.log(m, ' ',<span ${style}>${m}</span>
);// Tests describe('mirror', () => { it('basic', () => { const expected = { abc: 'cba', arara: 'arara', }; const actual = mirror({ abc: undefined, arara: undefined, });
}); });
Hello, codewarriors!
I've started collection "Learning TypeScript": https://www.codewars.com/collections/learning-typescript
Generally, I'm trying to create katas for this handbook: https://www.typescriptlang.org/docs/handbook/basic-types.html
Need help with testing/writing katas :)
The system can't ATTEMPT!!
Hi i have problem with "Alphabetic Anagrams" Kata (http://www.codewars.com/kata/53e57dada0cb0400ba000688). I passed all tests and made some other cases. I passed them as well. Problem is i can't get through final attempt. I just get error 24. This error dont tell me so much. What am I doing wrong? My code:
class Anagrams { private static BigInteger[] bigFactorials = { new BigInteger("51090942171709440000"), new BigInteger("1124000727777607680000"), new BigInteger("25852016738884976640000"), new BigInteger("620448401733239439360000"), new BigInteger("15511210043330985984000000")};
}
Hi all, i've started with Python recently and I have a problem with "Stop gninnipS My sdroW!" exercise. Description: "Write a function that takes in a string of one or more words, and returns the same string, but with all five or more letter words reversed (Just like the name of this Kata). Strings passed in will consist of only letters and spaces. Spaces will be included only when more than one word is present."
My code looks like that:
...output shows that single word is ok, but still shows an error with multiple words "'Hey' should equal 'Hey wollef sroirraw'". Could you help me with this problem?
Your return is within the for, so it never loops (the function returns as soon as it ends the first iteration) Aside from that, I don't understand why you use n instead of i, if you find say three words with respectively 5, 4 and 6 letters you'll add the first word reversed, then iterate. You then add the second word straight. And finally you add the second word once again (n wasn't incremented) but this time reversed. When do you expect n to differ from i?
PS: I forgot to say, their a discussion nail on each kata that you should use for kata specific questions. And avoid sending directly code as it could spoil people (in a kata's specific discussion you can tag a message as spoiler)
Hey guys my name is Lexi and I am a first year student at UCT. I have been given a project in java and I don't really know how to do it. If there is anyone who is understands java and is willing to help please email me at lexiwellsqw@gmail.com . I will really appreciate it if someone could try to help it would contribute tremendously to my career as a programmer.
Hi all, I am new to javascript and am having trouble with the Split Camelcase kata.
Description:
Split a camelcase string into individual words, the return value must be a single string of words seporated by one whitespace.
The strings are to be split on the capital letters like so:
'StringStringString' => 'String String String'
**I completed this with no problem, but what it doesn't mention in the instructions is that if two or more capital letters are next to each other, you only add a space before the first capital letter. So "TTThisIsAnExample" would become "TTThis Is An Example" and not "T T This Is An Example" ... if that makes sense. So this is the suuper inefficient code I wrote to try to satisfy those tests, but apparently it is an infinite loop and I have no idea why:
function splitter(str){ let array = str.split(''); for (let i=0; i<array.length; i++) { if(array[i] === array[i].toLowerCase() && array[i + 1] === array[i + 1].toUpperCase()) { array.splice(array.indexOf(array[i + 1]), 0, " "); } else if(array[i] === array[i].toUpperCase() || array[i] === " ") { continue; } } return array; }
I would appreciate any help people could offer on this code. Thanks!
Think I have some adviсes for your code. Firstly you receive an infinite loop because when the space are added to position whith index i+1 (btw you don't need use construction "array.indexOf(array[i + 1])", just "i+1") in the next round of your loop you will examine element of array which contents this just added space. Space satisfies condition of your if, your script will add enother space to next position and examine it in the next round. You will never come to else branch. You must move on to position after just added space in next round. Add "i=i+2;" after "array.splice...;" (+2 because you don't need to examine space and next standing uppercase letter). And remove your else branch. Another thing: in condition of your loop you must handle elements only up to "i < array.length-1". The last element will be examinated in the penultimate round.
I don't understand why this is giving me an error when it works fine in my interpreter...The Kata:
In this kata you will create a function that takes a list of non-negative integers and strings and returns a new list with the strings filtered out.
Example
filter_list([1,2,'a','b']) == [1,2] filter_list([1,'a','b',0,15]) == [1,0,15] filter_list([1,2,'aasf','1','123',123]) == [1,2,123]
My CODE:
def filter_list(l): numbers = [int(l) for l in str.split(l) if l.isdigit()] print(numbers) string = ' '.join(str(e) for e in numbers) return string #return a new list with the strings filtered out
The ERROR:
Traceback: in in filter_list TypeError: descriptor 'split' requires a 'str' object but received a 'list'
Any help would be greatly appreciated. Thanks in advance.
Please can you post Kata-specific problems on the discourse page for that Kata instead of the forum which is for general topics. Each Kata has an automatic discourse page in which you can mark your comment as a question, which means it's easier for me to help (since it's easier to find). Also, since this is a forum page, I can't mark your comment as a spoiler, meaning people can look at your code and use it themselves, however on the discourse page I can hide your solution.
Somebody already answered your question on your other comment so I won't comment about that here.
My first code. It's the convert two numbers added together to a binary string one. This is my code.
def add_binary(a,b): return a + b c = 5 d = 3 sum = (add_binary(c ,d)) solution = bin(sum) print(solution)
It works but it doesn't pass the second test example. Any ideas?
Hi and welcome;-)! First of all never post code which can solve a kata (later on only hidden if necessary);-)... Your code isn't working because it returns the result of a+b as an int/number (base 10) - your first two lines. But the task is to return the binary result of a+b as string (without starting "0b")... So everything behind return a+b is only visible as output but not the result of the add_binary function...
Please can you post Kata-specific problems on the discourse page for that Kata instead of the forum which is for general topics. Each Kata has an automatic discourse page in which you can mark your comment as a question, which means it's easier for me to help (since it's easier to find). Also, since this is a forum page, I can't mark your comment as a spoiler, meaning people can look at your code and use it themselves, however on the discourse page I can hide your solution.
A few improvements:
1.) Your code returns the sum of a and b and returns it. However, your code doesn't return the binary representation (just the sum) since you are printing your binary answer to the console and not returning it in the function. The function will be called and the return statement is used to check for equality (the right answer), not your console log.
2.) Try not to you reserved language keywords as variable names, as then you can't use the keyword again.
3.) Use markdown to format your code properly - see here: https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#code-and-syntax-highlighting
EDIT: fucking smile you beat me to it - also congrats on 1dan you clever bastard
@AcesOfGlory: Thanks for your friendly words:-)... next time you are surely the first again... last time i often saw your explanations, so good work;-)!
Hi all, not sure if I am asking this question in the right topic section - but I completed a kata asking to remove all the strings from a mixed array. I was accidentally logged out when I submitted my solution and once I logged in I could no longer find that kata. I would like to submit my solution! If anyone knows the name for the kata could you let me know please? You need to create a filter function that removes all the strings from a mixed array and returns a new array with only the numbers. Thanks.
@ginnk
,Have you tried looking at your profile page and clicking on the
Kata
tab? There are options forCompleted
andUnfinished
katas.I never clicked on "train" so it was never added to my unfinished kata. Thanks though!
When if i can. i want to help translate. but where is translate section? i mean english -> korean translate.
Write a C++ function int div(double &nominator, double denominator) that computes the integer part of double division. It takes as its arguments double &nominator by reference and double denominator by value and returns the integer part of the division. Before returning the result, it assigns the remainder to the nominator. For example, if nominator is 3.7 and denominator is 1.4, the function returns 2 with nominator assigned a new value 0.9, since 3.7 - 2 * 1.4 = 0.9.
who can help friends??????? I need help....
: Write a C++ program that creates two 3-element arrays double price[3] and int items[3]. These arrays represent prices and amount of three different products respectively. The program inputs the element values of double price[3] array and double money – the total available money. It assigns values to the elements of int items[3] array as follows: the first element is the maximal amount of items of the first product that can be bought by the initial money, the second one – the maximal amount of items of the second product that can be bought by the remaining money, and the third one – the maximal amount of items of the third product that can be bought by the last remaining money
and third .....
: Chess is played on an 8-by-8 board. The columns (files) are enumerated with letters from ‘a’ to ‘h’, and the rows (ranks) – with numbers from 1 to 8. Write a C++ function int ddist(string cell1, string cell2) that takes as its argument two two-character strings string cell1 and string cell2 representing the column and row of two cells and returns the distance between them in a diagonal direction. If the cells are not lying on the same diagonal, the function returns -1.
Please can you post Kata-specific problems on the discourse page for that Kata instead of the forum which is for general topics. Each Kata has an automatic discourse page in which you can mark your comment as a question, which means it's easier for me to help (since it's easier to find).
Hey. people. my solution always too long and inefficient. how can i learn clever solution idea? is it about natural talent thing? if i don't have sense of clever code.. is it still okay?
lol so do i, but always remember, if it's stupid but it works , it's not stupid :)
Thanks Yoloswag!
Practice and practice! :D After completing a kata, try to learn from other solutions and try again by refactoring your code.
Learn data structures such as: LinkedList, Stack, Queue, Binary Search Tree, Hash Map, etc. Once you really understands those data structures, you will find the most efficient way to solve the problems. Solving them is easy, solving them efficiently is harder.
I'm having a problem with countPositivesSumNegatives(). I'm a newbie but can't figure out why I'm getting and error. Not fail, but error.
The error is long, but gist is "TypeError: Cannot read property 'length' of null at countPositivesSumNegatives". I have obviously taken steps to solve the obvious things this error suggests. All other tests pass, and none fail.
Can I get help here? Not sure where the offcial help forum is.
Please can you post Kata-specific problems on the discourse page for that Kata instead of the forum which is for general topics. Each Kata has an automatic discourse page in which you can mark your comment as a question, which means it's easier for me to help (since it's easier to find).
Your task is to construct a building which will be a pile of n cubes. The cube at the bottom will have a volume of n^3, the cube above will have volume of (n-1)^3 and so on until the top which will have a volume of 1^3.
You are given the total volume m of the building. Being given m can you find the number n of cubes you will have to build?
#include class ASum { public: static long long findNb(long long m); };
long long ASum::findNb(long long m) { if(m<0) return -1; double descr = 1+8*sqrt(m); double n1=(-1+sqrt(descr))/2; if(n1==floor(n1)) return n1; return -1; }
this code does not go through one test only, don't understand whatis the problem, help me plz
Please can you post Kata-specific problems on the discourse page for that Kata instead of the forum which is for general topics. Each Kata has an automatic discourse page in which you can mark your comment as a question, which means it's easier for me to help (since it's easier to find). Also, since this is a forum page, I can't mark your comment as a spoiler, meaning people can look at your code and use it themselves, however on the discourse page I can hide your solution.
SELECT c.customer_id,c.email,COUNT(c.customer_id) AS payments_count,SUM(c.customer_id ) AS total_amount FROM customer c JOIN payment p ON (c.customer_id = p.customer_id) ORDER BY c.customer_id limit 10;
I have done this for the SQL Basics: Top 10 customers by total payments amount question but it still does not work it also wants to return a float number as well for the total amount
Overview
For this kata we will be using the DVD Rental database.
Your are working for a company that wants to reward its top 10 customers with a free gift. You have been asked to generate a simple report that returns the top 10 customers by total amount spent. Total number of payments has also been requested.
The query should output the following columns:
customer_id [int4] email [varchar] payments_count [int] total_amount [float] and has the following requirements:
only returns the 10 top customers, ordered by total amount spent
Please can you post Kata-specific problems on the discourse page for that Kata instead of the forum which is for general topics. Each Kata has an automatic discourse page in which you can mark your comment as a question, which means it's easier for me to help (since it's easier to find). Also, since this is a forum page, I can't mark your comment as a spoiler, meaning people can look at your code and use it themselves, however on the discourse page I can hide your solution.
Hi everyone! Can someone help me with KATA Count of positives / sum of negatives Here is my code and there is one wrong value when I attempt to pass. Please, can anyone help me to find mistake? Thanks a lot. function countPositivesSumNegatives(input) { var positive=0; var negative=0; var array1=[]; if(input == 'undefined' || input == null){ return array1;} else{ for(var i=0; i<input.length; i++){ if(input[i]>0){ positive+=1; }else{negative+=input[i];}
var array=[positive, negative]; return array; } }
Please can you post Kata-specific problems on the discourse page for that Kata instead of the forum which is for general topics. Each Kata has an automatic discourse page in which you can mark your comment as a question, which means it's easier for me to help (since it's easier to find). Also, since this is a forum page, I can't mark your comment as a spoiler, meaning people can look at your code and use it themselves, however on the discourse page I can hide your solution.
Hello,
I have three identical solutions on a KATA. I wanted to delete two of them (cause they are identical) but couldn't do it.
So I decided to REFACTOR one of them by making the code better. After succeeding refactoring it, I couldn't REFACTOR it but only SUBMIT it. And as a result, didn't REFACTOR the solution I wanted to.
Does anyone have an idea on how to rewrite the solutions to avoid similar one?
I dont even think I'm answering any of the katas correctly. I dont know how to input anything, i think.
Is this a place where I can ask about the kata?
Hello! Is it possible to publish two solutions for one kata? I ask because I made a second try and the second solution-code isn't showed in the solutions-overview. Did I do something wrong?
Kata:Are they the "same"?(C++ learning the language) I seem to be failing only test 8. the result of the test is "true". anyone knows what that test test's? am i not checking some exreme cases?
Suggestion: What about adding more solution sort possibilities like "number of characters" or "runtime"? Is that possible?
Kata: SQL Basics: Group By Day
I have one failure during its execution. Here is test-case message: " should should return the expected results ✘ expected true to respond to
true?
or perhaps you meantbe true
orbe_truthy
"Does it connected with my code?
I get the same issue, i have got that on all the SQL katas i have done. The postgreSQL syntax is correct, but it keeps givin me that error message
https://www.codewars.com/kata/tribonacci-sequence/train/python
I HAVE SOLVE THIS BUT GETTING ERROR WHILE FINAL SUBMISSION
HERE IS MY CODE
def tribonacci(signature,n): if n == 0: return [] if n < 4: return signature[:n] for i in range(2, n - 1): new = signature[i] + signature[i-1] + signature[i-2] signature.append(new) return signature
If the problem is Kata specific, you should post on the discourse page for that Kata instead of the forum which is for general topics.
Refresh the page, sometimes Codewars is buggy is leaves code from previous attempts, if you refresh then it will remove this and you should be able to pass. I just tried your code and it seems to work fine.
#issue @twinbird24 The kata Average Scores works fine on VS2015 on my laptop, but doesn't work here. The second basic test returns a value of 94, but here, it's returning 78. please help.
#how to implement difference function #what is problem with my code def array_diff(a, b): for i in range(len('a')): if (a[i] in b): a.remove(a[i]); break;
Next time can you post this on the Kata you are solving instead of the forums page which is for general problems and not specific problems.
for i in range(len('a')):
a should not be in quotation marks because then it recognises it as a string and not as a variable.You can figure out the rest.
Hi! How to submit my solution? I'm now 8 kyu and I've solved the task from the 7 kyu, but I can't submit it. Why???
If it still doesn't work, screenshot the problem and reply to this comment and I'd be happy to help.
Here's one: http://prnt.sc/cuzau2
.
Codewars is a little buggy sometimes, all I can suggest is refreshing the page and trying again later - the Kata is currently working for me. Maybe try another Kata and see if that works and come back to the other one later.
Hi, I just joined and solved my first kata -- which when I view my profile I see as a completed kata. However, I wanted to peruse my solution again, just mainly for curiosity, but when I try to view solutions to this "solved" kata the system says I can't view them since I haven't yet solved the kata. Am I doing something wrong, or is this a bug? Thanks, and cool site.
UPDATE: Maybe I was doing something wrong - if I click on the kata and then solutions, it says that I can't see them as I haven't solved (though I have); but if I click on my profile, then 'solutions' from my profile, I do see my submitted solution. Maybe that's just the way things work, though it was a bit confusing. Perhaps working as designed?
The 'Solutions' tab on your profile allows you to look at all of your solutions to all the Katas you have completed.
I hope I helped ;)
i solved the training module called "mumbling" my answer is identical to the solution but its saying its wrong... what do i need to do
import sys def accum(s): # your code i = 0 j = 1 while i < len(s): a = s[i] * j sys.stdout.write(a.title()) sys.stdout.write("-") i += 1 j += 1
Hello, is it possible to delete a solution? I submitted two that were almost identical (didn't know you could refactor) and now I'd like to remove one. Thanks!
I'm also interested in this question. I thought after refactoring only the new solution will be present, ie the old one would be removed, unless I want it to remain present, because I made very meaningful refactoring, and I want that both solutions can be seen.
Is it possible to add the solution's runtime to each submitted solution listed? Learning the cool features and extensions to a language is neat, but example runtimes of the various solutions could be very useful.
It is not possible at this time.
Is it possible to view all the solutions of a user?
Hi everyone!! Does anyone has an example of how to getcenter from multiple markers (coordinates). I want to from the same example the google gives here https://developers.google.com/maps/documentation/javascript/examples/layer-heatmap?hl=es And try to get the middle of all GetPoints. By The Way, Thanks for the Help. :+1
center of each group or average center of all markers?
i dont know why although my output matches the same as the test cases result i still got error.. E.g. Error ,expected:0, actual:0
I don't understand why I can't see the solution of the kata while I am working on it...
because then you can use the solution as your own and passevery kata very very easily
Hi, I have succefully solved my first kata, at least I run the tests and it says it's all good, but when I submit it it says "1 solved, 1 failed" and tells me to try again,when I run the tests it says "1 solved, 0 failed", why is this happening?
How can i see the solution to any problem?
This web so helpful for me :))
Please help me to solve "Don't rely on luck" problem. Please I'm stuck.
Hello! Suddenly someone is from Ukraine or Russia Knock on Skype will work together skype: mister-djim!
How can I use library like underscore.js in my code?
I thought it would be really cool if you could save the amount of time a solution took in your database and use this information to rank the solutions. Since the one that took the least amount of time is probably the most efficient one.
Hi, I am new to code wars, could anyone please guide me where to write a solution?
Is there any way to remove first published solution? I have lucky completed one based on random tests and suddenly published it. Later I have solved it correctly but now there are two of mine solutions in the list.
Yes please, I also would like to delete a less elegant solution of mine.
Me too, as I already stated. :-)
How may I see the katas that I started but haven't finished yet?
Looking for those?
Wow! Thanks! I was bookmarking all of my katas, just so I didn't have to find them again. This removes the need for that. :)
Grouping through community set flags
I suggest a grouping mode based on tags that users give to a solution. Many solutions can be discerned by very obvious criteria a user (human being) is able to grasp very quickly, but tools cannot). For Java for example there are many java 8 solutions using streams/lambdas. Flagging these would be a good group. Then you have "Optimised", "Vanilla Java", "Java with Guava and oher libraries", "Clean Code/Refactored", maybe things like "With issues", "Obvious cheating/circumventing acceptance tests" etc.
The flagging system should allow introducing new flags on the fly, but also give a list of all the flags already in use. So you can flag with some clicks, or by entering a new name. Very similar to the system currently used for tagging (new) katas!
Advantage of tags that people can define is that people can decide about the interesting features of a solution or time ("Zeitgeist"). Grouping would benefit from the current trends directly mirrored in the flags given from a user, so to say.
Personally I do not fancy a machine based grouping that much. I don't care what some algorithm tells me is "like my solution", in 99% of all cases, it isn't anyway. Mostly I would be interested in those solutions that are not like my solution... but which algorithm could possibly know that...
So, more power to the users/community! Less power to tools. And actually, less power to the honor points as well (but this is another topic).
Well, you probably know it by now, but use the ideas page for new ideas. That being said, I should probably add my idea below to the ideas portal too.
I was so pleased finding a feedback section directly in the codewars environment, that I didn't read the intro sections (wheras, the intro section here does not state an info about the ideas page).
Sorry for the inconvenience, I'll move this post to the ideas page as well. (Followup: https://codewars.ideas.aha.io/ideas/CW-I-22)
There are tools out there that universities use for cheat detection that will normalize code (variable names, whitespace, partial evaluation) and then computer a modified edit-distance-like score of similarity. They used to use it at Cal. Can't something like one of those be hacked up?
User driven solution grouping
The problem
We all know that grouping solutions isn't easy. People use other variable names, import libraries in another order, indent their code not the same way others do. Some of those things can be handled, for example with
clang-format-diff
or similar tools. However, take the following three snippets:They're all doing the same, their behaviour doesn't differ at all. However, the current grouping mechanism doesn't recognize those solutions as "the same". A really different solution would be something along
So, how can we group those things better?
Lets get some Levenshteinian help
Disclaimer: I'm not an expert in comparing strings, so the following could be a load of bull****. There are probably better algorithms.
If we take the Levenshtein distance of the four code fragments above, we end up with the following (symmetrical) table:
The number in parentheses is
1 - levenshtein(str1,str2)/(length(str1) + length(str2) / 2)
, the other the actual Levenshtein distance. Lets call the number in parentheses the Levenshteinian likelihood, or LL. We can see that the LL of our last snippet Create to the other snippets is less than 0.9, whereas Import <-> No import are above 0.9, as well as No import <-> Minimal. If we would automatically group solutions that have a LL of 0.9 or higher, we would group Import <-> No import <-> Minimal, since grouping should be transitive.However, that's not good enough. There are too many false positives and false negatives that can happen, although a LL of .98 strongly suggests that both solution are the same. So what's this fuzz about? It's meant for an initial grouping score.
Involve the author
Whenever the user solves a kata, he's usually presented with other solutions. They're ordered by best practices, clever, or whatever the user chose the last time he browsed those snippets. However, when a user solves kata, he shouldn't be presented with those things, at least not initially. When the user has solved a kata he should be presented with something along this:
The suggestions are based on the LL: if any LL of a solution in a group is more than .90, we suggest the solution/group for grouping. In order to keep the calculations on the server side to a minimum, the LL should computed if the solutions' lengths don't differ too much and don't exceed a certain treshhold.
If the user things that none of the other solutions are similar, he can simply click on "None". Then, the scoring mechanism I mentioned takes effect.
Involve the users
Take the initial LL, multiply it by 10, and take 5:
ll(str1,str2) * 10 - 5
. You'll end up with something in[-5,5]
. Users can now vote for likeness. Each vote is weighted the same way a usual vote is weighted, so warriors with +500 honor change the score more than those with 20. As long as the score is between[-10,10]
(excluding the ends), the potentional pair is up to review. If the score reaches-10
, the pair is declaired unsimilar and removed from review, if it reaches 10, it's also removed from review, but the solutions get grouped.Afterwards, the LL of other items in the review queue must be adapted, but I'm not sure how to do that.
If a user gets 1 honor (or 1 group honor, a new point currency) per reviewed solution/solution or solution/group pair, it should be rather fast. You could also provide a "group solutions queue" or something similar.
Questions and Answers
What if the author groups the question incorrectly?
Well, that could be handled with flags, see my feature request.
What if I don't have a LL between two solutions, since they exceeded the threshold?
Have users suggest a pair, which will start with a score of
-5
.Should the votes really be weighted? After all, it's a review process!
Well, that's up to discussion. If codewars introduced "group honor", the weighting should be based on that instead of the usual honor.
One honor per vote? That's insane!
You want to motivate people to participate. Gamification is usually a pretty good way. That being said, one could change this a little bit. For example, the user gets 1 "grouping honor" and additional "grouping honor", if other users agreed with his vote, e.g. if he votes
+
and it reaches10
.Agreed with his vote? Well, then I'll just vote for the majority.
Which is why the current score should be hidden. Abuse and stuff.
Last words
So, this has been yet another rather long text/feature request/idea for something. I hope it has been enjoyable to read, as I just wrote this down in a jiffy as the ideas came along, and I really hope that I haven't messed up formatting. (Edit: yep. Headings aren't really there :/)
TL;DR
Have users handle the grouping instead of fully automated mechanisms. Lure them with points, score the grouping.
Is there any way to tell us how runtime-optimized a solution is? I see the "Process took ... ms to complete" message after solving a JS kata, and I wonder..
If that kind of data is solid and comparable, can you attach it to the solutions, to let us notice how methods we use compare to each other in runtime.
Just a number there, and I think I would learn a lot from it.
That would be really cool! But probably not reliable. If they upgrade or downgrade server speed, all the numbers will be off. Plus the
ms
is not reliable in the first place. But I like the idea.Right, the actual runtime won't be the best for this. Not just because the server thing, but also the changing, or random test cases make that unreliable. Any idea for an indicator for code optimization?
Yes, it would be an amazing idea to classify the answers also by performance!
It could work similarly to to http://jsperf.com/ . Any user should be able to test all the sollutions in his own browser. The numbers shown should be the average of all runs for the last version of Chrome and Firefox... And maybe IE, but I don't think many people access this site with IE.
The run-time of a solution could be updated when you select "compare with my solution" so that you could at least compare the speed of one solution versus your own. I agree that creating a global score would be challenging. Perhaps they could semi-regularly check run times on the top 10 up-voted solutions.
Not sure it would work for other languages, but for python it doesn't matter if you write
'some string'
or"some string"
, except for need to escape quotations marks accordingly (if you use'some string'
you can leave doubled quotation marks but need to escape single ones and vice versa). So in most katas it doesn't matter which quotes to use, therefore it would be great to group such things.Good idea, except if the language differs between characters and strings (e.g. Java, Haskell, C, C++, …). However, if the code really just uses other quotation marks, it should be the same (although not compiling anymore in Java, Haskell, …).
Well, as long as you can only publish solution if it passes all tests, I think we can assume that all code is correct. So if we have two solutions which arecompiled OK and pass all tests, and these solutions only differ in quotes used... Well, I think it's obviously same solution. At least I can't imagine same solution working both with chars and strings (if it's different types).
Not really the right place to left that tought but...
I don't feel like it is easy to refactor your own code. (I just discovered this otpion in my personnal page -> kata solutions -> completed -> refactor). I feel like it would be good to have a "refactor" button on your solution in the solution section of a kata. I often want to edit my solution a bit after seeing other solutions. Plus a "delete" button when you have multiple solution. For the moment even after refactoring i feel like the old solution appears first in the solutions when the refactored should be first.
Up voted for "delete" button.
Some more thoughts about grouping. Solutions like
def summ(a,b): return a+b
anddef summ(a,b): return b+a
are counted as different. Not sure if it's possible to detect such things, but it would be good I think. Also for Python functions range() and xrange() are counted as different, though usually Python2 users use xrange() as it had some advantages, and Python3 users use range() cause in Python3 it behaves same way as xrange() in Pyton2, while latter is deprecated. So difference between such soutions is just preferred version of language.Thinking about it, I assume that you could still consider these two things as different, but add some 2-leveled grouping. So that first you group things like now (really-really same solutions, different only in comments, spacing and var names). And then you count kind of index-of-difference, and group closest groups in upper-groups.
To illustrate: solutions using range() vs xrange() or a+b vs b+a will be in different inner-groups, but in same outer-group.
I know it must be a big thing, so it's more like "an idea you could consider to implement in some distant future", not an actual feature-request like "I do really want it" :)
If
a
andb
are set to strings, these functions are different, right?Yes, I see. First I really thought about math, so these were equal, but then I thought that it's really not that easy. So I wrote about upper-grouping.
Right now the grouping is based on edit distance.
You can check out the source here: https://github.com/Codewars/code-grouper
Sadly, solution grouping is a feature that many users abuse. Let me explain: first, they copy the top answer and post it themselves. We used to share points for top answers but we've discontinued this practice. Still, you can observe that many users still do this even though they aren't getting credit.
So I hope you'll understand, we are reluctant to invest a lot of effort in code grouping, as grouping to begin with sadly inspires cheating.
Maybe AST edit distance will be better metric than distance between code as strings?
Hi. Python solution grouping is also not perfect.
There are solutions, that are not grouped because of comments, what if all comments are cleaed for grouping?
Other thing is that two solutions with different variables' names are not grouped. Is it possible to group them?
Good points. The code grouping gem needs to be updated to handle Python comments. We will look into it today. If you know Ruby and want to take a stab at it, please check it out yourself. I'm sure there are a number of improvements that could be made to it.
As far as I understand, I only need to add Python to case switch (line 124)... That's easy :)
It looks like the java grouping is also causing solutions to not be grouped because of comments...
Seems like this was fixed by Katzen_gott but not merged yet :( https://github.com/Codewars/code-grouper/pull/2
The Haskell solutions grouping is kind of poor.
Two solutions like (f (g x)) and (f $ g x) come up as different solutions, causing most of the first page to just be the same solution with alternating sets of $'s and ( )'s everywhere.
The other thing I've noticed a lot of is that some users (inc. myself) put a linebreak after
module ... where
before they start the import list, whereas others do not. These are counting as two different solutions ...Perhaps desugaring (attempting to inline $) the Haskell and removing all whitespace would be a good way to test equivalence.
Good points. The code grouping gem needs to be updated to handle Haskell comments. We will look into it today. If you know Ruby and want to take a stab at it, please check it out yourself. I'm sure there are a number of improvements that could be made to it.
I posted a long discussion on this yesterday: http://www.codewars.com/topics/feature-requests#52604d92594da0c37c0009ba
I think the grouping should be as aggressive as possible. Tools to minify or, at the very least, format the code should be used where available. For languages that don't have any such tools would just be grouped as best as possible.
The additional metrics available for complexity and lines of code have tools available for most languages. I doubt very many languages have tools that implement the maintainability index that I promote, so Code Wars would have to cobble together different code bases to produce that metric.
Just googling around a bit, I found a couple open source options that could handle a number of options:
http://cloc.sourceforge.net/#Languages
http://saikuro.rubyforge.org/
http://thegarywilson.com/blog/2006/cyclomatic-complexity-for-python-code/
http://www.locmetrics.com/alternatives.html
I hope it's the right place to post this. Can you show more solutions on the kata's solution page? It's kind of annoying to not be able to see the latest solutions. I want to post simple and elegant solutions (after spending time on refactoring the older ones), but I am not able to do this, because my solution will never be visible to anyone.
Maybe a quick fix is to remove all the invalid kata solutions. For example, on this page http://www.codewars.com/dojo/katas/51675d17e0c1bed195000001/javascript half of them are invald solutions.
I recently deployed some updates and the solutions page should be better now. The infinite scrolling wasn't working after the 2nd set of results. I've also made it so that the invalid solutions are optionally loaded at the end.
Works great ! Thanks:)
Kind of belongs here, kind of about upvoting. I'm wondering what user participation is like in situations where solutions diverge so greatly as to fill the page? I try to vote for the solutions I like but at a certain point the length becomes prohibitive and what might be very nice solutions go unobserved.
I would love for some automatic pre-arrangement to be taking place, probably by performance because I imagine it the easiest test to automate, while style, elegance and clarity are better suited to judgement by vote.
Each language is so different and the potential tools available to group solutions are so different from one language to the next, that I don't think it really would be possible to have a one-size-fits-all-languages solution. Probably the best we could do is to define the different ways in which code could be grouped:
Clarity: How readily the code is understood
Performance: How quickly the code performs the intended task. (Would probably require benchmarking or some way to generate the big O notation.)
Innovation/Elegance: How inspirational the design is, making use of language features in graceful ways where naive solutions look more like a hammer was used to solve everything.
There has been some talk about using minification which would work for js and coffeescript. I'm unaware of any kind of ruby minification library (why would there be one after all). I would prefer to find a solution that works across all languages, including those we intend to support (such as Python, Scala, Clojure, Java, C#, Objective C, etc). If we diverge too much in how solutions get grouped then it could fragment the experience. For example, maybe one solution is better than another even though they are essentially the same, because one user used bad naming conventions and the other didn't.
Thoughts?