7 kyu
Moves in squared strings (I)
365 of 13,969g964
Loading description...
Fundamentals
Algorithms
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.
Nim: even if the assertion is wrong, the tests will be marked as completed due to console output inside of the
dotest
function; although the assertions are processed correctly by giving the error at the end. UPD: apparently this happens because of helper functiondotest()
...merged the fix fork, closing
Scala fork to resolve the suggestion by me below
merged
Scala has an outdated version 2.1.3; it's recommended to upgrade it to 3.0, as well as testing framework.
upgarded by fork of mine
No random tests for Rust (probably for other languages too).
added, won't resolve it for now until it's verified all translations has random tests though
hi for dart there are working random tests just checked
all other languages seem to have random tests, closing
This comment has been hidden.
wasted more time because of that bash note i took as the actual things to do please don't make the same mistake i did
python new test framework is required. updated in this fork
Approved
Based on one of the top solutions in Python, there should be test cases for the "lower order functions" to ensure they work correctly. The specific solution I'm referencing sends lists to the lower functions which is against the scope of the functions.
I am not sure to understand your post. The kata asks for writing "horizontal_mirror", "vertical_mirror", "oper" nothing else and these functions are tested through "oper" function as can be seen in "Sample tests"; everybody can manage all that as he wants.
This comment has been hidden.
It has not been a problem for the few who passed the kata. Read the documentation for "SplitString" (System.StrUtils) or see "stackoverflow.com ... pascal-split-function".
As stated it can be parsed as a literal slash and n character, but it was a mistranslation of the original test code. In the other languages it was a newline
This kata is just poorly phrased, which is unfortunate because its pretty easy. Kinda hard to code something you dont know.
It was amazing Kata. I tryied to solve it about 4 hours. I wrote 40 lines of Kotlin code, and I did it !!! Then I had find solution for a 3 lines ))
Just finished in C#. Be wary: in my local environment, I had used two escape characters '\\n' to denote '\n' in a string - and that was perfect. But in the Codewars tool, it only wanted '\n' for some reason...
This comment has been hidden.
Your
vert_mirror
works fine, the error is elsewhere. Next time please use markdown tags to format your code, as explained there: https://docs.codewars.com/references/markdown/#code-blockhow to pass a vert/hor method as a parameter?
Advice for author, you make the description way more difficult than it needs to be on all your katas. thanks
This comment has been hidden.
You are mirroring along both axes I think
When I executed that line in IntelliJ, it worked as intended... hmm
Your code fails because you are using the wrong string for
separator
anddelimitter
This looks like a monster before realising it's not that hard.
stuck at oper function any hints guys I dont know how to handle static function passing in methods
Not a kata issue. Google is your friend! Cheers.
okay I will check
im unable to solve it using dart because (return r"") or (return"\") returns me ("\") why?
It's a question, not an issue.
it's issue because i want to print one / but it returns me two // in vs code the same code returns / with no problem
r'/' doesnt help
This comment has been hidden.
Thanks!
Func <string, string> f1 it doesn't work. How can I do it in C#?
This comment has been hidden.
It seems that you passed...
I did, I was confused about the bash instructions, all clear now, thank you :)
Loved this one. Learned something new :)
Thanks
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
should be... \ponm
This is really hard to undarstand this kind of spaghetti instructions and functions names
This comment has been hidden.
i am really not understanding it from last night i have been trying to understand but it's hard! Is there any hints or reference i should go through... please ?
This comment has been hidden.
In languages (like Go) with UTF-8 strings (variable number of byte per character):
Add a test case with 2 byte characters (like ±):
Solutions with byte access despite the structure of UTF-8 strings will fail the test.
This comment has been hidden.
Please which language? A question is not an issue, sorry.
static std::string oper(...,const std::string &s) When I press test, I get an error about this 3 dots (...).
I's a placeholder, you are supposed to remove the dots and fill it in with something.
Thank you!
OP solved it, closing
The instructions example:
s = "abcd\nefgh\nijkl\nmnop"
has 'n' and 'm' mixed, it seems to me
\n
is a newline escaped sequence. The string is ok.See?
Yes - it was me who was mixed up - thanks!
STDERR Traceback (most recent call last): File "main.py", line 8, in testing(oper(vert_mirror, "hSgdHQ\nHnDMao\nClNNxX\niRvxxH\nbqTVvA\nwvSyRu"), "QHdgSh\noaMDnH\nXxNNlC\nHxxvRi\nAvVTqb\nuRySvw") NameError: name 'oper' is not defined
Getting this error for python. I tried running the test without any code. I just put pass under the first function and i still received this error.
hi,
Not an issue: you're supposed to define that method too. You didn't (or you gave it another name).
If you need to get the initial solution again as a base, copy your code, then reset the trainer.
Ah gotcha. Thanks!
Hi all! Doing Shell. Please, point me to the right direction. I'm getting this error every check:
Test Failed expected: "QHdgSh\roaMDnH\rXxNNlC\rHxxvRi\rAvVTqb\ruRySvw" got: "QHdgSh\\roaMDnH\\rXxNNlC\\rHxxvRi\\rAvVTqb\\ruRySvw"
And I can't solve the problem with ecaped \r. Maybe i didn't understand a task?It seems you understood the task; you could Google something like "use of escape char".
Thanks!
Two months... i've lost two months just to find out that there is
-e
argument ofecho
command.Really enjoyed this kata, but I don't think it's 7 Kyu. It was more like 6 imho.
def horMirror(strng: String): String = { // your code }
strng
should be replaced withs
orstr
vertMirror
orhorMirror
is not proper name. Please avoid such shortcuts.Prolog translation kumited. Review carefully o_O
... I don't know Prolog, I trust you, approved!
That was the first time I tried writing random string generator for prolog, very hard to find anything online for it. I believe I tested it thoroughly, but you never know :P
Anyway, thanks!
This comment has been hidden.
This comment has been hidden.
Vertical is horiztonal and horizontal is vertical.
In practically all graphics editing software, which presumably many more people have experience with already, the vertical flip is not the one that spins the surface 180° around the vertical axis, it is the one that swaps the pixels according to their Y positions and preserves their X positions (i.e., spins around / mirrors across the horizontal axis). Yes, there is a horizontal aspect to every vertical flip, and vice versa, and it can't be helped.
For comparison, the complex conjugate of a point is mirrored across the real axis, while the component that actually changed is the imaginary. We don't actually, but if we did, would we call it a real flip, or an imaginary flip? It's a matter of convention, tradition, notation, etc. And here, author takes the the uncommon one.
I'm just sayin', for everyone else who comes after and likewise feels a bit disoriented. Don't worry about it, just follow the examples using the terms in the description until the tests pass ;)
Holly shit! And here I thought my solution was smart... Mad props to you man!
arigatou!
but I should point out that I redundantly recompute plenty of rows & columns for each character while one or two nested
for()
loops would avoid most of those. This style presumably sacrifices at least some performance, even though the compiler will do whatever it wants anyway.Dart and Elixir translations
I tried to approve the Dart translation but each time I click "Approve" nothing happens and no feedback. Can you have a look?
Try my fork
Same thing "Approve", "I'm sure" but nothing happens!
Approved some time ago
How the fucc Im supposed to split non-raw strings at escape-char in a goddamn python? This challange is a bad joke.
This comment has been hidden.
I was also confused when I first attempted this one with Python - the sequences of letters are separated by '\n' not '' or '\'. Hope this helps.
I raised this issue to see if I can edit Swift version from kata editor directly.
I think you can but the best it's to try. Need to put an issue for that or maybe I should let the issue?-)
I don't see the edit button, and when I do see it (from fork tab) and click it I get this:
That's why I created the issue, should I raise another one?
Did you solve the kata? I see it on this page and "Allow Contributors" is checked. Did you see it when you had put the issue? What do you want to do?
No, as I said, only from the fork tab and it doesn't work from there. I'm not listed in the kata Details either as a collaborator (maybe that's related). Should I create a bogus translation so I can edit the Swift translation? I'm trying to see if I can enable Swift 4. I'd prefer keeping an issue opened one week and check then.
I think that if you have not solved it in a given language you can't edit it. Solve first:-)
I have solved it in javascript, python and swift ;) Still, no Edit button :(
I don't know what to say... I wonder what posting an issue could bring. CW is mysterious! I tried with a few kata I have passed, some has an "Edit" button, some have not! Is it a bug to report at CW? By the way I am constantly logged off!
PS: did you try https://www.codewars.com/kata/56dbe0e313c2f63be4000b25/translations ?
This comment has been hidden.
I thought your fork would be the current translation too but it is not. First I would like you to try that:
Done (forked your translation again, as I can't edit), check it
Approved, thanks! When I first loaded the page it was your fork but when I have reloaded it it seems that it is still my old one:-(
This comment has been hidden.
I passed more than hour with "4.0" from your fork but I have had a real mess and many solutions were invalidated so I came back to my "3.1" version. I am sorry for your lost time (and mine too:-). I think we should keep "3.1" where it is since Swift is little backwards compatible; it is certainly for that that CW kept "3.1" and "4.0" side by side. Sooner or later we will have to modify for Swift "5.x" (November 16, 2018 (final branching) of Swift 5.0): Not for me:-) Anyway I thank you very much for your efforts to CW! Cheers.
PS1: if you try to fork again, note that the last function is "oper" and not "operArray". I didn't see that when I approved:-( PS2: CW is really in pain, now my "Solution" has disappered of the "Solutions" page!
No problem, at least we tried.
n is always even right? There's no mention of this in the instructions but it seems to be the case. even number of rows and columns
in C, I get this error:
Test Crashed Exit code: 0 Signal code: 6
on IDE, everything works fine.
Look at the top of the page: 115 guys passed the C kata; if there were problems someone would have seen them. I tried a few solutions and all worked fine. Look at your code and don't post issues unless you are very sure of your code (working on your IDE with some tests is not sufficient). Cheers.
they expect you to use malloc to reallocate string on the heap, there is free() in test.
So much kata don't support Swift 4
So much kata don't support Swift 4
I am getting the erroe " None should equal 'QHdgSh\noaMDnH\nXxNNlC\nHxxvRi\nAvVTqb\nuRySvw' ". but when I am running my code on my ide, I get perfect results.
You didn't write
oper
function properly orvert_mirror
doesn't return.This comment has been hidden.
oper
is not returning. And that if won't work.yes, I got that. Thanks!!!
This comment has been hidden.
"abcd\n" or "abcd\n\nefgh" are not squared (squared : string of n lines, each substring being n characters long. Re-read the description).
Ah I see. That makes sense, thanks!
Hi Folks, I'm new to Code Wars and trying to use it to practice some Swift. This feels like a great question so far! I'm having what feels like a basic issue where when I run my tests, I'm getting errors like "value of type 'String' has no member 'split'". I will admit to using a playground in Xcode to test my code. This seemed like a good idea... is it not? Is there some difference between the classes / packages available in a playground and the ones available in Code Wars? Is this all documented somewhere that someone can point me to? Sorry for the n00b questions!
You're using split like it can be used in Swift 4, and here Swift 3 is still used.
Ah, interesting that makes sense. Thanks for your help!
Ty for the kata. Was rly fun .
Thanks!
There's some kind of memory issue when running in C, i get this STDERR message quite randomly. I really don't think I'm the one responsible, because the sole memory handling operation I do is a simple malloc ("out = (char*) malloc(len*sizeof(char)+1);")
STDERR: *** Error in `/home/codewarrior/solution': free(): invalid next size (fast): 0x0000000000f7e850 ***
My code passed the sample tests but won't go through the actual attempt. It says "Time: 17ms Passed: 4 Failed: 1 Errors: 1".
My C solution passes all the first 60 tests, after the 61st I get the following message: *** Error in `/home/codewarrior/solution': free(): invalid next size (fast): 0x00000000023bc960 ***
Hi, I just want to say thank you for this kata! It was very enlighting to learn how to pass higher order functions in Java.
Thanks!
Objective-C Translation Kumited - please carefully review and approve :D
Approved (I know nothing in Objective-C:-). BTW can you approve this http://www.codewars.com/kumite/5a03059dc9fc0ee94b000081?sel=5a03059dc9fc0ee94b000081. The author is inactive since more than a month.
Many thanks for approving my translation; your translation has been approved in return :D
BTW would you mind approving these as well? I've tested all of them rigorously so there shouldn't be any issues, cheers :)
https://www.codewars.com/kumite/5a070d316975988929000030?sel=5a070d316975988929000030 https://www.codewars.com/kumite/5a07dd4b06d5b63fc800002d?sel=5a07dd4b06d5b63fc800002d https://www.codewars.com/kumite/5a07eb3b80171f7894000046?sel=5a07eb3b80171f7894000046
All approved: I trust you! Thanks for your approval of my translation:-) Have a good day!
Great Kata! Do you think it'd be possible to group your authored kata into collections of topics? I really like the idea of katas such as this one based on themes of increasing difficulty and it'd be nice to have them in a collection rather than scrolling through all of your authored katas each time.
Thanks!
It would be possible but when you go at the bottom of the "Detail" page you have "Similar Kata" where you find the others. Thanks for your post!
This comment has been hidden.
OP solved it, closing
ok I think theres something wrong in my code about the string sizes in the one function... debugging now! :D
This comment has been hidden.
OP solved it, closing
Im fairly sure I have a working solution for both simple functions for the mirror-functions. But I have absolutely no idea what exactly are higher order functions in C language?! Where should I go about learning more from higher order functions in C languge?
I was not taught about higher order functions in C in my basic C-programming course in university. Sorry for being a little bit shit, but this is really hard exercise for beginner level! :(
Maybe you could google "C high order function"?
underrated reply
OP solved it, closing
im doing this in C, but I would like to ask about a couple of things 1.) is it guaranteed that there will be no entersigns '\n' except in the limit between two substrings? 2.) what is the minimum inputstring letteramount that is going to be expected? 3.) I assume that the minimum allowed inputstring will be char string[3]="a\n"; where the letteramount==1 correct or false?
OP solved it, closing
I think this is quite hard exercise for beginner's level (7kyu)! I only did the verticalmirror function but I have no idea how to proceed
not sure if something has changed in the test code but I am printing out my answer to sample code, it matches the solution, but is still not passing the test.
This is the output.
Expected: equal to yeCt CSbg JVhv lVHt Actual: yeCt CSbg JVhv lVHt
look out for extra newlines or spaces which are not printed.
Hi, @g964! Tnx for the nice kata. Cheers!
Thanks for your encouragements!
FYI: There is an issue with tests. Method names vertMirror and horMirror are mixed.
I have implemented in C++, the code compiles, runs and the output is exactly the same... but the test and the submission fails... help?
I have the same problem.
are you guys able to do this without any prior knowledge of coding? if you are, how did you go about this? i'm at a total loss and could use some pointers.
have you written some code?
what is that mean : generic_func_t f . why the f in the end of the parameter . i built the programe but i can't run it here cause of this issue.
Google something like "C function as parameter". "generic_func_t" is the type of the parameter, "f" is the parameter name.
THANK YOU
Im getting this error:
Error in `/home/codewarrior/solution': munmap_chunk(): invalid pointer: 0x00007ffd60cf3820
I think there is some error in the tests! (maybe a free in a invalid position)
16 guys passed the C kata, not that many..., but I tried a few solutions and they worked fine. The tests don't have any "munmap_chunk()".
[C# Code] I don't know how to use this fct in Oper:
In the test cases it just says "testing(Opstrings.Oper(Opstrings.HorMirror, "lVHt\nJVhv\nCSbg\nyeCt"), "yeCt\nCSbg\nJVhv\nlVHt");"
What parameter do I have to use for ... fct?
EDIT: I now just completed it. For you who have the same problem: just google "(language) function as parameter"
[C++ newbie] I have problem with:
[ // your high order function oper //... oper(...); static string oper(..., const string &s); ]
I have no idea what it's for or what it is. Can someone please explain it to me or give me hints/sources about it. Thank you very much.
as you can see in the example
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm" oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
You have to implement function called
oper
in order to gain desired output.basically this func will call one of that (horizontal or vertical) functions over your input..
This comment has been hidden.
something like this:
int foo(std::function <int(int, int)> f, int a, int b) { return f(a, b); }
int main() { int x = foo([](int a, int b) {return a + b; }, 10, 20); cout<<x; }
example from stackowerflow. std::function(int <int, int>)
upd. sorry, it was codewars lag=) everything is ok now. thnx for kata!
This question does not understand what a horizontal or vertical mirror is. To demonstrate, open any picture in paint, click on "Rotate" and select "Flip Vertical". The image will now be upside down. That's what a vertical mirror is. This question's example of a vertical mirror, on the other hand, flips the text horizontally. Flipping "asdf" to "fdsa" is a horizontal mirror. A horizontal mirror flips over the y-axis, because it's inverting the x coordinates. A vertical mirror would be flipping over the x-axis, or doing what this question thinks is a horizontal mirror.
From http://physics.stackexchange.com/questions/8227/:
"All you have to do is imagine the line y=x+1 on the cartesian plane. If you reflect the line across a mirror in the vertical direction (across the y-axis), then the line becomes y=-x+1. Therefore, a vertical mirror flips the line's horizontal coordinates.
However, if you reflect the lines across a mirror is in the horizontal direction (across the x-axis), then the line becomes y=-x-1. A horizontal mirror flips the line's vertical coordinates."
In fact "Flip Vertical" flips as if you have a horizontal mirror and "Flip horizontal" flips as if you have a vertical mirror. The word following "Flip" refers to what happens to the image and not to the mirror. .
[JAVA] I have problem with(dots)
Can someone give me a hint or show me site where I can learn something about this?
The dots simply mean that you have something to complete (oper has functions as first parameter). You can google something like : "Java functions as parameter" or "Java unary, binary operators".
In "Java™ Platform, Standard Edition 8 API Specification" docs, search "uanry" or "function", it may help you a lot.
Same with Kotlin
using typescript return reference error - reference tags should be self closing
It is a known bug at CW. You write your TS translation correctly, you save it and CW modify the tags... I fixed it again and it seems to work. If not, please tell me.
Maybe i've been staring at this for too long, but for some reason the order of the elements keeps getting shifted. I've tried krsort() ksort() in an attempt to change the array row order prior to implode(). But nothing I do appears to change it.
I think there is no need to sort.
I'm using c++ for this kata and it works on my system as well as passes the sample tests here but during testing with random tests gives some output that is not expectecd. When I tested my code with one of the random tests on my system it resulted in expected output. but here it codewars it has some extra string before it .I don't know where they come from.
It seems that you often have problems with my katas:-) I just tried a few different solutions and they worked fine. Instead of posting an issue please give the failing test so I can see what happened.
Actually what is happening is like if the test is of 8 lines there are 8 extra lines coming from somewhere on top of my actual result. and total lines become 16. whereas on my system that extra lines are not present.
You should post the failing tests.
Expected: equal to OYlhXd
hJHhoq
dEnbrT
vxQAnm
ZpHZRG
BhIFDu
Actual: Extra part[IYoaOG DtkNzO
XXbxFi
mkauRi
wJjtKA
gzkuJz ]
Actual part [OYlhXd
hJHhoq
dEnbrT
vxQAnm
ZpHZRG
BhIFDu] These extra parts come with every test but are not the same. I mean are not like this extra part.
I think that it is your code which generates this extra strings. Did you print your result so that you can compare your "output" and "Actual"?
I have actually done it several times on my system and there is no such extra part. I guess there may be some problem with the test cases because i found that in one of the test the extra part was the solution of one of the fixed test.
I can't figure it out what is the problem.
I tried once more and had no problem. You should print your output on Codewars so you can compare it with actual.
how should i print my output on codewars. I didn't get your idea.
Use "cout" in your code. You should maybe learn a bit more about C++.
I know how print output in c++. But i thought u mean something else by saying "print your output on Codewars". By the way i've just learnt the essentials and i'm learning c++ standard lib and improving my skills with these challenges. I guess u r worn out with my questions so i wouldn't ask from now. Happy now?
No, I'm not worn out... not yet:-)
This is a great little kata for learning about helper functions, string and array manipulation!
Thanks!
Sorry for the stupid question, but I can't figure out what kind of syntax/call
method(:vert_mirror)
in the test cases is. I started Ruby some time ago, but I have not yet seen this kind of magic. -.-I tried
puts fct
, but the only output I get is#
and I don't know what to make from that. :/ I can't wrap my head around it, so a little hint would be really appreciated.Nevermind mates, stupid me figured it out myself. ;) One of the reasons I love Codewars (and code challenges), I always learn something new.
The initial Clojure solution doesn't contain namespace definition.
Fixed, thanks again!
This comment has been hidden.
Right! I thank you very much!