SHARE
TWEET

Roman numerals

a guest Jan 15th, 2012 52 Never
  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. }
RAW Paste Data
Top