Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Roman numerals

By: a guest on Jan 15th, 2012  |  syntax: Perl  |  size: 0.38 KB  |  views: 47  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/bin/perl -w
  2. $string="CMCDXCXLIXIVI"; @letters=split //,$string;
  3. foreach $i (1 .. 2 ** scalar @letters) {
  4.   %used=();$number="";$k=$i;
  5.   foreach ($j=0; $j<=$#letters;$j++,$k >>= 1) {
  6.     $letter=$letters[$j];
  7.     if ($k % 2 and !$used{$letter}) {
  8.       $used{$letter}=1; $number.=$letter;
  9.     }
  10.   }
  11.   if (!$seen{$number}){
  12.     $seen{$number}=1;
  13.     print "$number\n";
  14.   }
  15. }