Category: 1 SPL&Code
Eight Queens
The Eight Queens problem is a classic and well-known problem. Specifically, place eight queens on an 8×8 chessboard so that no two queens can attack each other, which means no two queens can be on the same row, the same column, or the same diagonal. The question is: how many solutions are there? A B C D 1 8 =[0]*A1 >i=1 2 for i>0 >B1(i)+=1 3 if B1(i)>A1 >B1(i)=0,i-=1 next 4 if i==1 && A1>1 >i=2 next 5 =B1(i) =B1.to(i-1) 6 if C5.pselect(~==B5|| i-# ==abs(B5-~)) next 7 if (i+=1)>A1 =@|B1.concat@c() >i-=1 8 =C7.len() http://try.scudata.com.cn/splx?4nr Consider each row of an N*N
Calculate the first N terms of the Fibonacci sequence
The Fibonacci sequence refers to a sequence of numbers: 1, 1, 2, 3, 5, 8, 13, 21, … This sequence starts from the third term, and each term is equal to the sum of the first two terms. Output the first N terms of this sequence (N>2). Define a sequence, assign the first two terms a value of 1, then loop N-2 times, taking the last and second to last terms respectively, and append their sum to the sequence. The result is the generated Fibonacci sequence. Using recursive algorithm: A B C 1 30 [1,1] 2 for A1-2 =B1.m(-1)+B1.m(-2) >B1|=B2







