Coder Social home page Coder Social logo

year-11-cs-unit-8-2d-arrays-quiz-magic-square's Introduction

Year-11-CS-Unit-8-2D-Arrays-Quiz-Magic-Square

Ensure that you read all instructions carefully. Do not include any additional methods that are not specified in this quiz description. Think carefully about your solution before writing any code. Use meaningful variable names and proper indentation - take pride in your work!

Task: In the MagicSquare class you will implement five methods.

  • checkSum: This method takes a 2D array of integers and returns the sum of the first row of the 2D array.
  • magicRows: This method takes a 2D array of integers and a checkSum and returns returns a boolean value depending on whether the sum of each row in the 2D array is equal to checkSum or not.
  • magicColumns: This method takes a 2D array of integers and a checkSum and returns returns a boolean value depending on whether the sum of each column in the 2D array is equal to checkSum or not.
  • magicDiagonals: This method takes a 2D array of integers and a checkSum and returns a boolean value depending on whether the sum of each of the main two diagonals in the 2D array is equal to checkSum or not.
  • isMagic: This method takes a 2D array of integers and returns a boolean value depending on whether the 2D array is magic or not.

Description: A magic square is one such that every row, every column, and both main diagonals add to the same value.

0,0 0,1 0,2
1,0 1,1 1,2
2,0 2,1 2,2
2 7 6
9 5 1
4 3 8

The sum of each row and each column and the main two diagonals all add to the value 15.

Row 1: [2,7,6] → 2 + 7 + 6 = 15

Row 2: [9,5,1] → 9 + 5 + 1 = 15

Row 3: [4,3,8] → 4 + 3 + 8 = 15

Column 1: [2,9,4] → 2 + 9 + 4 = 15

Column 2: [7,5,3] → 7 + 5 + 3 = 15

Column 3: [6,1,8] → 6 + 1 + 8 = 15

Main diagonal 1: [2,5,8] → 2 + 5 + 8 = 15

Main diagonal 2: [6,5,4] → 6 + 5 + 4 = 15


int[][] array2d = { {2,7,6}, {9,5,1}, {4,3,8} };

checkSum(array2d); → returns 15

magicRows(array2d, checkSum(array2d)); → returns true

magicColumns(array2d, checkSum(array2d)); → returns true

magicDiagonals(array2d, checkSum(array2d)); → returns true

isMagic(array2d); → returns true


Note that you solution must work for a 2D array of size n x n.

Note also that the 2D array will be a square. That is, it will have the same number of rows as columns, and all rows will be of the same length.

Good luck, have fun! =)

year-11-cs-unit-8-2d-arrays-quiz-magic-square's People

Contributors

techarenz avatar gravo-lan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.