Esempio n. 1
0
        static void runDownload(string[] args)
        {
            int level, id;

            if (getIntFlag(args, "level") != null || getIntFlag(args, "id") != null)
            {
                (level, id) = parseLevelAndId(args);
                (Sudoku.FromWebsudoku(level, id)).Print(Console.Out);
            }
            else
            {
                int n    = getIntFlag(args, "n") ?? 0;
                var rand = new Random();
                for (int i = 0; i < n; i++)
                {
                    level = rand.Next(4) + 1;
                    id    = rand.Next(short.MaxValue * 2);
                    Sudoku puzzle = Sudoku.FromWebsudoku(level, id);
                    Console.Out.WriteLine("//fetched from http://www.websudoku.com");
                    Console.Out.WriteLine($"//level: {level}, id: {id}");
                    puzzle.Print(Console.Out);
                    if (i < n - 1)
                    {
                        Console.Out.WriteLine();
                    }
                }
            }
        }
Esempio n. 2
0
        static void runSolve(string[] args)
        {
            List <Sudoku> puzzles = new List <Sudoku>();

            // require level and id if and only if one already exists
            if (getIntFlag(args, "level") != null || getIntFlag(args, "id") != null)
            {
                int level, id;
                (level, id) = parseLevelAndId(args);
                puzzles.Add(Sudoku.FromWebsudoku(level, id));
            }
            else
            { // otherwise read puzzles from stdin
                while (Console.In.Peek() != -1)
                {
                    puzzles.Add(Sudoku.FromTextReader(Console.In));
                }
            }

            for (int p = 0; p < puzzles.Count; p++)
            {
                if (puzzles[p].Solve())
                {
                    puzzles[p].Print(Console.Out);
                    if (p < puzzles.Count - 1)
                    {
                        Console.Out.WriteLine();
                    }
                }
                else
                {
                    Console.Error.WriteLine($"puzzle {p + 1} has no solution");
                }
            }
        }