Ad
  • Custom User Avatar

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

  • Custom User Avatar

    Lol I read "sum of the cube of the digits is divisble by 2" and I knew I'd skip that immediatly, probably not too hard but I dropped out of school for a reason ahah

  • Custom User Avatar
  • Custom User Avatar

    and having a function nested inside another doesn't mean you can call it, you can only call it if that function is returned, same as how you can't be aware of some integer unless that integer is returned

    Yes this most likely crossed my "Note: ..." edit where i do specify that the inner function is called by the return statement of the outer function, not by mere fact of having the outer function called with multiple parentheses set.

    So ... func(1)(2)(3) passes the args 1, 2, 3 to the three functions ... yeah ...

    This is misleading because it implies the call of inner functions and the passing of arguments is happening solely due to the func(1)(2)(3) statement.

  • Custom User Avatar

    Ok so I've found a satisfactory answer here : https://stackoverflow.com/questions/42874825/python-functions-with-multiple-parameter-brackets

    I'm a bit ashamed it's that simple, but basically you can pass arguments to inners functions by calling the outer function with two or more sets of parentheses.

    In python (sorry, did not specify language earlier...) you could do:

    def func1(a):
        def func2(b):
            def func3(c):
                return a + b + c
            return func3
        return func2
    
    print(func1(1)(2)(3))
    

    Outputs: 6

    So ... func(1)(2)(3) passes the args 1, 2, 3 to the three functions ... yeah ... (edit: misleading statement, see note below)

    Note : don't forget to return the inner functions ! It feels a bit weird, but keep in mind that func1 returns func2 which actually calls func2 right away. It's weird (to me) because in this case the verb "return" is insdiguishable from the verb "call". So, right when func2 gets called (or returned, same thing!), it looks for arguments (in the example provided, it's (b)which will take the value 2, and the arguments are provided with the call func1(1)(2)(3).

  • Custom User Avatar

    Ok then I must interpret the input in some erronous way. But if I do:

    def chained(functions):
      # solution code's function
    
    def f1():
      print("this is f1")
    
    def f2():
      print("this is f2")
      
    def f3():
      print("this is f3")
    
    chained([f1,f2,f3])(0)
    

    I get the output: TypeError: 'NoneType' object is not callable.

    At first I interpeted it (...any interpreation in code is wrong ik, but begginners always will somehow...) as "you cannot call the integer 0 as it is a NoneType object and those cant get called."

    But actually, NoneType refers to the returned value in my defined functions which indeed do not return anything, which is equivalent to returning None.
    If I change my functions to return say, a string, then the error is updated to: TypeError: 'str' object is not callable.

    You don't have to answer this, I'm sure I can find answers on Google, but the question is now: so the (0) here is some kind of parameter that gets passed to all functions ? the first function ? the latter one ? not that at all ? And why is it called input (and not say, args) ?

    Edit: sorry for 99 edits, learning markdowns and I'm a typo minigun. Also thanks for the reply it helped me unstick my line of thinking <3

  • Custom User Avatar

    Can someone explain why this kata description seems, to me, like it could just have been:
    Your function should look like that: "some valid function call with example arguments"...
    And you should output something like this: "some output related to the example given"...
    Why oh god why is this "Function(args)(input)" abomination standing here and no one seems to mind ... ? There's something I must not get. A Function(args)(input) call is not valid syntax.

  • Custom User Avatar
  • Custom User Avatar

    Why is this considered as a spoiler ? I even wrote this before having passed the test or even submitted a solution if I remember correctly ...

  • Custom User Avatar

    Yup agreed. I've now went through katas that make this one's description look pristine. I think just typical absolute beginner's frustration showed here. As someone who has to work for multiple hours to understand how extremly simple methods work, having to make the connection between a given string list and an imaginary "new line" in a text editor can make this very confusing.

    Trying to shortcut the problem's logic as to avoid truly getting it was my approach tbh.

    I hope this can help others not get trapped the same way, or not for too long.

  • Custom User Avatar

    For those not understanding the awfully written example and description :

    This kata is about the odd and even index numbers of a string. Example: "hello max" = 012345678

    Our index numbers are "hello" = 01234, " " = 5 and "max" = 678

    Take the even index numbers 0_2_4_6_8 = "hlomx". Then the odd index numbers. 1_3_5_7 = "el a".

    Join the two new strings you've created. The odd string goes first. Result: "el a" + "hlomx" = "el ahlomx".

    Repeat with "el ahlomx" = 012345678 and so on ...

  • Custom User Avatar

    I have absolutely no clue what I'm supposed to do ? Exceptionally unclear kata ... Idk if I have to return something different if the input isnt regular (a to Z) characters ? Some guy in discussion mentioned that apparently "abca" is supposed to output "1234" and not "1231" ... what !???? Skipping this one ...