Skip to content

Comment on Solving FizzBuzz with C++ compiler error messagesparent

Comments

How about Perl:

  #!/usr/bin/perl
  $n = 100;

  open(FH, '>touch') and print FH '' and close FH;
  push @ARGV, "Fizz$_" for (1..$n/3);	#push some fizz's
  push @ARGV, "Buzz$_" for (1..$n/5);	#push some buzz's
  push @ARGV, $_ for (1..$n);		#we'll sort it all out later

  1 while ($_ = shift and @ARGV and !fork);  #let the games begin

  if (/Fizz(\d+)/) {
     sleep $1 * 9;
     open (FH, '>>touch') and print FH "Fizz" and close (FH); 
     }

  elsif (/Buzz(\d+)/) {
     sleep $1 * 15 + 1;
     open (FH, '>>touch') and print FH "Buzz" and close (FH); 
     }

  else {
     sleep $_ * 3 + 2;
     open(FH, 'touch') and @lines = <FH> and close (FH);
     open(FH, '>touch') and print FH '' and close FH;
     print @lines ? @lines : $_, "\n";
     }

What do you think? I didn't bother cleaning up the file access. Nefarious though isn't it.
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.