After a fair bit of trial and error I've discovered that people who struggle to code don't just struggle on big problems, or even smallish problems (i.e. write a implementation of a linked list). They struggle with tiny problems.
So I set out to develop questions that can identify this kind of developer and came up with a class of questions I call "FizzBuzz Questions" named after a game children often play (or are made to play) in schools in the UK. An example of a Fizz-Buzz question is the following:
Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".
Most good programmers should be able to write out on paper a program which does this in a under a couple of minutes. Want to know something scary? The majority of comp sci graduates can't. I've also seen self-proclaimed senior programmers take more than 10-15 minutes to write a solution.
Der Artikel ist interessant und ihr könnt euch mal selbst testen. Wenn ihr in unter 10 Minuten was auf Papier bringt, was bei der Umsetzung lauffähig ist seid ihr kein vollhorst :)
Lösungen bitte mit dem Spoiler-Tag versehen!
15.07.2012, 15:12
Death~
AW: Why Can't Programmers.. Program?
Zitat:
10-15 minutes
Made my day :p
15.07.2012, 15:13
Bonkers
AW: Why Can't Programmers.. Program?
Code:
using System;
namespace FizzBuzz
{
class Program
{
static void Main(string[] args)
{
for (int i = 1; i < 101; i++)
{
if (i % 3 == 0) {
Console.Write("Fizz");
}
if (i % 5 == 0) {
Console.Write("Buzz");
}
if (i % 3 != 0 && i % 5 != 0) {
Console.Write(i);
}
Console.WriteLine("");
}
Console.Read();
}
}
}
Unschönes C#, hat dafür nur 1 Minute gedauert :)
15.07.2012, 15:14
enco
AW: Why Can't Programmers.. Program?
Du hast "FizzBuzz" vergessen, wenn durch 3 und 5 teilbar. So viel zu einer Minute ;)
Edit:\\ Leseschwäche :)
15.07.2012, 15:16
Bonkers
AW: Why Can't Programmers.. Program?
Zitat:
Zitat von enco
Du hast "FizzBuzz" vergessen, wenn durch 3 und 5 teilbar. So viel zu einer Minute ;)
Habe ich nicht. Bei 3 wird "Fizz" geprinted, bei 5 "Buzz" - Zusammen ergibt das "FizzBuzz" als Ausgabe.
15.07.2012, 15:18
Death~
AW: Why Can't Programmers.. Program?
Da fehlt noch ein Console.Writeline(i) vor oder nach den Bedingungen, damit auch die normalen Zahlen geschrieben werden.
Edit: != nicht gesehn, fail ^^
15.07.2012, 15:22
Bonkers
AW: Why Can't Programmers.. Program?
Könnt ihr alle nicht lesen? Mein Code funktioniert genau wie er soll. Normale Zahlen werden auch geschrieben, es gibt auch einen Zeilenumbruch. Erst lesen, dann Maul aufmachen.
Dein Code gibt aber "Fizz" und die Zahl aus wenn Sie durch 3 teilbar ist. Du sollst allerdings statt der Zahl Fizz/Buzz ausgeben. Nicht:
Mein Fehler^^
15.07.2012, 16:10
Bonkers
AW: Why Can't Programmers.. Program?
enco du solltest den Thread mal aufräumen und nur die zwei Lösungen stehen lassen.
Eventuell hat Reidcore ja noch Lust seine zu berichtigen, ich finde es nämlich etwas traurig dass sich zu solch einer einfachen Aufgabenstellung nur eine funktionieren Lösung finden lässt. Ich hoffe einfach mal das wenigstens unsere Ente noch etwas beiträgt.
15.07.2012, 16:15
ReiDC0Re
AW: Why Can't Programmers.. Program?
Zitat:
Zitat von Bonkers
Eventuell hat Reidcore ja noch Lust seine zu berichtigen,
Habe ich schon längst ;)
Ich glaub enco, hat dazu gar keine Rechte.
15.07.2012, 16:19
Bonkers
AW: Why Can't Programmers.. Program?
Zitat:
Zitat von ReiDC0Re
Habe ich schon längst ;)
Dein Code gibt immer noch Zahl und Wort aus.
Zitat:
print "Fizz" instead of the number
15.07.2012, 16:20
ReiDC0Re
AW: Why Can't Programmers.. Program?
Bei mir nicht:
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Evt. hast du den falschen Fetzen ausgeführt.
15.07.2012, 16:21
blackberry
AW: Why Can't Programmers.. Program?
Zitat:
Zitat von Bonkers
Habe ich nicht. Bei 3 wird "Fizz" geprinted, bei 5 "Buzz" - Zusammen ergibt das "FizzBuzz" als Ausgabe.
Haha, dein Code ist falsch, weil es kein Visual Basic ist!
15.07.2012, 16:47
Bonkers
AW: Why Can't Programmers.. Program?
Zitat:
Zitat von blackberry
Haha, dein Code ist falsch, weil es kein Visual Basic ist!
Code:
Dim FreeHack as competent
Error at line 1: FreeHack is incompetent beyond belief. Conversion Error.
Geht nicht?
15.07.2012, 20:29
IRET
AW: Why Can't Programmers.. Program?
Zitat:
Zitat von Bonkers
Unschönes C#, hat dafür nur 1 Minute gedauert :)
So lang? Das ist doch ein 2-Zeiler in C# ^^.
Code:
for (int i = 1; i <= 100; i++)
Console.WriteLine(
(i % 3 == 0) ?
((i % 5 == 0) ? "FizzBuzz" : "Fizz")
:
(i % 5 == 0) ? "Buzz" : i.ToString());
Bin etwas müde. Könnte sich also evntl. ein Fehler eingeschlichen haben.
//Edit: So hab den Code mal etwas formatiert, dass man ihn besser lesen kann.
15.07.2012, 20:41
ReiDC0Re
AW: Why Can't Programmers.. Program?
Zitat:
Zitat von fuckinghot19
So lang? Das ist doch ein 2-Zeiler in C# ^^.
Der gesamte Code unleserlich in einer Zeile ist immer eine gute Idee. Allgemein sollte ein Programm so wenig Zeilen wie möglich beinhalten.
Du hättest auch die Modulo Berechnung in den IF-Statements Abfragen können.
Damit hättest du ein paar Bytes sparen können. Da die 2 int Variablen Speicher verwenden.
16.07.2012, 12:46
Seraphine
AW: Why Can't Programmers.. Program?
Python:
Code:
for a in range(1, 101):
if a % 15 == 0:
print 'Seraphine'
elif a % 3 == 0:
print 'Sera'
elif a % 5 == 0:
print 'Phine'
else:
print a
Short Python:
Code:
import fizzbuzz
print autoawesome
(notquiteas)Short Python
Code:
for a in range(100): print a%3/2*'Sera'+a%5/4*'Phine' or a+1
Output:
Code:
1
2
Sera
4
Phine
Sera
7
8
Sera
Phine
11
Sera
13
14
Seraphine
16
17
Sera
19
Phine
Es tut mir leid "Grandmaster Berry" mehr als noobig ging gerade nicht
Wer meint mich in Brainfuck unterbieten zu wollen: bitte sehr. (aber bitte optimiert nicht einfach meinen Code [ja... da sind einige "<>"s und "><"s drin, die man nur löschen müsste, um einige Bytes zu sparen] und sagt das wär eurer... das wär noobig)
17.07.2012, 07:26
ReiDC0Re
AW: Why Can't Programmers.. Program?
blackberry forderte mich heraus und das mehrfach. Hier kommt meine Antwort:
Angefangen mit einem byte converter(dec):
Genau genommen dürften die Zahlen 3 und 5 nicht ausgegeben werden. Jetzt glauben alle sie wären Programmierer, dabei ist es doch eine Grundeigenschaft über den Tellerrand zu blicken, oder nicht?
Wer hatte nochmal gefragt ob ein echtes Vielfaches gewünscht ist?
17.07.2012, 18:10
Bonkers
AW: Why Can't Programmers.. Program?
Zitat:
Zitat von Atbash
Wer hatte nochmal gefragt ob ein echtes Vielfaches gewünscht ist?
Zitat:
In mathematics, a multiple is the product of any quantity and an integer.
Zitat:
The integers (from the Latin integer, literally "untouched," hence "whole": the word entire comes from the same origin, but via French[1]) are formed by the natural numbers (including 0) (0, 1, 2, 3, ...) together with the negatives of the non-zero natural numbers (−1, −2, −3, ...).
1 ist ein Integer und da in der Aufgabenstellung nur von "multiples" die Rede ist kann man davon ausgehen dass 3 und 5 mitgezählt werden.
17.07.2012, 18:20
Atbash
AW: Why Can't Programmers.. Program?
Programmier mal für einen Kunden. Du wirst schnell feststellen, dass er selbst nicht so genau weiß er will.
17.07.2012, 18:30
blackberry
AW: Why Can't Programmers.. Program?
Unfug. Wenn der Kunde nicht weiß was er will, dann ist das nicht dein Schaden. Dafür macht man am Anfang ein Pflichtenheft und hält vertraglich fest was zu leisten ist.
Das wird unterschrieben und wenn der dann am Ende meint er würde was anderes brauchen, dann kann er das gerne bekommen, aber für die getane Arbeit wird erstmal Geld rausgerückt und die Änderungen kosten extra.
Dass Kunden Hornochsen sind sichert dir lediglich auch für die Zukunft Aufträge. In dem Fall war nach Vielfachen und nicht direkt nach echten Vielfachen gefragt. Dein Einwand ist unsinnig.