Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
10.0.0.0 is not a valid address, it is a network address.
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
or cast to BigInteger. (BigInteger) Math.Pow() is the same as BigInteger.Pow()
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.
the cast to int is not necessary
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.
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.
nesting ternary is not bad practice. Nesting Ternary without using parantheses to increase readability is bad practice.
This comment is hidden because it contains spoiler information about the solution
The first is inclusive, and the last is exclusive.
Description: "including the first one, excluding the last one"
So it's 50
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.
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.
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.
From description:
So 0 counts, but 50 doesn't. 50 addresses seems correct.
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.
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...