לא עברתי על כל השאלות לאחרונה. יתכן שחלק לא קשורות למערכים.
כיצד לכתוב פתרון ל-Kata ב-Visual Studio:
- אחרי שלוחצים Train יפתח חלון ובו הבסיס לקוד הפתרון
ניקח לדוגמא את השאלה על ספירת כבשים
public static class Kata { public static string CountSheep(int n) { throw new NotImplementedException(); } }
- נעתיק את הקוד הזה לקובץ חדש של מחלקה (שניתן ליצור באמצעות Ctrl+Shift+A), או פשוט נדביק אותו מעל למחלקה Program, ככה:
namespace ConsoleApp31 { // מדביק מחוץ למחלקה Program public static class Kata { public static string CountSheep(int n) { throw new NotImplementedException(); // את השורה הזו נמחק } } internal class Program { static void Main(string[] args) { string res = Kata.CountSheep(5); // קריאה לפונקציה תוך שימוש בשם המחלקה Console.WriteLine(res); // :התחביר זהה לחלוטין לקריאה כאן, המוכרת לנו Console.ReadLine(); } } }
- ברגע שאנו מוכנים עם פתרון מלא, שבדקנו ונראה לנו תקין, נעתיק אותו בחזרה לתוך CodeWars
public static class Kata { public static string CountSheep(int n) { string result = ""; for (int i = 1; i <= n; i++) result += $"{i} sheep..."; return result; } }
כך זה נראה במקרה שיצרנו את המחלקה בקובץ נפרד:
9.2.1
9.2.2
How good are you really? | Codewars
9.2.3
9.2.4
9.2.5
9.2.6
9.2.7
Find the smallest integer in the array | Codewars
9.2.8
9.2.9
9.2.10 קשה
Sum of two lowest positive integers | Codewars