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
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/
** All postings, unless explicitly stated otherwise, are the opinions of the
author, and do not constitute legal or medical advice. This statement is added
to the messages for those lawyers who are too stupid to see the obvious.