Vietnamese numbers, with a couple of exceptions, are very very logical.
The number twelve is just (word-for-ten)(word-for-two) for instance. The number thirty is just (word-for-three)(word-for-ten) and the number thirty-two is just (word-for-three)(word-for-ten)(word-for-two).
The one main exception therefore is that numbers after twenty go two-ten-two, two-ten-three, etc, and the numbers between ten and twenty just go ten-one, ten-two, not one-ten-two.
However, despite the language being logical, I'm not so logical, obviously.
Here's what I came up with. Reverse the digits of the numbers, push the words, using a hash, onto an array, and then reverse the array and print it.
The code below works up to a hundred, but not after that.
I'm sure I'm missing some easy way to do this. Any help gratefully recieved.
%numbers = ( 0, '', 1, 'mot', 2, 'hai', 3, 'ba', 4, 'bon', 5, 'nam', 6, 'sau', 7, 'bay', 8, 'tam', 9, 'chin', 10, 'muoi', 100, 'tram', 1000, 'ngan' ); sub translate { my $number = $_[0]; my @output = (); if (defined($numbers{$number})) { $text_version = $numbers{$number}; print "$text_version \n"; } else { $reverse_number = reverse($number); $places = 1; @digits = split ('', $reverse_number); foreach $digit (@digits) { if ($places == 1) { push (@output, $numbers{$digit}); } else { push (@output, $numbers{$places}); unless ($number < 20) { push (@output, $numbers{$digit}); } } $places *= 10; } @output = reverse(@output); print "@output \n"; } }
($_='jjjuuusssttt annootthheer pppeeerrrlll haaaccckkeer')=~y/a-z//s;print;
In reply to Vietnamese Numbers by Cody Pendant
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |