Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
VFP beats out C#, Python, others in challenge
Message
De
11/06/2004 22:33:37
Walter Meester
HoogkarspelPays-Bas
 
Information générale
Forum:
Visual FoxPro
Catégorie:
ActiveVFP
Divers
Thread ID:
00912565
Message ID:
00912966
Vues:
17
Hi claude,

Just looking at this problem, I think it could be optimized even more.
But honestly, I don´t know if this implementation is 100% according specs.

BTW, the text.txt is just a copy of the words they listed on the site.

Walter,
CREATE CURSOR Words (Word C(39))
APPEND FROM text.txt CSV
REPLACE ALL Word WITH UPPER(Word)
INDEX ON Word TAG word

CREATE CURSOR KeyCodes (Code C(1), Chars C(4))
INSERT INTO KeyCodes VALUES ("2", "ABC")
INSERT INTO KeyCodes VALUES ("3", "DEF")
INSERT INTO KeyCodes VALUES ("4", "GHI")
INSERT INTO KeyCodes VALUES ("5", "JKL")
INSERT INTO KeyCodes VALUES ("6", "MNO")
INSERT INTO KeyCodes VALUES ("7", "PQRS")
INSERT INTO KeyCodes VALUES ("8", "TUV")
INSERT INTO KeyCodes VALUES ("9", "WXYZ")
INDEX ON Code TAG Code

cPhonenumber = "642-394-6369"
cPhonenumber = STRTRAN(cPhoneNumber, "-","")
cLen = STR(LEN(cPhonenumber)+1)

CREATE CURSOR Results (Word C(&cLen))

nSec = SECONDS()
SELECT KeyCodes
GetWords(cPhoneNumber,"","")
? SECONDS() - nSec

SELECT Results
BROWSE NORM
RETURN

PROCEDURE GetWords (cUncoded, cCoded, cWordpart)
LOCAL nT, cChar, cChars

DO CASE
	CASE EMPTY(cUnCoded) AND (EMPTY(cWordPart) OR KEYMATCH(cWordPart+" ",1,"Words"))
		INSERT INTO Results VALUES (cCoded+cUncoded)
	
	CASE !EMPTY(cUncoded)
		=(EMPTY(cWordPart) OR SEEK(cWordPart+" ","Words")) AND ;
			GetWords(SUBSTR(cUnCoded,2), cCoded+LEFT(cUnCoded,1), "") 
	
		cChars = ALLTRIM(LOOKUP(Chars,LEFT(cUncoded,1),code,"Code"))
		FOR nT = 1 TO LEN(cChars)
			cChar = SUBSTR(cChars, nT, 1)
			= KEYMATCH(cWordPart+cChar,1,"Words") AND ;
				GetWords(SUBSTR(cUnCoded,2), cCoded+cChar, cWordPart+cChar)
                ENDFOR
ENDCASE
RETURN
>Just thought I'd pass this URL along:
>http://www.calvinhsia.com/default.asp?Page=Phone
>Calvin's solution was in VFP and he won (and it looks like he did it in the shortest amount of time). The demo page is setup as a VFP mtdll called from ASP. This is a great example why, IMHO, VFP has an important place on the web...
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform