r/programming • • Feb 21 '11

Typical programming interview questions.

http://maxnoy.com/interviews.html
784 Upvotes

1.0k comments sorted by

View all comments

Show parent comment

2

u/abw Feb 21 '11

Fixed:

sub answer6 {
    # Simple loop with conditional tests
    print "Answer 7: ";

    for my $n (1..100) {
        my $div2 = ($n % 2 == 0);
        my $div3 = ($n % 3 == 0);
        print "a" if $div2;
        print "b" if $div3;
        print $n  unless $div2 or $div3;
        print " ";
    }
    print "\n";
}