So, I've been working on a bunch of the Project Euler problems since I did the first three and just stopped. I made it to #10 in about an hour, and wrote a pretty simple program. I don't want to give it away, but this is what I meant for my for loop to say: for (longlong i = 2; i < 2000000; i ++)
But instead, I wrote this: for (longlong i = 2; 1 < 2000000; i ++)
I figured my code would take a little while to run the whole way through, but after about 20 minutes I got nervous. Then I tried to do the sample, i < 10...I force closed it after 3 seconds. I then noticed my error.
Now, this isn't the first time I've accidentally written a 1 instead of an i, but I have no clue as to why I do it. Does anyone else out there have the same, or similar, issues?
It means you seek the absolute truth.
Seriously, do you really think it means anything? Your synapses still have some loose ends, that's all. Nothing to worry about in the long term.
lol I didn't mean like I think it means something in depth, just maybe there is a reason as to why I do it, and it only ever happens in for loops, very rarely elsewhere, and only when I'm programming in C++.
And I know a have more than some loose ends, but that's a topic for another thread.
Dr. Catfish II analyzes the problem and diagnoses!
Possible reasons for your actions: 1) insanity 2) fear of uncertainty 3) very bad font 4) lack of experience 5) inner desire to break things 6) inner desire to cause suffering (including to oneself)
Oddly enough, the closer you got to the bottom the more truthful your statements became, especially the last two. I apparently love making things hard on myself.
I do check my code, syntax highlighting makes it easy. But I believe it's made me lazy. I also believe the font type makes it hard to see the difference between a 1 and i. Either that, or I'm sitting too far away from my screen and can't differentiate. Maybe I'll just start using a and work my way up the alphabet.
Numbers appear red to me, and letters, black. it seems like it should be easily distinguished, and I can find my errors once my results are wrong, but they don't just jump out at me. =/
I've been having this issue since I started programming in 11th grade. Now 7 years later it still happens. Granted this isn't like every program I typed I make this mistake, but when I do I end up with either an infinite for loop, or a for loop that never gets run and I have to reread my entire code. Maybe I have a form of dyslexia.
Lol, I've been programming for a while, but I still look at myself as a beginner, no harm done. And I've been tinkering with different options, settings, macros, etc. in my different IDEs, but I've become extremely fond of Code::Blocks. Is there a compile-time tool or option of Code::Blocks that can do this? Or would I have to write a seperate program just to check my code for that instance?
#!/usr/bin/env python
import sys
if len(sys.argv) < 2:
print "Usage: %s FILE" % (sys.argv[0])
exit(1)
filename = sys.argv[1]
file = open(filename, 'r')
num = 1
for line in file:
if line.find('1 < ') >= 0:
print "%s:%d:%d: '1 < ' where 'i < ' may have been intended." % (filena$
num += 1
Then, have the IDE run that on each source file. I haven't used Code::Blocks in a while, so I don't know how to do it, but I have a feeling there is an option to.
If you haven't already, you'll need to install Python (or convert that script into C++, which is pretty easy to do).