• The first solution that actually takes into account that no constraints have been placed on the numbers in the description. =)

  • This approach is still quite iterative because it uses an unnecessary indexing variable. To get a more "streamy" solution, use generate and limit like so:

    return Stream.generate(() -> "codewars").limit(1000).toArray(String[]::new);

  • Thanks for your translation! Very well followed the original... Nice job.

  • I've added a new java translation for review.

  • Thanks... Recognizable! I also had to change my direction several times until I could solve.

  • This comment is hidden because it contains spoiler information about the solution

  • Fun and challenging kata! can't wait to try the 6x6

  • @OzzyD Thanks Ozzy. I have actually modeled this problem after my own garage door :-), which can harm pets both ways. I will try to add the double-press improvement, but my intent is to keep the problem description as simple as possible. Cheers!

  • Thanks;-)! Probably time for holidays... :-) (after completing #4000;-))

  • Congrats !
    ; ) )

  • I'd suggest obstacle detection should only occur when closing.
    If the door is opening it wouldn't matter; in this case if opening and an obstacle occurs it'd start closing and squish a pet. - This sounds like the original problem the company probably wants to solve. ie When an obstacle is detected the door should begin opening if closing. If already opening and an obstacle is detected continue opening.

    An additional intersting additonal would be a double press of the button would reverse direction. And further to that a double press after obstacle would ignore any further obstacles until closed.

  • You can also replace this lambda

    size -> new String[size]
    

    by a method reference

    String[]::new
    
  • Yeah I tried submitting my solution in 'Train' mode and had the same issue (no issue when validating in kata creation mode). I ended up setting a package for all of the classes (test classes and initial code template) which seems to have fixed the issue. Try setting the package org.codewars.kata.dynamicjava for your solution and custom tests and see if that fixes it.

    I changed all of the package names in the code to be compiled in the test cases to org.codewars.kata.dynamicjava as well but playing around a bit with the custom test cases in 'Train' mode no matter what I tried setting the package names to in the code to be compiled it didn't seem to cause any errors. I think the problem only occurs if the test class or solution class uses the default package and you try to load a class with a non-default package name. And this problem only seems to occur in 'Train' mode.

  • Yeah seems to be something with CodeWars. If I put a package on the unit tests it gets 'stuck' in that package even after removing it.
    For some reason for submitting, if the solution is not in a package it returns;

    Could not find ["my.project.CompilerTest" #<Kind CLASS>] among possibilities: (["CompilerTest" #<Kind CLASS>] 
    

    And when in the package it returns

    /my/project/CompilerTest.java:14: error: cannot find symbol
    Class testClass = DynamicCompiler.compileAndLoad(name,
    ^
    symbol: variable DynamicCompiler
    location: class CompilerTest
    /my/project/CompilerTest.java:31: error: cannot find symbol
    

    Giving an empty class also has the submit report the /my/project path for CompilerTest, seems it's stuck running the test cases out of a different directory.

    Edit: It seems the package stickign only occurs on this kata for me. Tried on another with putting the test cases into a package and all was fine after removing it.
    There was another comment on the forum about this kata and someone else having the same issue.

  • The CompilerTest class does not have a package specified. The my.project package however is used for all of the classes that the test cases try to compile. So for example you might get a call like

    DynamicCompiler.compileAndLoad("my.project.Something", "package my.project; public class Something {}");
    

    Perhaps that is related to the problem you are experincing? Or perhaps there is some issue with the CodeWars website because my reference solution works without those errors.

  • Loading more items...