7 kyu
Complete The Pattern #2
2,310 of 7,409DivyanshBatham
Loading description...
ASCII Art
Puzzles
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.
Java:
Actual and expected of random tests are swapped
Should use assertion messages instead of logging
Reference solution should be
private
python new test frame work
Approved
Excelent kata, many concepts in just a few lines.
This comment has been hidden.
me no like kata this
Dear Curious_db97 Thank you for this Kata. Although I'm a new coder and do not have a strong base for comparison, I found this very challenging! At first I was pulling my hair out trying to figure out how to detect the object ends with 0 or not, and how to remove a single item or 2. ex: How did the pattern go from: 543210 to 5432 ??
Was it your hope to create this type of consideration? Thankfully, an accpetable result was finally discovered! (although I don't have much hair left) Thank you!
Julia translation
I'm unsure why mine is timing out... This is the error I am getting. ( C# )
STDERR: Process was terminated. It took longer than 12000ms to complete Signal: Process exited prematurely with a SIGKILL signal.
It shows that I'm passing all the tests?
Test Results: Tests RandomGeneratedNumbers Test Passed Completed in 0.349773ms SimpleNumbers Test Passed Completed in 0.000266ms
-isystem /runner/frameworks/cpp/ error: 'pattern' is a private member of 'Pattern' Assert::That(Pattern::pattern(4), Equals("4321\n432\n43\n4"));
(c++) here is a issue or I do something wrong ?
pattern
should bepublic
. I've change the initial solution.This comment has been hidden.
Your code results in trailing
\n
at final output. You can highlight the entire region for that specific failing test case to see it clearly within the output panel.This comment has been hidden.
res += "\n"; res = res.Remove(res.Length - 1, 1);
this case has solved the problem, but I wonder why is it different than VS? Does it have anything to do with Mono 4.2.3?
Don't escape new line character.
That's right but why is it different from VS?
Actually the thing is that, testcases are written like that. It has nothing to do with VS or any compiler.
Alright
This comment has been hidden.
verry odd output in cloud ide:
pattern(11)
gives:
1110987654321 109876543210 9876543210-1 876543210-1-2 76543210-1-2-3 6543210-1-2-3-4 543210-1-2-3-4-5 43210-1-2-3-4-5-6 3210-1-2-3-4-5-6-7 210-1-2-3-4-5-6-7-8 10-1-2-3-4-5-6-7-8-9
i don't see where the dashes come from
This comment has been hidden.
the last \n i find it
I have an strange error: ✘ Expected: 1, instead got: 1. It works in cloud IDE but here i got the error. (javascript)
Probably Extra newline at the end of output string.
Trying Escaping the newlines of your output string and then compare the results.
yes, i already fixed it. Thanks for answer.
This comment has been hidden.
C++ translation kumitted kindly approve it so that c++ geeks can give it a try.
Done :D Also I suggest you to join this gitter chat room for further - https://gitter.im/Codewars/codewars.com/
O I've already joined that. Can u please approve the pattern1 translation. Or is it having some problem.
This comment has been hidden.
'looks like you've solved it'
What am I doing wrong? On the first test, I have a failure: 1 None should equal '1'
or
Why I can't connet "from future import print_function" ?? File "", line 6 SyntaxError: from future imports must occur at the beginning of the file
Language?
Python
Can you post your code here as a spoiler? Then I'll notify someone who knows python.
This comment has been hidden.
This comment has been hidden.
I get this error "Submission timed out while communicating with our servers. This may infrequently happen if our servers are extremly busy. Please try again. If issues persist you can check status.codewars.com to see if server issues are being investigated. " on submitting the solution. Why it is like this"
Most likely server overload. Just retry.
I don't get it.
Expected: 54321 5432 543 54 5, instead got: 54321 5432 543 54 5
I am returning the output. What's wrong?
Most probably a whitespace problem. It's difficult to see them in browsers. Make sure you are not printing any extra newline chars before or at the end of pattern.
Thanks CM for replying ^_^
This comment has been hidden.
remove the last "\n".your output is "sb.toString()"= "54321\n5432\n543\n54\n5\n"
Hi, i receive the following output for my code - and though it seems to be ok i still get an error in the browser and won't let me pass. My output: C:\Python27\python.exe C:/Users/########/PycharmProjects/TestProject/TestPackage/test222.py 1110987654321 111098765432 11109876543 1110987654 111098765 11109876 1110987 111098 11109 1110 11
Process finished with exit code 0
I get a message: "None should equal '1'" Not sure what the problem is. Thank you.
Can someone please elaborate as to what is wrong with the output?
Can you post your solution as a spoiler?
This comment has been hidden.
I got it ^_^' You are printing the solution instead of returning it as an string. Read the Instructions carefully, moreover I made it clear in the kata description.
Read this (An Extract of Description) :
The actual expected values (when I try to submit) do not respect the requirements. For example:
Expected: 16151413121110987654321 1615141312111098765432 161514131211109876543 16151413121110987654 1615141312111098765 161514131211109876 16151413121110987 1615141312111098 161514131211109 16151413121110 161514131211 1615141312 16151413 161514 1615 16 instead got: 16151413121110987654321 1615141312111098765432 161514131211109876543 16151413121110987654 1615141312111098765 161514131211109876 16151413121110987 1615141312111098 161514131211109 16151413121110 1615141312111 161514131211 16151413121 1615141312 161514131 16151413 1615141 161514 16151 1615 161 16 1
After trying it a few more times I noticed that the issue arises when the last digit is a 0. It all goes fine until it encounters a 0 after which is starts chopping two off the end.
@TeodorDumitru I will sugest you to just sit back and relax! You are trying to find a more complex solution for a very basic question... And IMHO This post looks more like a question instead of an issue.
Actually you misunderstood the problem, see the examples again carefully.
I have exactly the same problem.
This comment has been hidden.
I don't understand why I get that "slice" doesn't exists, do I need to write my own functions for everything?
No you don't need to write your own functions, There maybe one of two problems :
This comment has been hidden.
First please format your comment using-
To create a code block leave one blank line above and below the code, then in the staring of every code line provide atleast 4 Spaces / 2 Tabs. Then whatever you write will be displayed as it is.
To make some text Italic or Bold Close it between Single and Double * Respectively.
To create a bulleted list leave one blank line above and below and then write whatever you want as a bullet after a single @s Note: here s represents space. And at the place of @ there is star or asterisk
Use can also use basic HTML.
Want to know more then visit this. OR comment again.
And as I guessed you code is producing an extra newline after the pattern:
Expected: 1, instead got: 1\n
To make it clearer :)Post your formatted code here as a spoiler so that I know that you understood what I meant :)
This comment has been hidden.
This comment has been hidden.
I just founded another link for Markdowns ^_^
Awesome! Thanks a lot for your help! I'll definitely practice writing the code with an array to try and make it look a lot nicer. And thanks for the Markdowns link! I know I have a long way to go but this has definitely been a big help. Thanks again!
Just saying thanks like this is not that much good as I think of it, because you can easily give another person 1 honor point by upvoting his/her comment :P Or can give several by upvoting the katas authored by him/her :P
Check this out you must have gained a honor point <= Just for demonstrating purpose
Haskell translation available.
Approved ^_^ but I'm not able to approve that of pattern #1 whenever I try I get "Uh oh! Something went wrong! (500)"...:(
Huh... I can build it, so there shouldn't be a problem...
Maybe Codewars just had a hiccup? If you try later tonight, it might work.
Yeah I told you just to notify you..:) And not tonight in the morning here it is 12:14 AM
Some remarks about the Haskell translation:
The instructions did not clearly indicate that where n is greater than 2 digits in length that you want the 2-digit numbers removed as whole numbers or as individual digits:
151413121110987654321
15141312111098765432
1514131211109876543
151413121110987654
15141312111098765
1514131211109876
151413121110987
15141312111098
1514131211109
151413121110
15141312111
1514131211
151413121
15141312
1514131
151413
15141
1514
151
15
1
vs.
151413121110987654321
15141312111098765432
1514131211109876543
151413121110987654
15141312111098765
1514131211109876
151413121110987
15141312111098
1514131211109
151413121110
1514131211
15141312
151413
1514
15
This can be inferred via the "upto n number of rows" part of the instruction but it could be more clear.
Additionally, I would recommend adding a unit test to cover that scenario.
Something like this would be nice:
Assert.AreEqual("1110987654321\n111098765432\n11109876543\n1110987654\n111098765\n11109876\n1110987\n111098\n11109\n1110\n11", k.Pattern(11));
Hi, the thing which you are talking about can be infered by the user by seeing "upto n number of rows" and the algebraic pattern example. Making it to the point maybe too much spoon feeding...:)
I finally did that as I was
reformating the description of all my katas
, Let me know If you like it now :)Kata was more complicated than initially thought, but was just alright. Hmm, I am far from implementing Python "one-liners", but I notice I am not generating too much code either + readable.
How to know if my code is good at all ? Should I strive to learn these Python one-liners ? Because nearly every Python kata solutions section has these, and it worries me that I can't comprehend them.
You do not have to make all your solutions as one-liners. In real applications, I think one-liners are usually bad practice because they tend to be less readable (not always, though).
Those one-liners you see in solutions are mainly for fun, to show a "smart" way of solving things. However, it is a good idea to learn to read them well, as it will make your code reading skills better.
And to learn to read one-liners, you should try make one yourself :) Vicious circle!
I think it is a good idea to ask questions how a solution works if you cannot comprehend it yourself. It will help you develop your skills faster!
Many Ms Man makes some good points.
One line functions are bad functions. Knowing how to read them will help because many people write them.
Don't be worried that you can't comprehend them. Rewrite them on multiple lines using variables and you will find that you can comprehend the logic and what they have done is obfiscate it through their "cleverness". This is the definition of unreadable code. It isn't clever, it's unreadable (not to mention undebuggable).
Always write your code as though you are not going to be the person to maintain it. As much as possible it should be self documenting. If your code becomes difficult to understand because it isn't self describing due to an important consideration like performance, comment it. Instruct people why you have done what you have done.
It is not you who are falling short here. One line code writers without explanatory documentation are bad at what they do.
Thanks for reassurance, I was thinking along these lines, but was seeing upvotes mostly on oneliners, therefore was a bit confused.
This comment has been hidden.
Hey @beaugaines I don't know anything about python right now, but I guess their is "/n" in the end of the string..:-)
This comment has been hidden.
I think it is just because it does not make it any shorter and more understandable in this case - you still have to define the function. I tried this approach, and you can see how it does not simplify the solution.
I think the understandable thing is upto background, for me
map(f, iterable)
is more readable (lately mostly working on clojure). And you can always use a lambda rather than define a separate function.I think it is more upto the background in
for
vsmap
case.But I am really thankful for seeing so many solutions with
for
. I was not so used to it, but now I am very comfortable using it, helps a lot.Same as with the other kata, still if you wish to approve my translations :)
Approved :-D