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.
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
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.
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
mad respect for solving this with Linq only. Without any knowledge of IpAdress class. You are sick man :D
Showed this to my colleagues we were very impressed
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
In the C# unit tests that the kata provides one of the tests will cause errors which are not my fault. The test is simply missing the parenthesis from invoking the method PageCount(). It is used like a property but was supposed to be a method. itemscount was supposed to be a property but PageCount was not.
Thats why my code will always crash with an error and a line reference in that unit test saying I would use a method group like an object.
In my code editor I run all the tests perfectly fine. Its really just the parenthesis missing for invoking the method in one of the Asserts.
Please fix
This comment is hidden because it contains spoiler information about the solution
The error's line reference is also kinda suspect because it refers to a line where I barely have any code and definetly no method group being used as an Object. Could this be a problem with the compiler, runtime or stuff like that?
Loading more items...