Main Thread
In 3×3 board, if queens(3) should be 0, then why [0,2,1], [1,0,2], [1,2,0] and [2,0,1] are not legal orders?
Hi,
Take the first example of [0,2,1]:
[*,-,-]
[-,-,*]
[-,*,-]
As you can see, the last 2 queens stand in the same diagonal line from each other.
The same happens in the other examples you mentioned.
Nobody except my "queens_rec" method use the "partial" list.
Can I save there something else than the rows numbers?
What else would you want to save in partial?
There is no need to save anything other than a legal arrangement in it.
can i define a empty list before the queens_rec like this?:
def queens(N): ''' how many ways to place n queens on an NXN board? ''' partial = [] # list representing partial placement of queens on the left columns return (queens_rec(N,partial)) index=[] def queens_rec(N, partial):
You can simply use the first parameter of queens_rec for that.
מותר לכתוב פונקציית עזר שמקבלת ערכים שונים ממה שכתוב בהמלצה בסעיף d?
אילו ערכים אחרים היית רוצה להעביר?
המידע שנחוץ כדי לבדוק אפשרות הרחבה של סידור חוקי לטור הבא הוא הסידור (החוקי) הנוכחי והשורה בה רוצים להציב מלכה בטור הבא.
Is it possible to use:
import sys
sys.setrecursionlimit(10000)
to increase the maximum recursion depth exception?
No, you cannot change it.
hint: the recursion depth in your solution should be N, so you really don't need to change it.
About the recursive function we have to write;
If I give it a list, 'partial', it has to return the number of ways I can arrange the empty columns (the right ones) based on what already there is in the first K columns (the left ones) ?
Is that exactly what it should do ?
The recursive function should in the end return the number of legal arrangements on the board.
Is it OK to write an additional utility function besides the one that verifies if we can expand in a certain row?(the suggested one)
השתמשתי בקאונטר גלובאלי בפונקציה הפנימית. מותר להוסיף לפונקצית המעטפת שורה שתאפס אותו? אחרת המונה פשוט יוסיף לערכו הקודם בכל מימוש.
לא, אין לשנות את queens, אלא רק להשלים את queens_rec.
הכוונה: אין צורך בעוד משתנים. המידע שמועבר לפונקציה הרקורסיבית (partial ו- N) מספיקים, כי הרי הפונקציה הפנימית צריכה רק לדעת מהו הסידור החוקי החלקי עד כה, ומהו גודל הלוח המקורי.
האם יכול להיות קלט של N=0? אם כן, מה צריכה הפונקציה להחזיר עבורו?
תודה.