f 1=[1]f n|x<-f$n-1=last[k|k<-[1..n],p<-[1..n],k*p<n,take(k*p)x==([1..k]>>take p x)]:xg=reverse.f main = print $ g 30
Standard input is empty
[1,1,2,1,1,2,2,2,3,1,1,2,1,1,2,2,2,3,2,1,1,2,1,1,2,2,2,3,1,1]
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!