/* Enigma Number 1574 (Doubly square dates) in Picat. From New Scientist http://www.newscientist.com/article/mg20427370.400-enigma-number-1574.html """ 02 December 2009 by Richard England Doubly square dates 4 April 2001 was the first doubly square date of the century because whether written in the order day.month.year or in the order month.day.year (in each instance with two digits for each element) it comes out as 04.04.01, and 40401 is 201^2. Still with two digits for each element, there are some doubly square dates for which the square that comes from the order day.month.year is not the same as the square that comes from the order month.day.year. This is the case for each of the next two doubly square dates after 4 April 2001. What are those two dates (in the same form as 4 April 2001)? """ The two dates are: 2009-04-12 and 2009-12-04, i.e 12 April 2009 and 4 December 2009 This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go ?=> N = 6, DayMonthYearA = new_list(N), DayMonthYearA :: 0..99, MonthDayYearA = new_list(N), MonthDayYearA :: 0..99, Day :: 1..12, % Must be 1..12 since we can write DDMMYY and MMDDYY Month :: 1..12, Year :: 0..99, MonthDayYear :: 40401 ..123199, DayMonthYear :: 40401 ..311299, fd_min_max(MonthDayYear,Min1,Max1), fd_min_max(DayMonthYear,Min2,Max2), Y1 :: ceiling(sqrt(Min1))..ceiling(sqrt(Max1)), Y2 :: ceiling(sqrt(Min2))..ceiling(sqrt(Max2)), Y1 #> 0, Y2 #> 0, % we don't allow month == day Month #!= Day, % check the squares Y1*Y1 #= MonthDayYear, Y2*Y2 #= DayMonthYear, to_num(MonthDayYearA, MonthDayYear), to_num(DayMonthYearA, DayMonthYear), to_num([DayMonthYearA[I] : I in 1..2], Day), to_num([DayMonthYearA[I] : I in 3..4], Month), to_num([DayMonthYearA[I] : I in 5..6], Year), to_num([MonthDayYearA[I] : I in 1..2], Month), to_num([MonthDayYearA[I] : I in 3..4], Day), to_num([MonthDayYearA[I] : I in 5..6], Year), Vars = DayMonthYearA ++ MonthDayYearA ++ [Day,Month,Year], solve($[constr,split],Vars), println([Year,Month,Day]), % println([y1=Y1,y2=Y2]), % println(dayMonthYear=DayMonthYear), % println(monthDayYear=MonthDayYear), % nl, fail, nl. go => true. % % converts a number Num to/from a list of integer List given a base Base % to_num(List, Num) => Len = length(List), Num #= sum([List[I]*10**(Len-I) : I in 1..Len]).