Created
October 23, 2020 06:57
-
-
Save madhoshyagnik/5794b476a28e6c138278d7a59be09e3c to your computer and use it in GitHub Desktop.
challange problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Python Data Structures - A Game-Based Approach | |
Reading a maze from a text file | |
Robin Andrews - https://compucademy.net/ | |
""" | |
def read_maze(file_name): | |
""" | |
Reads a maze stored in a text file and returns a 2d list containing the maze representation. | |
""" | |
try: | |
with open(file_name) as fh: | |
maze = [[char for char in line.strip("\n")] for line in fh] | |
num_cols_top_row = len(maze[0]) | |
for row in maze: | |
if len(row) != num_cols_top_row: | |
print("The maze is not rectangular.") | |
raise SystemExit | |
return maze | |
except OSError: | |
print("There is a problem with the file you have selected.") | |
raise SystemExit | |
if __name__ == "__main__": | |
maze = read_maze("mazes/challenge_maze.txt") | |
for row in maze: | |
print(row) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
using System;
class Program
{
static void Main() {
int[][] jagged = new int[4][];
// set row 1
jagged[0] = new int[2];
jagged[0][0] = 10;
jagged[0][1] = 11;
// set row 2
jagged[1] = new int[1];
jagged[1][0] = 55;
// set row 3
jagged[2] = new int[4];
jagged[2][0] = 70;
jagged[2][1] = 23;
jagged[2][2] = 33;
jagged[2][3] = 56;
// set row 4
jagged[3] = new int[1];
jagged[3][0] = 69;
Console.WriteLine("At row 3, col 2 "+jagged[2][1]);
}