ศุกร์ 13

แสดง list ของ ศุกร์ที่ 13 ตั้งแต่ปี 1900 ถึงปี 2012 ด้วย Mathematica

x = Reap[Do[If[#[[1]]==”Friday” && #[[2]]==”13″,Sow[#]]&@StringSplit@DateString[i,{“DayName”,” “,”Day”,” “,”Month”,” “,”Year”}],{i,1,3565900800,86400}]][[2,1]]

(* แสดงว่าในแต่ล่ะปีจะมีศุกร์ 13 อย่างน้อย 1 ครั้ง *)
Union@ToExpression@x[[All, 4]] == Range[1900, 2012]
True

(* ลอง plot histogram ดู *)
Histogram[ToExpression@x[[All,4]],Length@x,PlotLabel->”# of Friday 13^th in each year\n(from 1900 to 2012)”,PlotRange->{0,4},ColorFunction->”Rainbow”]

%d bloggers like this: