/* All different date in Picat. From Chris Smith https://twitter.com/aap03102/status/1276014721108451329/photo/1 """ I was only six years old at the time so I probably didn't appreciate that 33 years ago today (25th June 1987) was a pretty special day. The digits in the data 25/06/1987 [i.e. 1987-06-25] were all different. When will this happen next? """ The next all different date is: 2345-06-17 Here are the next few all different dates: 2345-06-17 2345-06-18 2345-06-19 2345-07-16 2345-07-18 2345-07-19 2345-08-16 2345-08-17 2345-08-19 2345-09-16 2345-09-17 2345-09-18 2346-05-17 There are 44580 all different dates after 1987-06-25 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 ?=> Year :: 1988..9999, YearL = new_list(4), YearL :: 0..9, to_num(YearL,10,Year), Month :: 1..12, MonthL = new_list(2), MonthL :: 0..9, to_num(MonthL,10,Month), Day :: 1..31, DayL = new_list(2), DayL :: 0..9, to_num(DayL,10,Day), % YYYYMMDD Date = YearL ++ MonthL ++ DayL, all_different(Date), % Days in a month DayMonth = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ], element(Month,DayMonth,MaxDays), % Check leap year: leap_year(Year,LeapYear), (LeapYear #= 1 #/\ Month #= 2) #=> Day #<= 29, % leap year LeapYear #= 0 #=> Day #<= MaxDays, % not a leap year % Test leap year % Month #= 2, LeapYear #= 1, Day #= 28, Vars = Date ++ [Year,Month,Day], solve(Vars), printf("%4d-%02d-%02d\n",Year,Month,Day), fail, nl. go => true. leap_year(Year, B) => B :: 0..1, ( (Year mod 4 #= 0 #/\ Year mod 100 #!= 0) #\/ (Year mod 400 #= 0) ) #<=> B #= 1. % % converts a number Num to/from a list of integer List given a base Base % to_num(List, Base, Num) => Len = length(List), Num #= sum([List[I]*Base**(Len-I) : I in 1..Len]).