Ad
  • Custom User Avatar

    This task is not only interesting one, but also this seria's katas are practically useful.

    Thank you.

  • Default User Avatar

    It seems the test cases in the Swift version of this Kata has errors:

    main.swift:25:74: error: module 'test' has no member named '0'
                  ("Some Common Resistor Value Tests", commonValueTests, "Testing with \(test.0)"),
                                                                                         ^~~~ ~
    main.swift:35:26: error: cannot convert value of type '[(String, (ExampleTest) -> () -> (), String)]' to expected argument type '[(String, (XCTestCase) -> () -> Void)]'
      testCase(ExampleTest.allTests)
                           ^
    main.swift:35:26: note: arguments to generic parameter 'Element' ('(String, (ExampleTest) -> () -> (), String)' and '(String, (XCTestCase) -> () -> Void)') are expected to be equal
      testCase(ExampleTest.allTests)
                           ^  
    

    I've tested my code against all the test cases and I get the correct results:

    let commonResistorValues = [
      	("10 ohms", "brown black black gold"),
      	("47 ohms", "yellow violet black gold"),
      	("100 ohms", "brown black brown gold"),
      	("220 ohms", "red red brown gold"),
      	("330 ohms", "orange orange brown gold"),
      	("470 ohms", "yellow violet brown gold"),
      	("680 ohms", "blue gray brown gold"),
      	("1k ohms", "brown black red gold"),
      	("4.7k ohms", "yellow violet red gold"),
      	("10k ohms", "brown black orange gold"),
      	("22k ohms", "red red orange gold"),
      	("47k ohms", "yellow violet orange gold"),
      	("100k ohms", "brown black yellow gold"),
      	("330k ohms", "orange orange yellow gold"),
      	("1M ohms", "brown black green gold"),
      	("2M ohms", "red black green gold")
      ]
    for test in commonResistorValues {
      print (encodeResistorColors(test.0) == test.1)
    }
    

    All test print true!! Can someone please sort this out?

  • Default User Avatar

    Yup, you got that right.

  • Default User Avatar

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

  • Default User Avatar

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

  • Default User Avatar

    Thanks, that's clear now - still got bugs but getting closer to solution!!

  • Custom User Avatar

    The Lift never changes direction until there are no more people wanting to get on/off in the direction it is already travelling

    Lift was going up...

    Person at floor 6 wants to go up... keep going up.

    IIRC the empty lift rule applies only when that rule can't.

  • Default User Avatar

    Really excellent and challenging kata!

    I am, however, stuck on what seems to me to be a conflict between 2 of the lift rules:

    The Lift never changes direction until there are no more people wanting to get on/off in the direction it is already travelling
    
    When empty the Lift tries to be smart. For example,
       If it was going up then it may continue up to collect the highest floor person wanting to go down
       If it was going down then it may continue down to collect the lowest floor person wanting to go up
    

    For example: lift is going up and discharges all passenger at floor 3. There are 2 people waiting at higher floors say, 1 at floor 6 wanting to go to floor 10 and 1 at floor 9 wanting to go to floor 5.

    Does it

    a) follow the empty lift rule and go straight to floor 9, then to floor 5 and then to 6 for passenger going to floor 10? 
    

    or

    b) continue up, stop at 6 for 1 passenger, take him to floor 10 then come back to floor 9 to take final passenger to floor 5?
    

    Option b) seems the more logical but appears to conflict with the empty lift rule. I'm probably just being dense, but would really appreciate some clarification.

  • Default User Avatar

    That is exactly right. Your brain defrags overnight, providing clarity and answers when you awake.

  • Default User Avatar

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

  • Default User Avatar

    Phew!!!! Had to ressurect some defunct brain cells to get this one done - quite tricky for non-mathematicians!!

  • Default User Avatar

    Would be helpful if the description gave the range of test cases the code was expected to pass!! Particularly since one of the test cases contained an invalid string in the input - what should be the expected behaviour for this case? Assume zero or raise exception?

  • Default User Avatar

    @evanmdort - nothing wrong with your thought process coordinates of the corners of the rotated rectangle are [0.707,3.53],[-3.53,-0.707],[-0,707,-3.53],[3.53,0.707]. Neither the picture nor your thought process is wrong, the problem must be in your computation of the integer coordinates contained in the rotated rectangle. What is your algorithm for finding these points?

  • Default User Avatar
  • Default User Avatar

    Really enjoyed this Kata - kudos to author!! Expresion trees are something I've never really understood in the past; writing a solution to this challenge has taught me how they work. Got a bit caught out by unary '-' which I assumed would always precede a numeric literal - WRONG!!

  • Loading more items...