Skip to content

Instantly share code, notes, and snippets.

@madhoshyagnik
Created October 23, 2020 06:57
Show Gist options
  • Save madhoshyagnik/5794b476a28e6c138278d7a59be09e3c to your computer and use it in GitHub Desktop.
Save madhoshyagnik/5794b476a28e6c138278d7a59be09e3c to your computer and use it in GitHub Desktop.
challange problem
"""
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)
@madhoshyagnik
Copy link
Author

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]);

}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment