#!/usr/bin/perl -- use strict; use warnings; Main( @ARGV ? @ARGV : qw' 123 555 7672676' ); exit(0); sub Main { for my $num (@_) { my @n = MakeN($num); for my $n (@n) { print "permute: $n\n"; print join( "", @$_ ), "\n" for permute( NumberList($n) ); } print "\n"; } ## end for my $num (@_) } ## end sub Main sub MakeN { my $n = join '', @_; my @n; while ( 3 <= length $n ) { push @n, $n; chop $n; } @n = reverse @n; @n; } ## end sub MakeN sub NumberList { my %lettermap = ( 1 => [' '], 2 => [qw' a b c '], 3 => [qw' d e f '], 4 => [qw' g h i '], 5 => [qw' j k l '], 6 => [qw' m n o '], 7 => [qw' p q r s '], 8 => [qw' t u v '], 9 => [qw' w x y z '], 0 => [' '], '*' => [qw' + '], '#' => ['#'], ); return @lettermap{ split //, join '', @_ }; } ## end sub NumberList ## http://perlmonks.org/?node_id=24270# Permutations and combinations sub permute { my $last = pop @_; unless (@_) { return map [$_], @$last; } return map { my $left = $_; map [ @$left, $_ ], @$last } permute(@ +_); } ## end sub permute __END__
For example 555 or 123 (any permutation of 123) cannot comprise English words.
7672676 aka popcorn used to be a special number (at the beep, the time will be 2:30 pm, PST, beeep) and it was 767 followed by any four numbers, not just corn.
In reply to Re: Phone number to word conversion
by Anonymous Monk
in thread Phone number to word conversion
by oko1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |