//VGR07052003 Création par portage de source Turbo-Pascal
//
// ----- Functions
function Recursion($par,$prev,&$resu,&$nb) {
// algorithm :
// if length>0 treat first char in a loop, call for the rest
// else memorize result and get out recursively
if (strlen($par)>0) {
switch ($par[0]) {
case 0 : $chars=array('0'); break;
case 1 : $chars=array('1'); break;
case 2 : $chars=array('A','B','C'); break;
case 3 : $chars=array('D','E','F'); break;
case 4 : $chars=array('G','H','I'); break; // 'I' should be out (confusion with 1)
case 5 : $chars=array('J','K','L'); break;
case 6 : $chars=array('M','N','O'); break; // 'O' should be out (confusion with 0)
case 7 : $chars=array('P','Q','R','S'); break;
case 8 : $chars=array('T','U','V'); break;
case 9 : $chars=array('W','X','Y','Z'); break;
} // switch/case of
foreach($chars as $char) { $newst=$prev.$char; Recursion(substr($par,1),$newst,$resu,$nb); }
} else { // result found
$resu[$nb]=$prev; // substr($resu[$nb-1],0,strlen($resu[$nb-1])-1);
$nb++;
}
} // Recursion Procedure
function DoIt($tel) {
$resu=array();
$nb=0;
Recursion($tel,"",$resu,$nb);
return $resu;
} // DoIt Array Function
// ----- MAIN
$numtel='4143';
$result=DoIt($numtel); // $result initialized in DoIt()
$nbres=count($result);
echo "number $numtel<BR>";
echo "$nbres combinations : <BR>";
for ($i=0;$i<$nbres;$i++) echo $result[$i].'<br>';

Ce code, bien que moins élégant que son original en Pascal, est encore plus élégant que la version C++ (comme d'habitude...) que vous trouverez à http://www.dreamincode.net/forums/showtopic50805.htm from zoom2ashish (Ashish Patel ) "Converting Telephone Numbers To Letters With All Combinations" on 21 Apr, 2009 - 12:25 PM for a 2 May, 2008 question.
Remarque importante : apparemment, malgré l'usage de cette technique depuis octobre 1912 (du moins en France, "Gutemberg 1225" ou le fameux "ODEon 84.00"), quelqu'un(*) a osé tenter de déposer un brevet en 1999 !!! ((WO/2001/011849) CODING TELEPHONE NUMBERS AND CIPHERS WITH LETTERS)
Je suis certain que mettre MON code de 1983 dans le domaine public n'enfreint aucun brevet ni marque déposée ;-))
(54) Title (EN): CODING TELEPHONE NUMBERS AND CIPHERS WITH LETTERS
(54) Title (FR): CODAGE DE NUMEROS DE TELEPHONE ET DE CHIFFRES AVEC DES LETTRES
(*) des Chinois partiellement établis en France, un comble.
Aux E.U.A. cet usage est apparu à la fin des 70s à l'arrivée des "1-800-FLOWERS" et autres "Telephone mnemonics" ou "vanity numbers").
Bien sûr, ce code ne trouve pas des ***mots*** : il crache simplement les combinaisons possibles : à vous d'en tirer des mots ;-)
Cordialement,

Althought uglier than the original Pascal version, this PHP code fragment is more elegant (as usual ;-) than the C++ version that you may find at http://www.dreamincode.net/forums/showtopic50805.htm from zoom2ashish (Ashish Patel ) "Converting Telephone Numbers To Letters With All Combinations" on 21 Apr, 2009 - 12:25 PM for a 2 May, 2008 question.
Important Caveat : apparently, despite the use of this since October 1912 (at least in France, "Gutemberg 1225" or "ODEon 84.00"), someone(*) dared to try to depose a patent on a similar technique ! ((WO/2001/011849) CODING TELEPHONE NUMBERS AND CIPHERS WITH LETTERS) on 04/10/1999.
My code being from 1983, I think I don't infringe any patent showing it to the general public ;-)))
(54) Title (EN): CODING TELEPHONE NUMBERS AND CIPHERS WITH LETTERS
(54) Title (FR): CODAGE DE NUMEROS DE TELEPHONE ET DE CHIFFRES AVEC DES LETTRES
(*) des Chinois partiellement établis en France, un comble.
The use in the U.S.A. seems to date from the appearance of the 800- numbers in the late 1970's ("1-800-FLOWERS", so-called "Telephone mnemonics" or "vanity numbers"). You may read http://findarticles.com/p/articles/mi_qa3736/is_199901/ai_n8847105/
Of course, this code doesn't search for ***words*** in a dictionary ; it simply spits out the ***combinations*** : it's up to you to get words out of it ;-)
Best regards,
for European Experts Exchange and Edaìn Works back to list of test scripts
Last update 2009-10-30 09:19:53
| Add This Article To: | |||
| |
|
|
|
| |
|
|
|