Ad
  • Default User Avatar

    10.0.0.0 is not a valid address, it is a network address.

  • Default User Avatar

    small optimization in terms of avoiding code repetition: instead of incrementing the count variable in both the if part and the else part you could do it before or after the if statement, just once

  • Default User Avatar

    or cast to BigInteger. (BigInteger) Math.Pow() is the same as BigInteger.Pow()

  • Default User Avatar

    Most likely because whoever wrote this didn't realize it can be solved in O(1). Or because this kata is listed in the section "LINQ excercises" so the author tried to solve it using System.Linq library. I don't think it can be solved in O(1) using language integrated query.

  • Default User Avatar

    the cast to int is not necessary

  • Default User Avatar

    While using a stack for this is clever it's actually bad practice because it increases the space complexity of the function. A simple integer getting incremented or decremented is enough for this problem, no need for stack.

  • Default User Avatar

    this is bad practice, instead of using multiple if, use else if. else if only checks the other conditions if the first one resolved to false, yours will always be checked in any case. Also the last if should be moved inside the scope of second if to only check it if the current parenthesis is a closing parenthesis.

  • Default User Avatar

    nesting ternary is not bad practice. Nesting Ternary without using parantheses to increase readability is bad practice.

  • Default User Avatar

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

  • Default User Avatar

    The first is inclusive, and the last is exclusive.
    Description: "including the first one, excluding the last one"
    So it's 50

  • Default User Avatar

    Looking at your function I would expect the result to be ending with a whitespace, what Am I missing here? You join every line with an ending line switch, also the last line where we dont want a line switch anymore right?
    So I would expect line 10 to have an ending line switch in your solution but there is none. Thats so confusing to me. I personally didnt use the -join option but used a different approach and there I had to use an if statement to see if its the last line, to only add a line switch when its not the last line. Or I could simply remove the last one with the Replace method but its so weird to me that you dont have to do any of that here. Why does the output from your solution NOT have a line switch after line 10??? someone please explain

    Edit: I just found out how it works. For those who struggle understanding this solution: Google how the join method actually works in the background. Cuz I thought it would append every line but it does not. Its rather defining a seperator for the join. So the line switch only occurs in between two lines.

  • Default User Avatar

    Thanks for the complements! I actually use the IPAddress class for work fairly regularly. Codewars is where I tend to write rediculous one liner linq answers just for fun.

    Just one thing: when I cast your method on start = "10.0.0.0" and end = "10.0.0.50" it returns 50 but should be 51. From 0 to 50 you have 51 adresses to choose ;) so just add 1 to it somehow

    The Kata description says "returns the number of addresses between them (including the first one, excluding the last one)"
    That is why 50 is the correct answer.

  • Custom User Avatar

    From description:

    (including the first one, excluding the last one).

    So 0 counts, but 50 doesn't. 50 addresses seems correct.

  • Default User Avatar

    The first Assert in the kata is not correct tho, correct me if I'm wrong. It Asserts there are 50 ip addresses in the given range but there are 51 actually. Whoever wrote this Assert just calculated the difference but its actually always the difference + 1 , because you count the 0 too. Somehow it does not matter if your solution returns 50 or 51 here, it will both be accepted as a correct solution. Is that a bug or a feature? :D I saw submits return 51 here while mine returning 50 here was also accepted.

  • Default User Avatar

    The Assert expects 50 as result for the first Difference but should be 51.

    Since from 10.0.0.0 to 10.0.0.50 you have 51 adresses, not 50. You can choose the zero as well

  • Loading more items...