Grids and Graphs

We’ve been asked to build some easter eggs for those using our software. These are some fun things and games that those who find it can enjoy.

The Challenge

In this challenge we’ll be using nested loops, multi-dimensional arrays, matrices, and grids. Focus first on solving the problem then on optimizing it.

Creating a Test Case

No matter the level you choose to work with write a test case before you start your code. Then write just enough code to pass the test. Once you have passing code refactor to pass other test cases. You’ll notice that not all of these challenges can easily be tested. Some you will have to see in order to test it.

Level 1 Ascii Art

   _______
  |.-----.|
  ||x . x||
  ||_.-._||
  `--)-(--`
 __[=== o]___
|:::::::::::|\
\-=========-\()

jgs

Image from www.asciiart.eu

Ascii art is images created using numbers letters and characters. You’ve been asked to create some diamond out of ‘*‘. Start by taking in an integer from the user. This will be the length of on of the sides. Then create and return the diamond with that number of ‘*‘ on each side.

1
2
3
4
5
6
7
8
9
Enter side length: 4
*
***
*****
*******
*****
***
*

Hint: You may need to use nested loops. Create the top half in one outer loop and the bottom half in another.

A Step Further

Going a step further, write an app that builds a face using ascii art. If you are feeling very fancy animate the face.

Level 2 Magic Squares

A magic square is a matrix of unique numbers starting at 1 and incrementing. The sums of each row, column, and the two diagonals are the same.

For this challenge you have been asked to take in user input for each row. Then check that each number is only used once and every number from 1 to the max is used. Next check if the sum of the rows, columns, and diagonals are the same. Tell the user if they have entered a magic square or not.

1
2
3
4
16 3 2 13
5 10 11 8
9 6 7 12
4 15 14 1

Hint: This may require using nested or multi-dimensional arrays.

A Step Further

Going a step further, build a magic square generator. Have the user input the max number for the matrix.

Level 3 Sudoku Generator

If you are not familiar with it Sudoku is a game played on a 9 x 9 grid broken into 9 sections of 3 x 3 mini-grids. To solve is enter the numbers 1-9 only once per column, row, and 3 x 3 grid. Each puzzle will have enough grids filled in to be able to logically solve the puzzle.

Image from Puzzle Stream

Build an app that will randomly generate a Sudoku grid with the correct starter numbers so that there is a correct solution. Allow the users to input their solution and check that it is correct.

Hint: Each puzzle has a unique solution. The game is about pattern matching not math.

A Step Further

To really give yourself a challenge build a Sudoku solver. The user will need to enter the location and value of each number provided on the grid. Then the program will return the solved grid.