Ad
  • Custom User Avatar

    python new test framework is required. updated in this fork

  • Custom User Avatar

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

  • Custom User Avatar

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

  • Custom User Avatar

    Hi @Rockkley.

    Lambdas are anonymous callable objects. If you want call it later, you must use a variable, no other choice to do that. And here (in codewars) if there no name, unit test cannot check the solution.

    For your information, in python, a def (and so, a fonction) defined like that create a variable:

    def foobar(): pass
    

    The variable created is foobar, the proof, you can do that:

    def foobar(): pass
    foobar = 1234
    

    It's the aim of the mechanism under the concept of decorators.

    If you prefer i can use these solutions instead of lambda, the solution will be acepted:

    # Common accepted solution
    def check(s, e): return e in s
    
    # Another solution
    def singleton(c): return c()
    @singleton
    class check:
      def __call__(self, s, e):
        return e in s
    
  • Custom User Avatar

    I know that lambda is anonymous function, and there's no need to create variable for lambda, but here we need to meet the interface requirements. Requirement here is that check is callable.

    In real world I would not create function for this one liner, that's why I'm showing solution with lambda.

  • Default User Avatar

    variable "check" holds the function. and ambda describes the oneliner function.

    mult = lambda a,b:a*b

    is the same as

    def mult(a,b):
    return a*b

  • Custom User Avatar

    What do you mean? Do you know how lambdas work? Do you know you can copy the code and make trials on your own to understand how it works? On your own computer, or just here, by clicking on Forkjust below any solution.

  • Custom User Avatar

    Why creating a variable for lambda?

  • Default User Avatar

    Good Kata for what it wants to do. Minor suggestions for the description:

    • Your job is to write a class 'Walker()'

      Just write 'Walker', maybe emphasize it.

    • This class should have a couple of methods:

      "This class should have two methods:". This is a specification, let's be precise :)

    The following list could use some clean-up: Why precede each method with a number? There should be 2 list items, one for each method, with the description below at matching indentation.

    • walk(string):

      a method that takes a string of directions for Mr. Strolly to walk as input (this hasn't happened yet, why past tense?)

    • coords():

      a method that returns Mr. Strolly's position relative to his house*

    * Instead of pre-populating the __init__ method, you could specify that Mr. Strolly's initial position is his house at (0,0).

  • Custom User Avatar

    Please use new python test framework.

  • Default User Avatar

    I modified the description to clarify that Mr. Strolly only takes one walk per day.

    A class keeps state between walks. If there is only one walk, a function is better than a class.
    Using a class only to split a function into three is bad practice.

  • Custom User Avatar

    Agreed. Doing it in C is actually not that easy, too. The string handling isn't super involved but definitely worth more than 8 kyu. It is so unfortunate that it isn't possible to have different difficulty rankings for different languages. Sometimes the tooling makes all the difference between a Kata being super easy or actually quite hard.

  • Custom User Avatar

    Except that this is a ver bad example. If you want to make a kata about how to write classes (which, btw, there are always many such katas so your would be a duplicate) you need a better situation where doing so would make sense. As it currently stands it really doesn't.

  • Default User Avatar

    Matrices don't have up and down. There are all kinds of coordinate systems in programming. Downwards Y is used in 2D quite often, but for instance PDF has Y pointing upwards. In 3D graphics Y seems to point upwards in most cases both in right- and left-handed coordinate systems. In math right-handed systems are usually used, although it looks like left-handed systems are used in other areas too.
    Note that downwards Y in 2D probably comes from analog TV scanning direction or from writing direction, so it's mostly associated with screen coordinates.

  • Custom User Avatar

    That depends on the coordinate system orientation, although Y axis is generally facing downwards in programming (row number in matrices, offset in GUI etc.).

  • Loading more items...