Ad
  • Custom User Avatar

    Wow I wrote that comment three years ago, surprised to see a reply now. I learned to write it like that from my high school CS teacher, but generally speaking string addition with "+" is bad practice since it is space inefficient (Strings are immutable, so it creates a new string every time you add). It seems to be fine in this case, however, Character.toString(c) may be considered best practice. String.valueOf(c) should likely work as well.

  • Custom User Avatar

    Sorry for the late reply. So the empty string before I put the line number tells java that this is String addition. In this case, I am not sure it is necessary beacause I am adding another String right after. Also, I made this a long time ago, so this is not good coding practice at all. String addition is generally bad practice because it takes up extra memory (Strings are immutable).

    Just to answer your question more clearly:

    (5) is an int

    ("" + 5) is a String

    For clarity, String.valueOf(5) is probably better.

  • Custom User Avatar

    Yes, I believe that c + "" would also result in a String and the code should run just fine. As for why I wrote it as "" + c is that it is more explicit in showing that I am appending a character onto a string. I guess it is also better practice because that was how I was taught to do it. :)

  • Custom User Avatar

    I am pretty sure only the first person who makes a particular solution gets honor for upvotes.

  • Custom User Avatar

    Thank you for the compliments.

    Most programming competitions are aimed for high school coders, so it will be hard for college students to start; however, there are still many local competitions that occur everywhere, so that is a good place to start. Ironically, my coding teacher told me to start practicing for competitions by using this site beacuse the questions here come out of competitions and job interviews sometimes.

    I admire students with jobs. Having many friends in the college I will go to, I understand the time pressure. I wish you good luck with your programming!

  • Custom User Avatar

    I thought the same thing, but it ran in about the same time as the conventional code.

    The reason for this is than my code has two loops, but each loop only has one check, making it O(2N) like you said. However, the conventional code has one loop, but two checks in it. This makes it O(2N) as well. This code did run slightly faster, but that probably has to do with server load - not efficiency.

    To answer your question about the competitions, my team likes to have clean and clever code that looks better for judges. This takes more memory, but memory isn't much of a factor in the code's readability and use of convention. Run time is a factor though.

    Thank you for your feedback! :)

  • Custom User Avatar

    I understand that this code will have to be redone if there are any twists in the kata. However, I am training for programming competitions, and I am practicing optimization... Normally I would iterate through the string and count the x's and o's.
    :)

  • Custom User Avatar

    The formula takes a lot less time than recursion or loops for really big numbers as far as I know. Also, the formula only gives integer outputs for intger inputs (the coefficient on the sqrt(5) term always ends up as 0). I think ths formula is a lot more efficient, however there might be an accuracy issue due to the use of doubles, but I never experienced such problems.

  • Custom User Avatar

    mathforum.org/library/drmath/view/56926.html

    This is a good explanation of the formula I used. If it still does not make sense, just try searching "Sum of first n triangular numbers". There are a lot of good proofs be induction online.

  • Custom User Avatar

    In the description, we are given a sequence starting for 1, and we are looking for the missing number. Every single example case with an output other than 1 is in numeric order, so I assumed this kata was providing test cases in numeric order. I could have split the string and sorted it, but I did not feel the need. Hope this helps a little :).

    EDIT: "Each sequence always increments by 1"; That is why you don't need to sort.

  • Custom User Avatar

    I lost about 200 ranks originally, but by today it is only 100 ranks less than before the honor issue. I think everyone's ranks are still being corrected as more people lose their incorrect honor.

  • Custom User Avatar

    My honor went from 780 to 1430, but know it is back to 780 and all is good. However, I got an "ability" from 1000 and 1300 honor milestones. This should be revoked right?

  • Custom User Avatar

    "At least one letter character at the beginning"

  • Custom User Avatar

    That was a very good explanation :). I leared it as calling 'R' as right and 'D' as down. We have to go right a certain number of times and down a certain numeber of times, so a solution to "(2 3)(5 7)" could be 'RRRDDDD'. Every different way we can arrange the sequence, we get a new path, therefore the solution is (x2 + y2 - x1 - x2)! / (x2 - x1)! / (y2 - y1)!...

    It is essentially the same thing :P.

  • Custom User Avatar

    No you are not stupid ;). I was wondering the same thing and was hoping for some clarification. I returned it as an int and passed all the test cases.... :)

  • Loading more items...