8 kyu
Total amount of points
36,287 of 118,751petrosernivka
Loading description...
Fundamentals
Arrays
Strings
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Perl translation
This was great practice for divide and conquer for clojure
It will count 3 points weather it wins from 2:1 or 4:2
The random cases are passing, however the fixed cases are failing. I can not tell which particular fixed case is causing this to fail. Anyone please help in point out the test case.
which language?
anyway, you can print your input
I used C, I found out what the issue was. Thanks mate.
it is not 8 kata 100%
i think it depends on language you chose to solve it. I learn Dart for 1,5 week. I have solved this. What i really want is to understand how could i made this in functional style.
I'm trying to figure out how to store the first char before : and then second char after the : into their own variables. then i can begin an accumulator. But I cant figure out the first part. Any one got any tips or cna point me in the right direction?
This comment has been hidden.
This comment has been hidden.
To answer by not giving spoiler, find a string methods that seperates the string provided
there is problems in test case!!
sure let me just grab my residual mind reader and scan your message to figure out what the problem is
This was really nice to practice syntax for a new language on.
The test cases in NASM have sometimes a space included in the provided test cases. It is not clear whether it is intended or just a typo. The description should be updated or the test cases corrected.
I fixed NASM test cases.
Lua translation is waiting for approval
Approved with minor edits
I think the kata should be kyu7. The problem is quite simple, but in many languages you need to use proper tools.
You should definitely pass by this question until you are advanced with arrays and have learned about advanced array methods.
Hint to solvers != kata suggestion
Test case suggestion: All the test cases have single digit scores. A wrong solution is possible by using the first and last characters of the 'x:y' string. Recommendation is to increase the range of the random tests or include an explicit multiple digit score.
Read the notes, it is specified the input can only have one digit numbers. So, changing the specs or the tests after approval would be wrong.
it was so hard 😭
yeah mate 😭
great kata!!
I don't understand what it is asking for as the end result. Only return x?
Can someone decode what 0 <= x <= 4 is mean?
Your team's score will always be between 0 and 4, both inclusive.
the values for the x should be between those parameters
random tip, I tend to read these like a sentence.. so
0 <= x <= 4
would read as:0
is "less than or equal to"x
andx
is "less than or equal to"4
.x value range from 0 to 4
whats up freunde?
halli hallo
hi
Language:Python All my outputs are correct, but the tests are failing.Don't know why?
Read this: https://docs.codewars.com/training/troubleshooting/#expected-the-same
I have this: Traceback (most recent call last): File "/workspace/default/tests.py", line 3, in from solution import points ImportError: cannot import name 'points' from 'solution' (/workspace/default/solution.py) Is it ok?
The function's name should be points, not sum_points. Don't rename the function, it won't work.
thanks!
This comment has been hidden.
Please use appropriate markdown formatting when posting code. See https://docs.codewars.com/training/troubleshooting#post-discourse.
No, there are no errors in the tests. I recommend reading the description before attempting to solve the kata.
satisfied :)
hi guys
This would've been more difficult if the author of the kata took into account the, albeit less likely, case of one or both teams scoring 10 goals or more.
Seems like I could have done this better had I paid more attention to the given constraints.
It was like a nightmare at the start, but its just about understanding whats it about.
Woohoo! My first Kata! Don't overthink it guys! Think about the problem, then code! Trust me! You'll be shocked at how much you may have overthought it!
I was attempting to accomplish this Kata without using a for loop, but cant seem to think of another way of doing it. After giving the for loop a go I keep running into the error "TypeError: 0 is not iterable" now im assuming that this has something to do with my loop, but i cant seem to see where i went wrong. Any guidance on where i might have messed up would be great, and if maybe you could give me another possible route to take to accomplish a correct answer without using a for loop would be awesome. Thanks for any help
A loop is required, simply because you don't know how long the arraygames
is. A solution without a loop isn't possible.Edit: Since there are always 10 games, you don't need a loop.
The error comes from this line:
let [i] = 0
, which tries to handle 0 as if it were an array. You should uselet i = 0
instead.Here are a few tips:
games
variableThis comment has been hidden.
In the description says that the team always plays 10 matches, but is secure to use a loop.
.
Hi! I'm getting this error but I don't see where the problem is. Anyone else having the same issue ? Traceback (most recent call last): File "/workspace/default/tests.py", line 2, in from solution import points File "/workspace/default/solution.py", line 13 pass TabError: inconsistent use of tabs and spaces in indentation
I fixed indentation of initial solution, which caused this problem. But you still need to fix your code, and make sure that all lines in your solution consistently start with spaces, or with tabs.
Hi! I got some strange error. In my function i used method of string "str.at()". And in console everything is OK, i got correct results in all cases (i took your examples). But when i tried to test my decision here, i got this error "TypeError: item.at is not a function". Can you tell me please, what is wrong. If you need my decision for checking i can provide it.
it sounds like you are using an old version of Node JS.
String.prototype.at()
requires Node JS >=16.6
. In the dropdown menu of the trainer, what is the Node version you have selected ?Thank you very much, sir. You are right. I have changed Node version and my code passed all the tests. I didn't pay attention to it before. Thanks again.
I don't understand this kata. Could someone explain me this, pleace?
nice kata!
This comment has been hidden.
Hint != kata suggestion. See https://docs.codewars.com/training/troubleshooting#post-discourse.
This comment has been hidden.
It is definitely Ok and you are strongly encouraged to do so , just don't google the answer directly by typing the kata title or description ^^
great thanks
really hard
Loved it! Finally something about football.
Btw, is football popular hobby among programmers?
I used to play FIFA a lot when I was younger.
Seemed very hard at first. but it is fun and doable :)
I like this one!
RISCV Translation
This one should be at least 7-kyu, in Elixir this goes kinda verbose. But it seems that the author cannot change the rank.
It was kinda fun anyway
This comment has been hidden.
use a spolier flag when discussing code (i added the flag)
also: state the language you're using to help others help you. I can tell from your profile that it's C#, but still...
have you carefully read through any error messages you get? if not, do that next and see where that leads you
This comment has been hidden.
Please use appropriate formatting (code blocks) when posting code.
Your solution contains a common beginner's mistake. Try calling your function more than once and see if it still behaves correctly.
thank you I will do as you said look at the outputs thank you for helping me
CoffeeScript translation
Approved
This comment has been hidden.
Your code fails because you're (ab)using some built-in functions counter to their intended purpose.
For more general troubleshooting help see: https://docs.codewars.com/training/troubleshooting/
Are the instructions correct? If you enter 'typeof' on parameters 'games' it returns an object, not a string. (I was wondering why split wasn't working!)
Yes, they are correct. In this case, the collection is an array.
games
is an array. Elements of the array are strings.The description says that the input is a collection of games. This is shown in exampels, and in example tests too:
assert.strictEqual(points(["1:0","2:0","3:0","4:0","2:1","3:1","4:1","3:2","4:2","4:3"]) , 30);
Oh I see 'games' is an array of strings, that clears things up, thanks
This comment has been hidden.
This one was a fun challenge!
yo this one is real hard
Nice kata, but way too hard for an 8 kyu. In my opinion it should be at least 7 kyu as this is much more advanced than other 8 kyu katas.
Ranks can't be changed :(
tog'ri
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
No way it's 8kyu 0_0
This comment has been hidden.
Hey, and welcome to Codewars. I don't use C/C++ so I can't help with your query, but just to say that if you don't get a reply via this kata page, you can always join the Codewars Discord (link is in sidebar on the left of your screen)
There are dedicated language channels where you're more likely to get a reply (especially if you ask clear and polite questions - as you did! - rather than just "why it no work???")
You don't actually need to discover the length of games for two reasons:
This one has more difficulty than 8 kyu in my opinion. I think its to be 7 or 6 kyu!
This comment has been hidden.
Your solution has a (small) mistake.
Error in your solution is not a kata issue.
Thanks, I found it
This comment has been hidden.
It could be a 7 Kyu kata according to this: https://docs.codewars.com/curation/references/kata-ranks/#7-kyu 6 seem a little too high for this.
Ranks can't be changed
This comment has been hidden.
Read the notes at the end. Not a kata issue.
This comment has been hidden.
The go version of the template has a
;
after the return statement, go does not use semicolons there.Removed.
There is a typo in the Javascript instructions.
3rd sentence:
"where x us our teams score"
'us' should be 'is'
Fixed.
Not 8kyu at all
This comment has been hidden.
I solve this kata in Java. randomTests Log Testing for: [2:0, 0:1, 0:2, 1:0, 0:4, 0:4, 4:3, 3:4, 4:2, 1:2] expected:<12> but was:<0>
basicTests Test Passed
What is the problem?
Hi,
Not an issue, a question (the kata isn't broken, it's just about your code that isn't handling that case properly.
Aside of the obvious answer that "your code doen't do the right thing", we cannot tell with so little information. Try reading a bunch in that wall of text, that might help: https://docs.codewars.com/training/troubleshooting
Cheers
Can I send you my code to understand what is the problem?
You cannot compare strings in Java with
==
(or you can but it will not give you the expected result) https://www.baeldung.com/java-compare-stringsuse charAt() method
Update to Scala 3
.
They should clarify in the problem that you don't want to track both teams, just the one team, and should clarify which team is 'yours'.
Is this fork any clearer?
Seems like someone approved my fork, so I'll mark this as resolved.
Thanks a lot! Forgot all about this! Appreciate that.
Esa monda la entiendo me tome un tiempo pensando como armar el codigo pero que es eso que sale al final?? no logro entenderla
Notes:
there are 10 matches in the championship 0 <= x <= 4 0 <= y <= 4
I think these are constraints but not checking any test case!! not 8kyu Notes: there are 10 matches in the championship 0 <= x <= 4 0 <= y <= 4
Definitely not 8kyu at all
Rust translation
approved
Although it was easy to solve, i would say that this is definitely not a 8 kyu
Not 8 kyu
Was a hard kata for me. Defo, not 8 kyu
Very good kata.
also, consider changing this to say ADD 3 points, ADD 0 points, ADD 1 point. As it is currently written, the user is lead to believe that points are to be subtracted
Done.
Seems like you need to understand the sport a little bit in order to understand what is asked of you. The description here is a bit convoluted.
also, consider changing this to say ADD 3 points, ADD 0 points, ADD 1 point. As it is currently written, the user is lead to believe that points are to be subtracted
What sport knowledge do you need? To know the team who has the biggest score wins? Please, not an issue...
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Please don't post solutions in the discourse. But if you must, make use of the
spoiler
button. Any function that takes in a number of arguments and must inspect all arguments is by definition at least O(n), wheren
is the number of arguments. This applies to your solution as well. A quick way to get a measure of complexity is to inspect your code for loops, and compare the total number of iterations in the loop.Thank you.
This was harder than the other 8 kyu katas I've done. Was not able to complete this with my beginner knowledge of Python
This comment has been hidden.
I'm not sure with what you are actually doing, but you must
return
the result, not print it withconsole.log
.OP solved it, closing
I am getting Indentation error. Sometimes Like this I do some kata also, I get Indentation error after all it is all good with the code. Please help what can I do in that case
Edit: My error coming is 'IndentationError: unindent does not match any outer indentation level'
Click reset, try again. I can't reproduce the error, check your code's indentation is fine.
This: if x>y - 3 points if x<y - 0 point if x=y - 1 point
should be rewritten as:
if x>y add 3 points if x<y add 0 point if x==y add 1 point
For a moment I thought I had to subtract :D
COBOL translation (author inactive).
Approved some time agooo
This comment has been hidden.
Please mind your language at least a bit.
The description is clear and understandable
This comment has been hidden.
else if(x < y)
you are comparing pointers here. this is not what you intended.
This comment has been hidden.
Sorry for format, didn't find how to not lose indents in copy-pasting.
About the format, read this: https://docs.codewars.com/training/troubleshooting#post-discourse
This comment has been hidden.
This comment has been hidden.
Could a test case added with a result over 10 in one of the entries?
Some solutions are not changing the results to integer because just comparing the characters is enough. But comparing "12" to "2" would give the wrong result to them. Specially if they don't split and just compare the first and third character, so "1">":" is also false.
impossible, because of the restrictions given in the description:
When compiling gives error "Unexpected } on line 9" when I don't even have a line 9.
Either your code causes that error or you changed the sample test and that caused that error, click reset and start over.
No random tests in Go (despite it has a random tests
describe
block ~~)This comment has been hidden.
Can someone explain the first line of the C++ version please (already typed in the editor)? Much thanks! Here it is:-
What is the meaning of the input of this function?
int points(const std::array<std::string, 10>& games)
I am not sure how exactly you want to have it explained, but it can be read as:
Thanks a lot @hobovsky, your reply cleared my doubt. Really helpful!
Clojure Translation ready for review
Approved some time agoo
This comment has been hidden.
Java tests are not written correctly. For example: {"1: 0", "2: 0", "3: 0", "4: 4", "2: 2", "3: 3", "1: 4", "2: 3" , "2: 4", "3: 4"} -> 1 + 2 + 3 + 1 + 1 + 1 + 0 + 0 + 0 + 0 = 9, but the test shows a value of 12
Read the description again
{"1: 0", "2: 0", "3: 0", "4: 4", "2: 2", "3: 3", "1: 4", "2: 3" , "2: 4", "3: 4"} -> 3 + 3 + 3 + 1 + 1 + 1 + 0 + 0 + 0 + 0 = 12
In PHP I get the following error in the test:: 'Failed asserting that 10 matches expected 30'. I only return the value of 30 in this way "return 30;" to know what kind of result should my function return. Can someone tell me what value should I return to pass this test case please.
Actual and expected were flipped in PHP. Click Reset, try again.
Thanks Chrono79, I reset and tried again and now I get the following error: 'Failed asserting that 30 matches expected 10.' the test case is this '$ this-> assertEquals (30, points ([' 1: 0 ',' 2: 0 ',' 3: 0 ',' 4: 0 ',' 2: 1 ',' 3 : 1 ',' 4: 1 ',' 3: 2 ',' 4: 2 ',' 4: 3 ']));' the value I returned is this 'return 30;'
No, that can't be right. How do you know that test is failing? If you are using the sample tests, comment out the others and with
return 30;
it should pass. But it won't pass the next test that's expecting 10.It was my mistake, thanks Chrono79, it was solved.
This comment has been hidden.
You have different indentation there (2 spaces and 4 spaces), make them all the same.
Sorry. I am still editing it. Forgot to format for code, and then indentation changed, but I swear mine was ok :D :D
Why is the for loop indented different than the var initialization?
I don't know. Here, I see it as you, indented 4 extra spaces regarding the variable above, but in the coding space it has the same indentation. I don't understand it.
Delete all indentation, write it again.
Yep, I wrote it again and it worked. I don't know. Maybe something to do with mixture of tab & 4 spaces? By the way, thank you for helping, Chrono79.
^ That, and you're welcome.
How about mentioning how football scores work. A lot of people don't watch sports. They might not know which is your teams score.
Then they learn how football scores work from solving this Kata. Thats a win!
dud i'm not gona waste 15 minute to learn some stuf not gonna add any knolage to me to just solve one single keta!!!
Is the point of this just code golf (AKA write a solution in as few characters as possible)? I ask because the preferred solutions do not take any error checking or validation into account.
the point is to just pass every single test. Meaning if the tests do not enforce any validation of the input, you don't need to implement it (aka, TDD approach)
ok, I can agree to that, but if the kata has conditional criteria and the tests don't enforce the conditions, isn' this a poorly formed kata? I wouldn't have wasted time and energy on the conditions then.
what condition are you thinking about, exactly?
At the end are these constraints:
Those constraints are given to you so you know the input will be like that, not that you need to validate it.
Ok, because the problem doesn't explicitly say these are constraints enforced by my function, I don't have to code to them. They just let you know the collection won't be insanely long, and the x and y values won't be crazy big. Thank you.
I don't really get this. Do i need to create a random list of values or i need to input them? Please, give me a little hint of way that i can do that
They are provided to you. Exactly ten scores.
OP solved it, closing
C# random tests issue
Solution SolutionTest RandomTests Test Failed Expected: 145 But was: 0 Completed in 94.1030ms
=========================
And how's that an issue?
The random tests produced championships with 100 matches, now I've fixed it to comply with the description.
Expected: 145
we can maximum get 10 matches * 3 points - 30 points per championship
Now it works. Thanks!
Go does not have random tests
Raised above (didn't see this issue as first sorry ~~)
Kotlin translation is ready for review!
'alr approved some time ago'
Are you sure there is noting wrong with the random tests in c#? I can't pass only them, expected walue 120, 138, 153... we can maimum get 10 matches * 3 points - 30 points per championship how can test expect values above 30 with these rules?
Same here. The test work perfectly but when I try to valid my answer, every random tests are failing.
I just passed it without issue.
The C# translation is not producing those bigger numbers. The scores in the random tests are within the given constraints.
The championships in random tests had 100 matches instead of 10.
Factor translation ready for review!
I think this kata should be 7 kyu IMO
This comment has been hidden.
proper markdown formatting
Wasn't immediately clear but suggest stating that we want the point value of the "x" team.
It's already been reported but the go version is missing the package statment, i.e it should have the statement
package kata
as the first line.no need to have duplicated issues, then.
edit: done
Go, package missing
Racket translation
The "reset" state for Go should have
package kata
added as the first lineThis comment has been hidden.
done
Julia translation
Elixir tests have
x
andy
greater than 4.done
This comment has been hidden.
This comment has been hidden.
All random test results expected to equal 30 in javascript regardless of their actual values.
You were mutating the input, that's why you got a wrong expected value, now it doesn't matter because I fixed it. Try again.
In Go version missing package declaration "package kata"
In Haskell the length of list is not always
10
:Random tests:
STDERR:
Fixed.
I've solved this in Haskell, but it still shows as a non-completed kata
https://github.com/Codewars/codewars.com/issues/1592 https://github.com/Codewars/codewars.com/issues/1683
This comment has been hidden.
Load my code at the beginning with the CONVERT function, but it did not allow me, so I had to use the INT.PARSE function, if someone can indicate why you have this error please explain to me
You need to
import System;
,Convert
belongs toSystem
namespace. It's basic C# knowledge ;-)The Java test assertions are incorrect based on the description. The following should return 12 and 9 respectively, but the Tests are asserting with 12 and 15 which I have no clue where you deduced from. System.out.println(points(new String[] {"1:0","2:0","3:0","4:0","2:1","1:3","1:4","2:3","2:4","3:4"})); 1+2+3+4+2+0+0+0+0+0 = 12
Your points calculation is wrong. The expected values (
15
and12
) are correct.can u elaborate how? ive shown my calculation next to the game's scores in earlier comment
Where did you get 2 points for second match (or 1 for the first one)? For each match won you get 3 points.
lol, i was using the winning score instead of 3. thanks!
Regarding the C translation: Even though the exercise description mentions there are 10 matches in the championship, I recommend adding a "size_t n" parameter to the function "int points(char* games[], size_t n)" with "n" representing the number of string elements within char* games[]. Doing so will explicitly include this information within the source code itself and represents a software engineering best practice when passing an array of strings to a function. Additionally, it offers beginning C Programmers a glance at size_t data structures.
The user can modify the input in Python.
Hii! What do you mean?
The user can change the input array which will make your reference solution return a value known beforehand.
In "Sample Tests"? How can I to fix it?
Either one is good.
Fixed.
This comment has been hidden.
Fixed.
What do you mean with this?
I tested a code with the sample test and it works fine, but when I try to submit fails, and in all cases it says that is expecting the result to be zero
Thanks
There are 10 matches in the array you need to process. x and y will not be smaller than 0 or bigger than 4.
I'm doing that. The code that I'm trying to submit has passed the initial tests, but on the others is failing and like I said it's very strange because it says that is always expecting zero as result
https://www.codewars.com/kata/total-amount-of-points/train/javascript/5c917b4aaccd820016f40d8f
Thanks
You're probably mutating the input.
Hi,
No and I think there's an issue with the tests when we try to submit, because all of them are saying that the expected result is zero. On the sample tests the code, are working fine. For what I saw now, on the tests that runs on the submission, it's passing an invalid array
Ex: Testing for points(['1:0','2:0','3:0','4:0','2:1','3:1','4:1','3:2','4:2','4:3']) Test Passed: Value == 30
Testing for games = [1:4,1:3,2:0,0:2,4:3,4:1,1:1,3:4,1:3,1:3] = It should work for random inputs too - Expected: 0, instead got: 10
But have you tried not mutating the input?
What do you mean with 'mutating the input'? It's changing the initial value? If it's that, I'm not mutating.
Note: I'm doing with javascript. My function it's always expecting that the value sent it's an valid array
Could you just post your code in a comment with a spoiler tag?
Write
console.log(games);
as the first line of your code and before your function's return line too, see if they're different, if so, you've mutated the input.No, I'm not mutating the input
This comment has been hidden.
You've destroyed
games
withsplice
how is that not mutating the input?I forgot that, even doing it just to assign it to another var, it was mutating it :/ Thanks
C++ translation. Please, review and approve.
Bumping translation.
PHP translation: https://www.codewars.com/kumite/5c9100b5f7701d7d48fe2ec1?sel=5c9100b5f7701d7d48fe2ec1
Please, check!!
Approved
How to equate x:y to the numbers in the kata?
Reason translation: https://www.codewars.com/kumite/5c8536d21da38406aa426faf?sel=5c8536d21da38406aa426faf Please approve.
Approved
Go translation added. Please approve.
Approved
The go version is missing the package name at the start and thats causing a weird 422 server error, please add it:
Read-only strings are passed as non-const
char[]
in C.const
addedC translation update
.
I spent 10 mins comparing a number to the ':' character before i realised what was happening. :) I compared using the string values but am guessing there is a better way also for all possible scores
LOL, same thing
I just woke up
This comment has been hidden.
Shouldn't
else if(x=y)
beelse if(x==y)
or justelse
? Mark your post as having spoiler content next time. Why are you using float instead of int?atoi
accepts a NUL-terminated string, which isn't what you pass.This comment has been hidden.
Infinite loop, out of bounds access by index, wrong
return
condition. You really should learn C at least to some extent before trying to solve anything with it.I refactored alot and cannot get it to work for the
while
loop using those conditions. Thanks for ideas.This comment has been hidden.
Return instead of print
C# Translation
Approved
This comment has been hidden.
I apologize to the haskell-programmers community)
Apart from that, there's an inconsistency in the usage of these terms:
IMO, both should be replaced with a more generic word like "collection".
Fixed. Thanks
This comment has been hidden.
Approved
Please, NASM Translation
Approved
Haskell translation
Please approve
Ruby translation
Please approve.
At first attempt I included the result in a str(), but it returned error u.u! I'd just suggest if it could take into account that case hehe, just for embellishment purposes xd Good kata :)!
In which is the language? Thank you for your feedback!
Py! Anyway, it works as intended when an int is given as return :)! Thanks (Y)! Gonna keep practicing haha
Good coding :)
C translation kumited
please scrutinize for approval
domo!
scrutinized)
This comment has been hidden.
Hi!
Problem with spaces in 5 lines. Also use "games" as a list, not as a dict.
Good luck!
This comment has been hidden.
Fixed. Thanks!
Are you sure about the
0 <= score <= 4
limitation? Some solutions (like this one or this one) would fail if there were scores which have to be compared as numbers and not alphabetically (e.g.10:2
).The description states that:
ergo
10:2
is not possible, which you can also see when you look at the random tests.Yes, you are right. But football teams very rarely score 10 goals or more. So leave a range from 0 to 4. Maybe I will do kata with basketball teams, then the range will be bigger)) Thank you for your feedback!
Not very rarely 5 - 10 mathes in a year. It is quite enougth to expand tests)
Hi!
This is a special tournament)) You're right, that's enough for a test.