Ad
  • Custom User Avatar

    7 lines is not bad. Honestly I'll defend my 4 line solution as being a better practice because it's more legible to other people, even if it isn't as clever as this one. And this one is clever! I'm not here to be a hater. I just get frustrated when people mistake "shortest" for "best." Imagine if one of your coworkers wrote this code, went on vacation, the code broke, and then you had to debug it. I don't think it would result in great professional cohesion.

  • Custom User Avatar

    Totally agree. I love when solutions are short and clever, and if I could FOR THE LIFE OF ME figure out what the heck is going on here, I might use it for personal things. But professionally, your code is going to be passed along to other people. It just is. Being a smirking know-it-all about how you're better at math than everyone else (which is not what I think the person who posted the solution is doing, but certain other people in the vicinity sure are!) is only going to make your coworkers hate you and the work more cumbersome. If the micromilliseconds that a solution like this shaves off actually matter, then that will be part of the stated requirements. Otherwise, it's counterproductive to do something confusing.

    Imagine this: you write some indecipherable code and then go on vacation. Something else in the project changes, causing your code to no longer work*, but no one except you understands what you wrote well enough to debug it. When you get back from vacation, they're not going to think you're a genius. They're going to think you're a jerk. (Which is to say nothing of the probability that you also won't understand it once you haven't looked at it in a while!)

    * I find it really interesting how many people think that "shave off imperceptible amounts of time" is a omnipresent, implicit requirement, but "harden your code against foreseeable weak spots" is a low priority that can be handled later. When they also think that "make it legible to other people" is a low priority, I really have to wonder what it is we're actually even doing here.

    (All that said, the solution is, best I can tell, really clever! There's nothing wrong with someone having created or posted it - the opposite of wrong, that's fantastic! I am about to spend a lot of time on google and probably learn something! It's amazing how the human mind can weave different concepts and understandings together to come up with something really elegant! For the actual purpose of this website - practice - this is a great answer. But you are completely correct that it would not be best practice in a professional setting, and it makes me nuts when people just say "well maybe other people should just know all the things I know!" rather than engaging with practical limitations and basic interpersonal realities.

  • Custom User Avatar

    Oh that's clever though! You figured out a way to get it done!

  • Custom User Avatar
  • Custom User Avatar

    ...Yes???? Yes, a whole bunch of 1s absolutely is a valid answer??? 1x1 is a square. If length x width = a, then a 1x1 squares will completely cover the rectangle. And sure, "figuring out how to ["]properly["] cut it" COULD "be part of the task", but my point is that it's not currently specified that it is. Again, the fix is simple. The instructions currently read "to cut a given "true" rectangle into squares." The only change that would be necessary is to add "the fewest necessary," so it reads, "to cut a given "true" rectangle into the fewest necessary squares." Three words! Three words, and then the instructions will actually say what they evidently meant to say (given that other, yes, perfectly valid, answers aren't accepted).

    If it's a puzzle, then why are you so averse to a clever solution? I think it's like the riddle - "I have two coins that add up to 30 cents, and one of them isn't a nickel. What are they?" You could go crazy trying to find some historical coin worth 29 cents or whatever, or you could say, "Yeah, one of them's not a nickel - the other one is!" Just because it's easy doesn't mean it's not clever.

    If you imagine a scenario where you had to do this for real, what kind of solution would you want? Like, if you worked for a concrete company and needed to know how many gallons (gallons? I don't know what units are used for concrete) of concrete were needed for a a driveway of A x Y proportions, and the guidelines specify gallons per square area. Sure, you could cut up the driveway like they did in the diagram and calculate it for all those different squares, but it would require using a loop and all that. My solution is one line of code. It's more efficient, and gets the same job done. Isn't that usually better?

  • Custom User Avatar

    Hey! There's no need to be snarky or condescending. The drawing literally says it's "an idea" of how to do it. My point stands. It doesn't say that it has to be those exact squares, and indeed, it wouldn't make any sense to say that, given that the tests are to sub in different dimensions. To my reading, the most important phrase is, "how to cut a given "true" rectangle into squares". Maybe you disagree, but that's exactly the point I was trying to make - it's ambiguous enough that multiple answers are justifiable, and yet only one is accepted. And since one of the main things about codewars seems to be creativity and cleverness, it sure seems to me like my solution should be a valid answer! It's an out-of-the-box way of doing it! And really, what kind of coding exercise is it if it's so averse to a literal reading? Isn't one of the most important skills in coding to be able to write instructions tight enough to exclude any answers you don't actually want? It seems to me that if you're writing a script and it's giving you an answer you don't like, then the problem is that you didn't write the script well enough for what you want it to do. You can't get mad at the computer for executing it literally. So don't get snippy with me, either.

  • Custom User Avatar

    In my opinion, if the purpose of this kata is to produce a list of the dimensions of the fewest squares needed to fill the rectangle, then it should say so. (5, 3) -> [3, 2, 1, 1] is an example of the fewest squares. There are four squares there, and it's not possible to cover the whole area with only 2 or 3 squares. However, the instructions don't specify that you have to generate the fewest squares, just that you have to generate squares. So I did what I thought was the fastest, simplest, most obvious thing:

    x = length * width (in this case, x=15)
    answer = a list of 15 1s.

    It works! It answers the question! 1x1 is a square, and 15 of them will indeed cover a 3x5 rectangle! But it didn't pass the tests. I'd say you should either accept answers like mine, or edit the instructions to clarify what you want.