These are chat archives for Codewars/codewars.com/kata-solving-help

22nd
Dec 2016
EK
@docgunthrop
Dec 22 2016 06:04
if anyone has solved http://www.codewars.com/kata/diffuse-the-bomb , I'm curious about the process of figuring it out. I'm not asking for help on the solution (I've already forfeited the honor points), but I'm fascinated by the thought process for finding the solutions.
Natacha Beck
@natacha-beck
Dec 22 2016 06:05
Ahah I am stuck at step 1 !
but I least I get the first answer.
EK
@docgunthrop
Dec 22 2016 06:06
yeah, I was able to defuse the first bomb, but got stuck after that
Natacha Beck
@natacha-beck
Dec 22 2016 06:07
you need to inspect all available objects as far as I understand to know what happens, but hmm I am puzzled by this one
but not ready to forfeit on my side I will go back to this one later....
EK
@docgunthrop
Dec 22 2016 06:07
I'm seeing some really clever solutions, but also solutions that seem almost impossible to figure out without being clairvoyance
*clairvoyant
I think the best approach is getting a clever solution rather than trying to go full Sherlock Holmes with it.
Natacha Beck
@natacha-beck
Dec 22 2016 06:11
hmm I like the hint... so I guess some people do not 'really' solved all the bomb ?
EK
@docgunthrop
Dec 22 2016 20:38
yes, for that kata there are definitely some 'hackable' approaches
Natacha Beck
@natacha-beck
Dec 22 2016 20:38
Hmmm :( I haven't found this one !
Dec 22 2016 20:41
hi everybody
I have a question about a kata'
and this is my soloution
def spacify(str)
new_str = String.new
str.each_char { |x| new_str << "#{x} " unless x == " "}
return new_str.chop
end
but the test results are failed
is my solution is wrong???
Giacomo Sorbi
@GiacomoSorbi
Dec 22 2016 20:47
yes
Dec 22 2016 20:48
why?
Giacomo Sorbi
@GiacomoSorbi
Dec 22 2016 20:48
does it pass?
Dec 22 2016 20:48
no
Giacomo Sorbi
@GiacomoSorbi
Dec 22 2016 20:56
so you might guess that is indeed wrong
Dec 22 2016 20:59
Ok. i know that's wrog. but why?
Giacomo Sorbi
@GiacomoSorbi
Dec 22 2016 21:02
shouldn't you get a message telling you which cases you fail?
Dec 22 2016 21:03
@GiacomoSorbi Test Results:
✘ Expected: "h e l l o w o r l d", instead got: "h e l l o w o r l d"
Giacomo Sorbi
@GiacomoSorbi
Dec 22 2016 21:06
because it does not print correctly the spaces, but I would assume you did not put an extra one where needed; what happens then to your last character?
Dec 22 2016 21:08
the last character shouldn't has a space
✘ Expected: "h e l l o w o r l d", instead got: "h e l l o w o r l d" but itexactly the same
Giacomo Sorbi
@GiacomoSorbi
Dec 22 2016 21:23
as I mentioned, the printed display in CW is not reliable, as it can remove extra spaces
Dec 22 2016 21:28
so, where is my mistake?
Giacomo Sorbi
@GiacomoSorbi
Dec 22 2016 21:37
I think I already said that
Dec 22 2016 21:37
ok thank you
Giacomo Sorbi
@GiacomoSorbi
Dec 22 2016 21:38
what happens then to your last character?
Dec 22 2016 21:39
I removed the space from last char with chop method
Giacomo Sorbi
@GiacomoSorbi
Dec 22 2016 21:52
oh, right, missed that; what happens when you get a space, instead?
Dec 22 2016 21:53
@GiacomoSorbi str.each_char { |x| new_str << "#{x} " unless x == " "}
Giacomo Sorbi
@GiacomoSorbi
Dec 22 2016 21:54
so you do NOT add a space, do you?
[using git flavored markdown might help readability here]
Dec 22 2016 21:55
"#{x} "
there is a space after }
Giacomo Sorbi
@GiacomoSorbi
Dec 22 2016 21:56
I mean a single space: when `x==" "`
Dec 22 2016 21:56
x == " " yes there is a sigle space
Giacomo Sorbi
@GiacomoSorbi
Dec 22 2016 21:57
what do you do when `x==" "`? That is what I am asking...
Dec 22 2016 21:58
I put a single space after each character unless that char is a space
It's clear on my code
Giacomo Sorbi
@GiacomoSorbi
Dec 22 2016 21:58
the point is that you should put the character itself when it is a space
[it would be also much efficient to store them into an array and not adding to a string at each loop, but ok]