FizzBuzz · فيزباز
FizzBuzz
The classic. Walk the numbers 1 to n and, for each, decide what string to add to a list:
- divisible by both 3 and 5 →
FizzBuzz - divisible by 3 →
Fizz - divisible by 5 →
Buzz - otherwise → the number itself, as a string
Check the "both" case first, or a multiple of 15 will be caught by the 3 test alone.
فيزازبوز
الكلاسيكية. مرر الأرقام من 1 إلى n، ولكل رقم، حدد ما إذا كان يجب إضافة نص معين إلى القائمة:
- قابل للقسم على كلا 3 و5 →
FizzBuzz - قابل للقسم على 3 →
Fizz - قابل للقسم على 5 →
Buzz - غير ذلك → الرقم نفسه كسلسلة نصية
تحقق من حالة "كلا" أولاً، وإلا سيتم التقاط مضاعفات 15 بواسطة اختبار 3 وحده.
Write fizzbuzz(n) returning a list for the numbers 1..n: Fizz if divisible by 3, Buzz if by 5, FizzBuzz if by both, otherwise the number as a string. · اكتب fizzbuzz(n) تُرجع قائمة للأرقام 1..n: Fizz إذا كان قابلاً للقسمة على 3، Buzz إذا كان على 5، FizzBuzz إذا كان على الاثنين معاً، وإلا الرقم كنص.
Click Run to see the output here. · اضغط تشغيل لرؤية المخرجات هنا.