עבור לתוכן

לולאות for ב#C

Featured Replies

פורסם

יותר טוב, אבל כאמור ה-Shuffle שלך עדיין שגוי.

על איזה קוד התבססת? (אני מניח שלקחת קוד מאיפשהו באינטרנט)

  • תגובות 37
  • צפיות 3.4k
  • נוצר
  • תגובה אחרונה
פורסם
  • מחבר

אשמח אם תגיד לי למה הוא שגוי.

חלק לקחתי מכאן וחלק ניסיתי לשכתב לבד. (את מה שבסוגריים לקחתי משם ואת מה שבבלוק ניסיתי לכתוב על פי הרעיון שמודגם שם).

פורסם

שים לב מה הפרמטר שהם מעבירים ל-Random.Next ומה אתה מעביר לו.

פורסם
  • מחבר

1.זה כל הטעות שלי? או שיש עוד משהו?

2.למה באמת עדיך לשים את i ולא כמו שאני עשיתי?

תודה.

נ.ב. מצטר שאני משגע אתכם עם כל השאלות (ולא רק בדיון הזה), אבל אני פשוט רוצה להבין הכל ולא סתם לכתוב מה שאומרים לי.

פורסם

1. זהו.

2. כי רק ככה זה עושה באמת הגרלה אחידה - הסיכוי לקבל כל תוצאה אפשרית של ערבוב הקלפים הוא שווה. יש בויקיפדיה הסבר קצת יותר מעמיק (הוא דורש קצת הבנה בקומבינטוריקה):

http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#Implementation_errors

Similarly, always selecting j from the entire range of valid array indices on every iteration also produces a result which is biased, albeit less obviously so. This can be seen from the fact that doing so yields nn distinct possible sequences of swaps, whereas there are only n! possible permutations of an n-element array. Since nn can never be evenly divisible by n! when n > 2 (as the latter is divisible by n−1, which shares no prime factors with n), some permutations must be produced by more of the nn sequences of swaps than others. As a concrete example of this bias, observe the distribution of possible outcomes of shuffling a three-element array [1, 2, 3]. There are 6 possible permutations of this array (3! = 6), but the algorithm produces 27 possible shuffles (33 = 27). In this case, [1, 2, 3], [3, 1, 2], and [3, 2, 1] each result from 4 of the 27 shuffles, while each of the remaining 3 permutations occurs in 5 of the 27 shuffles.

פורסם
  • מחבר

אוקיי, תודה

ולגבי התיבת טקסט המסומנת יש משהו לעשות?

פורסם
  • מחבר

תודה רבה!!!

אני חושב שסוף סוף התרגיל מושלם.

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים