7 kyu

[Code Golf] Number Pyramid Series 1 - Sum of Corners

Description
Loading description...
Mathematics
Restricted
  • Please sign in or sign up to leave a comment.
  • MikalaiLappo Avatar

    It looks easy when it's solved, but I've spent quite some time stuck at 36-37 chars solutions. With <36 chars it's probably a 6kyu

  • samulik Avatar

    Am I correct in assuming that the code needs to start "def sum_corners(n):return " leaving just 9 characters for the code or the formula?

    • hobovsky Avatar

      No, this is not correct. You can squeeze out 4 characters more.

    • LanXnHn Avatar

      This is one of the basic Python golfing trick, you can find it on Internet quite easily.

    • samulik Avatar

      Thanks for the Kata, finally got it. I didn't realize that we are allowed to alter the function definitions here at Codewars. I also think that this was a bit tough for 7 kyu, needed pen and paper + needed to learn new ways of writing python for this one, usually 7 kyu are pretty much tutorial stuff.

  • Bivvercode Avatar

    This comment has been hidden.

  • kuddusi98 Avatar

    i should learn that lambda thing

    • LanXnHn Avatar

      Well, you can definitely google and learn it.

      You can found many websites about it, then come back to continue golfing!

      Enjoy your learning.

  • oldcoder Avatar

    good kata ,I enjoyed. thx

  • JohanWiltink Avatar

    I would strongly suggest having a one character function name. Every additional character comes off the code size limit, so the limit could be 30 instead of 40 without changing the difficulty of the task. The golfing task ( generous as 40 is! ) is not a 40, it's a 30.

    • dfhwze Avatar

      A long method name adds something special (sadistic) to a code golfing exercise. I would keep it. I would like to see the limit lowered to 35 though. Makes it hard enough, but still allows for a varity of solutions.

    • LanXnHn Avatar

      Length limit was changed to 35 as mentioned below.

      Regarding the name of the function, I will leave this suggestion open and see if there is an agreement to change the name.

      Will change/remain it accordingly.

  • benjaminzwhite Avatar

    Cool kata, fellow code golf fan :) by the way I think the accepted title format is to include [Code Golf] - I get dozens of hits when I search with that title tag, whereas I get 0 when I search for [Golfing]

    Also - I'm not sure what the Codewars consensus is because I'm waiting for my first golf kata to get approved - maybe the char limit is currently a bit generous at 40? My first unoptimized solution passed with 36 - I guess it depends what difficulty you are aiming for?

    • Kacarott Avatar

      I agree, my very first attempt was easily short enough. I would suggest bringing it down to at least 35.

    • hobovsky Avatar

      I think that now when kata tags are finally getting cleaned up, tags in titles become redundant (unless it's a golfed version of another kata).
      Just search for restricted and you should find only code golf and similar.

    • JohanWiltink Avatar

      If even I can solve it, it's probably too easy.

      Figuring out the formula is harder than golfing it right now.

    • LanXnHn Avatar

      With the suggestion, I updated it to 35.

      If there is something still need to be improved, please let me know.

    • LanXnHn Avatar
      Suggestion marked resolved by LanXnHn 3 years ago
    • Fuzzi Avatar

      35 is too hard for 7 kyu. It took quite some time to figure out the shortest formula and then I can't get below 36 :-/

    • Fuzzi Avatar

      This comment has been hidden.

    • Kacarott Avatar

      There is one quite easy way for you to get down to 35, one of your math operations can be slightly rewritten.

    • Fuzzi Avatar

      Haha ok thank you I got it. But still it's quite hard for 7 kyu. I'm excited to see the other solutions. /edit Ok if you got some experience in code golfing it looks much easier.

    • benjaminzwhite Avatar

      @Fuzzi - now try the other ones in @LanXnHn 's Number Pyramid series, they are all great!

    • LanXnHn Avatar

      Well, I will get more opinion before changing the length limit.

      This was approved Kata and I want to have the minimum amount of modifying.

  • hobovsky Avatar

    restrictions tag should be added.

  • hobovsky Avatar

    Description: "The lenght of your code should be less or equal to 40."

    Sample tests:

    Sample Tests
      Code Length Test
        Your code is too long: 40 should be less than 36.