Maybe something like ..
STORE CAST(0 AS I) TO lnCheck
lcDtString = STRCONV(DTOS(DATE()), 12)
=ALINES(laValues, m.lcDtString, 0, CHR(0))
FOR lnPosn = 1 TO 8
STORE VAL(laValues(m.lnPosn)) TO lnVal
? lnVal
IF BITTEST(m.lnCheck, m.lnVal)
*- Have a duplicate number - do what ever
=MESSAGEBOX(laValues(m.lnPosn) + " appears more than once.")
EXIT
ELSE
STORE BITSET(m.lnCheck, m.lnVal) TO lnCheck
ENDIF
ENDFOR
-----Original Message----- From: ProfoxTech [mailto:profoxtech-bounces@leafe.com] On Behalf Of Gene Wirchenko Sent: Monday, 18 July 2016 2:29 AM To: profoxtech@leafe.com Subject: Checking for All-Different Characters
Hello:
I write a logic/math puzzle each week. They appear in my blog (http://genew.ca/) and two local newspapers.
Here is the latest problem:
"Consider a date in YYYY-MM-DD format. What is the next date where all eight digits will be different?"
I solved this by hand. I decided to verify my solution with a program. I often cook up something in GW-BASIC, but since VFP has date functions, I decided to go with it.
It was very easy to set up the framework of the loop. What threw me for a loop is how to check that all of the digits are different. I ended up converting the date to string with dtos() and then testing the string with a rather ugly-looking condition. Is there something faster?
***** Start of Code ***** * 16s-16.prg * Date Puzzle * Last Modification: 2016-07-17 * * Consider a date in YYYY-MM-DD format. What is the next date where all * eight digits will be different?
? "*** Execution begins." ? program() close all clear all
set talk off set exact on set century on set date ansi
*
local startdate startdate=date()
? "Start Date: "+transform(startdate)
local trydate, looping trydate=startdate looping=.t. do while looping
local trydtos trydtos=dtos(trydate) if right(trydtos,4)="0101" ? "Working on year "+left(trydtos,4) endif
if; iif("0"$trydtos,1,0)+; iif("1"$trydtos,1,0)+; iif("2"$trydtos,1,0)+; iif("3"$trydtos,1,0)+; iif("4"$trydtos,1,0)+; iif("5"$trydtos,1,0)+; iif("6"$trydtos,1,0)+; iif("7"$trydtos,1,0)+; iif("8"$trydtos,1,0)+; iif("9"$trydtos,1,0)#8 trydate=trydate+1 else && solution looping=.f. endif
enddo
? "Solution is "+transform(trydate)+"."
*
close all clear all ? "*** Execution ends." return ***** End of Code *****
Sincerely,
Gene Wirchenko
[excessive quoting removed by server]