#!/usr/bin/env perl use strict; use warnings; use open OUT => qw{:encoding(UTF-8) :std}; use constant VF => { 1 => { 2 => 0xbd, 3 => 0x2153, 4 => 0xbc, 5 => 0x2155, 6 => 0x2159, 7 => 0x2150, 8 => 0x215b, 9 => 0x2151, 10 => 0x2152, }, 2 => { 3 => 0x2154, 5 => 0x2156, }, 3 => { 4 => 0xbe, 5 => 0x2157, 8 => 0x215c, }, 4 => { 5 => 0x2158, }, 5 => { 6 => 0x215a, 8 => 0x215d, }, 7 => { 8 => 0x215e, }, }; my @tests = ( [1,2], [1,3], [1,4], [1,10], [3,8], [9,10], [qw{x y}] ); compose_vulgar_fraction(@$_) for @tests; sub compose_vulgar_fraction { my ($num, $denom) = @_; my $composed; if (exists VF->{$num} and exists VF->{$num}{$denom}) { $composed = chr VF->{$num}{$denom}; } else { $composed = join '/', $num, $denom; } printf "%3s/%-3s : %s\n", $num, $denom, $composed; return; }