I am always interested to participate in code competition. Recently I solved one puzzle like that.
Puzzle
Develop an algorithm to display the day of the week (Sunday to Saturday) for a given date. For example, if the date given is 07/07/2008 (8th July 2008, dd/mm/yyyy format), the algorithm would return Monday. Date 29/02/2008 will return Friday.
Solution - 4test code
[+] testcase Puzzle_4Test (STRING sGivenDate) appstate none [ ] // Puzzle: [ ] // Develop an alogrithm to display the day of the week (Sunday to Saturday) for a given date. [ ] // For example, if the date given is 07/07/2008 (8th July 2008, dd/mm/yyyy format), the algorithm would return Monday. [ ] // Date 29/02/2008 will return Friday. [ ] INTEGER iGivenYear, iGivenMonth, iGivenDay [ ] DATETIME dtFormat [ ] STRING sResult [ ] [ ] STRING sSeperator = "/" [ ] STRING sFormatRequired = "dddd" // To get the day in word [ ] [+] do [ ] [ ] iGivenDay = Val (GetField (sGivenDate,sSeperator,1)) [ ] iGivenMonth = Val (GetField (sGivenDate,sSeperator,2)) [ ] iGivenYear = Val (GetField (sGivenDate,sSeperator,3)) [ ] [ ] dtFormat = MakeDateTime (iGivenYear,iGivenMonth, iGivenDay) [ ] sResult = FormatDateTime (dtFormat,sFormatRequired) [ ] Print ("Puzzle1: Input - {sGivenDate}: Result - {sResult}") [+] except [ ] LogError ("Puzzle1: Input - {sGivenDate} is not in expected Format dd/mm/yyyy")
2 comments:
Hey,
Thanks a lot man.....
Even I am working with SILK.....
I need to subtract a value from an year and your blog gave me the right hint at the right time...
Please do share your puzzels with me
mail ID ravisankarb4u@rediffmail.com
Thanks Once Again.....
-Ravi
Hi..
Thanks alot......
ur post is very usefull for all testers........
Thanks.......
Post a Comment