I had to prove to myself that I'm not one of those mentioned, so here's my Ruby solution to the pre-interview 'test':
Ruby:
100.timesdo |n|
if(n%5 == 0 && n%3 == 0)then puts"FizzBuzz" elsif(n%3 == 0)then puts"Fizz" elsif(n%5 == 0)then puts"Buzz" else puts n
end
end
This took <10 minutes, including the time I took to look up how elsif structures work in Ruby (since I haven't used those in a while, oddly).
Sponsor Sponsor
USEC_OFFICER
Posted: Thu Mar 11, 2010 12:33 pm Post subject: RE:Why can\'t programmers...program?
Really? They can't even do the FizzBuzz program? Even though it has been a while since I used C++, I'm sure I could do it in under 10 minutes. (Too lazy to try.)
EDIT: Here it is in Turing, took me a minute or two:
Turing:
for i :1.. 100 if i rem5=0and i rem3=0then put"FizzBuzz" elsif i rem5=0then put"Buzz" elsif i rem3=0then put"Fizz" else put i
endif endfor
chrisbrown
Posted: Thu Mar 11, 2010 1:20 pm Post subject: RE:Why can\'t programmers...program?
The purpoose of this exercise isn't to see if you can write the program or even demonstrate a working knowledge of a particular language, it is to show that you can produce a working program from a given specification. I think it is safe to assume that most members here would call this a trivial problem.
This article is trying to point out that there are a large number of people who, for whatever reason, think they are good programmers, but aren't.
Personally (because I've seen way too much of this), I think this is because they spend hours on the tweak-test-repeat cycle until they stumble onto the desired behaviour. That's fine for high school, but beyond that, you need to be able to look at a program and at least get a general idea of problem spots, rather than change one thing and hope your problem goes away, and try again if it doesn't.
Zren
Posted: Thu Mar 11, 2010 3:15 pm Post subject: RE:Why can\'t programmers...program?
PS: The multiple of 3 and 5 is the same as multiples of 15.
I've noticed people tend to do exactly as the problem says (not that it bad really), but don't notice simple math rounding or slightly more efficient code.
Insectoid
Posted: Thu Mar 11, 2010 4:09 pm Post subject: RE:Why can\'t programmers...program?
Well, if I bothered to think about this I'd realize that Zren, however I wasn't at school at the time so I was lacking in motivation.
My grade 12 CS class was supposed to be focused on efficiency, but instead we wasted time learning yet another useless language (this one Flash) so I dunno how to make it more efficient beyond replacing n%5 && n%3 with n%15.
USEC_OFFICER
Posted: Thu Mar 11, 2010 4:20 pm Post subject: RE:Why can\'t programmers...program?
You really can't make a simple program like this one more efficient than it already is.
andrew.
Posted: Thu Mar 11, 2010 4:34 pm Post subject: RE:Why can\'t programmers...program?
Wow, that's shocking. I did it myself in under 2 minutes.
Python:
for i inrange(1,101):
if(i % 15 == 0): print"FizzBuzz" elif(i % 3 == 0): print"Fizz" elif(i % 5 == 0): print"Buzz" else: print i
rdrake
Posted: Thu Mar 11, 2010 6:36 pm Post subject: Re: Why can't programmers...program?
Needs nicer Ruby.
Ruby:
100.timesdo |n|
if n % 15 == 0 puts"FizzBuzz" elsif n % 3 == 0 puts"Fizz" elsif n % 5 == 0 puts"Buzz" else puts n
end
end
Sponsor Sponsor
Insectoid
Posted: Thu Mar 11, 2010 6:56 pm Post subject: RE:Why can\'t programmers...program?
Meh, I can never decide if Ruby wants brackets or not, but what harm is there in using them?
Switching between Java, Flash, Turing and Java often confuses me.
Anyway, we all know every one of us can do this program, but let's discuss the actual issue the blog was addressing.
DtY
Posted: Thu Mar 11, 2010 7:20 pm Post subject: RE:Why can\'t programmers...program?
I guess this topic is just going to be about posting the solution over and over in different languages, so here's another solution in Python:
Granted, I probably wouldn't go for that if all I had was paper, and could not actually test it.
Never thought of doing it like that. I guess that proves I'm still a Python n00b.
USEC_OFFICER
Posted: Thu Mar 11, 2010 8:08 pm Post subject: RE:Why can\'t programmers...program?
Now that we do know that in fact, we can all do the program, can we talk about the blog? And why most graduates can't do this in 10-15 minutes?
DtY
Posted: Thu Mar 11, 2010 8:27 pm Post subject: Re: RE:Why can\'t programmers...program?
USEC_OFFICER @ Thu Mar 11, 2010 8:08 pm wrote:
Now that we do know that in fact, we can all do the program, can we talk about the blog? And why most graduates can't do this in 10-15 minutes?
It's probably largely how CS is taught. Last year, when we were learning Turing, I felt like there was a lot of this is how you do this, and not so much this is why you want to do this, and this is how it works with that. I don't imagine this would continue so much into a university level, and the teacher I have this year does a better job with the why. What I mean can be summed up pretty well (by changing the context) with this passage out of Nineteen Eighty-Four:
Quote:
He took up his pen again and wrote:
I understand HOW: I do not understand WHY.
This seems to be, in my experience anyway, the problem with a lot of elementary and high school classes.
I went to a French immersion school until less than a month into grade six, when I moved and started going to an English school. Going through non immersion French classes until grade nine, using grade three to four textbooks, it amazed me that a lot of the class could not string together complete sentences and carry a conversation in French, that was something the majority of my class could do after kindergarden. It was not their fault though (of course, it didn't help that no one, not even myself wanted to be there), most classes were learning verb conjugations and exceptions, and not actually talking in French. It's funny, though, you can ask nearly anyone who is a native English speaker to conjugate 'to be', and they'll stumble over it, or not get it at all, but they can use it in any sentence just fine, it's because you don't learn a new language by memorizing verb exceptions, but there is such an emphasis on that for some reason.
---
andrew: Don't worry, no one who hasn't spent time using functional languages would think that's a good idea to use
andrew.
Posted: Thu Mar 11, 2010 10:32 pm Post subject: Re: RE:Why can\'t programmers...program?
DtY @ Thu Mar 11, 2010 8:27 pm wrote:
I went to a French immersion school until less than a month into grade six, when I moved and started going to an English school. Going through non immersion French classes until grade nine, using grade three to four textbooks, it amazed me that a lot of the class could not string together complete sentences and carry a conversation in French, that was something the majority of my class could do after kindergarden. It was not their fault though (of course, it didn't help that no one, not even myself wanted to be there), most classes were learning verb conjugations and exceptions, and not actually talking in French. It's funny, though, you can ask nearly anyone who is a native English speaker to conjugate 'to be', and they'll stumble over it, or not get it at all, but they can use it in any sentence just fine, it's because you don't learn a new language by memorizing verb exceptions, but there is such an emphasis on that for some reason.
That's an amazing point. I've never really thought about the way language is taught (mostly because I don't like language). But now that you have me thinking about it, Spanish is also taught this way and I'm sure German, Latin, and other languages are too. I completely agree with you that we should learn to speak fluently first, and not to focus too much on things like conjugations. That way students will have a better understanding of the language and the way it works.
I see how you are linking this to a programming language. The students should learn the substance of the language and how it works instead of piecing together half-formed programs using methods that they memorized. I think this is a great point and I completely concur with it.
P.S. How do you conjugate "to be" in English?
Alexmula
Posted: Thu Mar 11, 2010 10:37 pm Post subject: Re: RE:Why can\'t programmers...program?