One Point Solution

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Friday, 4 October 2013

More answers to Quora questions.

Posted on 16:58 by Unknown

Weeks ago I wrote a post: vexorian answers quora questions. It was a fun blog post to wire it, so I am going to answer some more:

What are the things you wish you knew when you started programming for the first time?

In general:

  • Speed sucks. There will be some situations in which speed matters, and it is good to have a language that is not like super ultra slow. But unless you have very specialized applications, low level speed should never be your primary objective. (high level optimization is cool though)
  • You'll spend more time reading your code than typing it. So make it readable for god's sake.

For "Competitive programming" :

  • There is no money in participating in contests. There is good money in working behind the scenes though.
  • You did not solve a problem until you code a passing solution. No, you didn't. No, just knowing what the solution is is not the same as solving the problem.
  • It is pointless to spend weeks trying to come up with solutions on your own. If you can't solve a (practice) problem after some hours, search for the solution.
  • Similarly, it is pointless to look for answers immediately after reading a problem's statement. Always give yourself a chance to at least try solving it.
  • You need a plugin to code in TopCoder. Really, you do.

(topcoder) Do you use the Coding Area to code your solution or a separate IDE?

IDEs are the spawn of Satan, but the arena is very limited. You need a plugin. Until recently I've been using a modded KawigiEdit. Lately I am using Greed. I use jEdit to edit code. Each programmer needs a specific set of editor features and in my case I prefer to have fewer features as big editors "get in the way".

How should I practice so that I will be at a level where I can approach TopCoder's Div1-500 problems with confidence?

Sink or swim. What I did when I noticed I was getting stuck in division 1 easy difficulty was to open the div 1 500 first. This way I was forced to solve a div1 medium every once in a while or else my rating would be destroyed. Plus I eventually got used to at least being able to try this slot. I know that this doesn't help your issue about [confidence], because you'll need to at least once try to solve a div1 500 during a match knowing that you don't have a confidence to solve them. But you don't really need the confidence.

Difficulty is not static though, with time problems became tougher and I have had to repeat the effort more than once.

Is it better to learn algorithms from a book or by solving online problems?

I've been meaning to say something about the Books topic in this blog for a while now. Books have not really helped me that much. Whenever people ask me about books, I bring the two closest things to a book that helped me, like Programming Challenger and CLRS. But the other day I learned that I don't even know the author's name for Programming Challenger.

In my case, I think that reading online resources (Editorials, tutorials, howtos, wikipedia pages, etc) and asking questions in forums was far, far more useful than books. Any good contest site should have a resource like that. Try to solve a problem, then after the contest, ask how to solve it, read editorials and any material suggested by people explaining the problem. But if you like getting theory from books, feel free to do it.

Why do a lot of successful competitive programmers not participate actively on CodeChef but participate often on sites like TopCoder and Codeforces?

I don't know about successful coders, but I can speak for myself.

  • I don't have time to participate in all contests released in a month, so I have to put priorities.
  • I choose TopCoder as my first priority, because the 75 minutes format is a lot more comfortable than longer format, and because I would likely have to solve those problems anyway because of my job.
  • Second priority is Codeforces because it is has a very competitive userbase. Although it sort of bores me some times.
  • Why Codeforces and not Codechef? The Codechef format is not helpful. Spending 15 days on a contest would really kill me and leave me with no time for other things. The cook-offs sound ok, but they happen only once a month, and on Sundays, and at a very bad time of the day for me.

How should programmers place their hands on the keyboard in order to increase the typing speed

Uh? Unless you have serious difficulty typing at a decent pace, you shouldn't care that much about your typing speed. Other factors are more important, like thinking of the algorithm you need to code.

If you do lack typing skill (For example, you need to see the keyboard while you are typing), then there are good resources to learn typing out there in the web and practice makes best. typeracer offers both a place where you can practice typing competitively and the forum is a good entry point to the part of the internet that cares about typing speed and has tips/etc.

I learned to type in school around 18 years ago. They made do typing in typewriters, if you got something wrong, you had to restart over. Yeah.

Do you find skills you achieved during programming contests to be useful outside of them?

I personally wouldn't have learned C++ nearly as well as I had without programming contests. Programming contests give you a very good opportunity not just to code solutions to known problems. but to make mistakes when coding those solutions. Because the problems are well-defined, we can run your solutions against a fixed-tester and find a plethora of implementation bugs. Constantly. This will teach you about what things can fail, what pitfalls your language has. What sort of mistakes you are likely to make.

Rant: My god, look at the answers to this question. Read this: Regarding the smug opposition to programming contests. Specially the anonymous guy who thinks adding a competitive layer to programming is to "prostitute" programming.

Programming contests are fun and that should be your first priority. There are, however, some nice skills you can learn through them. It is true that they are skills you can learn in other ways like making contributions to open source software, the demoscene, modding, making your own apps, building robots, etc*. To each their own, if you have more fun at competitive programming than in those areas, then programming contests are a good way for you to develop these skills. The trick to programming is to pick an area you are passionate about and develop your skills there. It is incredibly stupid to be afraid to pick areas of programming that do not have the approval from random people in question sites...

(*But of course not college! lol!. I am talking about skills that require creative coding ability, things college cannot really teach (sorry!) ) Speaking of college, while a good college should be better at teaching you CS theory, the programming contest world is probably a better place to learn CS theory than 99% of colleges.

What do you do when your code is not accepted but you don't find a test case that makes it fail?

If you can't really find any test case, then you are wasting your time solving problems in a judge site that doesn't share test cases. That is very bad for your productivity. Avoid those sites like the plague they are. While there are urban myths about how making you find the wrong test case by yourself will make you better at programming, you should consider that transparency is very importance. Have you stopped to think, what if? What if your code is actually correct? What if the judge was wrong? What if that's the reason you can't find a wrong test case? Transparency = guarantees. If somebody thinks he will get better by guessing the test case he is failing, he can just not take a look at the test cases.

If your problem is different and you actually know that your code is failing a case, but it is a very complicated one so it doesn't tell you much. Then you'll need to get creative.

  • First of all, why is it that apparently none of the simple test cases was wrong? Maybe your code has issues that are specific to large test cases? E.g: A memory write out of bounds of an array could be corrupting your memory. E.g.2: Overflow.
  • In topcoder, sometimes some large cases of the system tests are first in order to other, simpler cases. But since system tests finish running once they find a wrong test case, you cannot find out the simpler cases. What I do sometimes is manually pre-code the results to each complex case until I find a simple case that executes after them and is also wrong.
  • Read editorial / tutorial and try solving with the solution described in there . If the solution in the editorial is the same as yours then you probably need to inspect each line for possible errors. That is sometimes all I can do, verify each line, sometimes multiple times. Sometimes I fall sleep while doing it.
  • Ask in the forums. But please, help us help you. You need to explain your solution and why do you think it should be correct. If you don't have a proof that your solution should work, then it probably won't work. Probably its bugs are not small implementation mistakes but the whole algorithm is wrong. Sometimes it is better to just redo the work. If you have been having issues proving a solution is correct, then maybe you should try to prove it is wrong. Unfortunately this involves finding counter-examples and that's exactly what you are looking for.
  • If everything fails: Grab somebody else's correct code and generate random, small, test cases until you find one that makes your solution give a wrong solution. Maybe you will finally find something.
  • If that fails, give up.

Why is Python not allowed as one of the languages for ICPC?

I'd say some tournaments just can't keep up :/

How can I print 1 to 100 in C++ without a loop, GOTO or recursion?

Lambda power (requires c++11):


#include<functional>
#include<iostream>
using namespace std;

int x = 0;
void q()
{
if (x != 100) {
cout << (++x) << endl;
}
}

// t(q()) returns a function that calls q() two times.
// t(t(q())) returns a function that calls t(q()) two times == q() four times
// ...
function<void()> t( function<void()> g) {
return [&g] {
g();g();
};
}

int main()
{
// call q() 128 times:
t(t(t(t(t(t(t(q)))))))();
return 0;
}

Laziness power:


#include <iostream>
using namespace std;

int main()
{
cout << "Please type all numbers from 1 to 100 in a single line:"<<endl;
string x;
getline(cin, x);
cout << x; //If user does his/her job correctly, this statement will print the numbers
return 0;

}
Email ThisBlogThis!Share to XShare to Facebook
Posted in answers, quora, rant | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • TopCoder SRM 557 - finally
    SRM 557 Explanation for division 1 Easy and match recap. Explanations for div2 easy and div2 medium. It feels like it has been ages since t...
  • SRM 589 Editorial
    I have finished writing the editorial for TopCoder SRM 589: http://apps.topcoder.com/wiki/display/tc/SRM+589 . As you most likely noticed. L...
  • SRM 590 recap and editorial
    Another week another Topcoder match. Not a great day. I had a bad flu and still do. Div1 500: The one with Xor Given a list of cards with nu...
  • SRM 546: relief
    I figured I should post something about this SRM. I've been very busy these weeks because the semester is ending and I tried to win a t-...
  • SRM 526: The killing wait for results
    While I wait for results, here is my perspective on this algorithm contest. It began with issues, it had to be postponed 15 minutes. TC has ...
  • SRM 554 div1 hard: TheBrickTowerHardDivOne
    Link to problem statement We got infinitely many bricks of dimensions 1x1x1 and C different colors. Count the number of towers of size 2x2...
  • SRM 533: Div1 500 MagicBoard explanation
    Finally solved it. It is a nice problem that is worth explaining in a post. You have a grid/board of at most 50x50 cells. Some cells contain...
  • Member SRM 505: Part 1
    So, let me explain a couple of problems from a Topcoder Member SRM that I wrote and never got an editorial. BTW, it was the last member SRM....
  • ListedLinks 2012-02-10
    Saturday Morning Breakfast Cereal comics: Grace Hopper's ghost That Oracle engineer blog post Oracle would really not like anyone to se...
  • Codeforces "Good bye 2013" round
    So it was a special round for coders of both divisions, problems ranged from the super easy problem A to the super difficult problems E,F,G....

Categories

  • acm
  • algorithm
  • answers
  • arenaplugin
  • badday
  • behindthescenes
  • bugs
  • c++
  • censorship
  • codechef
  • codeforces
  • contests
  • crocchamp
  • editorial
  • editorial.srm
  • embarrassing
  • explanation
  • gcj2013
  • gmp
  • goodday
  • google
  • googlecodejam
  • greed
  • groklaw
  • health
  • html
  • httpseverywhere
  • implementation
  • ipsc
  • ispc
  • java
  • kawigiedit
  • kindagoodday
  • lamebook
  • languages
  • lego
  • listedlinks
  • marathon
  • nasa
  • offtopic
  • ouch
  • postmortem
  • postportem
  • practical
  • probably_not_a_good_tip
  • problemsetting
  • programming
  • python
  • quora
  • rant
  • recap
  • slightlygoodday
  • snippet
  • srm
  • stl
  • strategy
  • swerc
  • tco
  • tco12
  • tco13
  • tco2012
  • tco2013
  • ternarysearch
  • topcoder
  • tricks
  • ubuntu
  • uva
  • vjass
  • vkcup
  • wc3
  • zinc

Blog Archive

  • ►  2014 (1)
    • ►  January (1)
  • ▼  2013 (141)
    • ►  December (14)
    • ►  November (8)
    • ▼  October (13)
      • Coding habits
      • SRM 595
      • Editorial for SRM 594 Div1 Hard: FoxAndAvatar
      • SRM 594 editorial (Part 1)
      • SRM 594: More slowness
      • So, TCO 2013 video contest
      • WolfDelaymasterHard editorial
      • SRM 593 Editorial (Part 1)
      • c++ and python topcoder generic testers
      • Together we can send vexorian to the TCO 2013
      • SRM 593: Meh
      • More answers to Quora questions.
      • Codeforces #204 (div 1) Recap
    • ►  September (11)
    • ►  August (14)
    • ►  July (15)
    • ►  June (13)
    • ►  May (13)
    • ►  April (12)
    • ►  March (11)
    • ►  February (11)
    • ►  January (6)
  • ►  2012 (94)
    • ►  December (5)
    • ►  October (6)
    • ►  September (8)
    • ►  August (6)
    • ►  July (3)
    • ►  June (5)
    • ►  May (8)
    • ►  April (10)
    • ►  March (20)
    • ►  February (16)
    • ►  January (7)
  • ►  2011 (51)
    • ►  December (7)
    • ►  November (12)
    • ►  October (5)
    • ►  September (1)
    • ►  August (3)
    • ►  July (4)
    • ►  June (3)
    • ►  May (7)
    • ►  April (3)
    • ►  March (2)
    • ►  February (1)
    • ►  January (3)
  • ►  2010 (9)
    • ►  December (4)
    • ►  October (1)
    • ►  June (1)
    • ►  May (1)
    • ►  January (2)
  • ►  2009 (1)
    • ►  December (1)
Powered by Blogger.

About Me

Unknown
View my complete profile