npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

magic-squares-generator

v0.3.1

Published

A Node.js package to generate and print magic squares.

Downloads

20

Readme

NPM Version

__/\\\\____________/\\\\___________/\\\\\\\\\\\__________/\\\________/\\\________/\\\_____/\\\\\\\\\_______/\\\\\\\\\______/\\\\\\\\\\\\\\\_____/\\\\\\\\\\\_________________/\\\\\\\______________/\\\\\\\\\\_____________/\\\_        
 _\/\\\\\\________/\\\\\\_________/\\\/////////\\\_____/\\\\/\\\\____\/\\\_______\/\\\___/\\\\\\\\\\\\\___/\\\///////\\\___\/\\\///////////____/\\\/////////\\\_____________/\\\/////\\\__________/\\\///////\\\________/\\\\\\\_       
  _\/\\\//\\\____/\\\//\\\________\//\\\______\///____/\\\//\////\\\__\/\\\_______\/\\\__/\\\/////////\\\_\/\\\_____\/\\\___\/\\\______________\//\\\______\///_____________/\\\____\//\\\________\///______/\\\________\/////\\\_      
   _\/\\\\///\\\/\\\/_\/\\\_________\////\\\__________/\\\______\//\\\_\/\\\_______\/\\\_\/\\\_______\/\\\_\/\\\\\\\\\\\/____\/\\\\\\\\\\\_______\////\\\___________________\/\\\_____\/\\\_______________/\\\//_____________\/\\\_     
    _\/\\\__\///\\\/___\/\\\____________\////\\\______\//\\\______/\\\__\/\\\_______\/\\\_\/\\\\\\\\\\\\\\\_\/\\\//////\\\____\/\\\///////___________\////\\\________________\/\\\_____\/\\\______________\////\\\____________\/\\\_    
     _\/\\\____\///_____\/\\\_______________\////\\\____\///\\\\/\\\\/___\/\\\_______\/\\\_\/\\\/////////\\\_\/\\\____\//\\\___\/\\\_____________________\////\\\_____________\/\\\_____\/\\\_________________\//\\\___________\/\\\_   
      _\/\\\_____________\/\\\________/\\\______\//\\\_____\////\\\//_____\//\\\______/\\\__\/\\\_______\/\\\_\/\\\_____\//\\\__\/\\\______________/\\\______\//\\\____________\//\\\____/\\\_________/\\\______/\\\____________\/\\\_  
       _\/\\\_____________\/\\\__/\\\_\///\\\\\\\\\\\/_________\///\\\\\\___\///\\\\\\\\\/___\/\\\_______\/\\\_\/\\\______\//\\\_\/\\\\\\\\\\\\\\\_\///\\\\\\\\\\\/______________\///\\\\\\\/____/\\\_\///\\\\\\\\\/____/\\\_____\/\\\_ 
        _\///______________\///__\///____\///////////_____________\//////______\/////////_____\///________\///__\///________\///__\///////////////____\///////////__________________\///////_____\///____\/////////_____\///______\///_

Magic Square Generator

Overview

The Magic Square Generator is a Node.js package designed to create magic squares of odd and doubly even orders, as well as verify the magic square property of given square matrices. A magic square is a grid of numbers where the sums of the numbers in each row, column, and the main diagonals all add up to the same constant. This package offers a simple interface to generate and validate these fascinating mathematical objects easily.

Installation

To add the Magic Square Generator to your project, use the following npm command:

npm install magic-squares-generator --save

This command will download and install the package, making it ready to use in your Node.js applications.

Usage

After installation, you can generate and print magic squares by importing the package and calling its functions. Here's a simple example to get you started:

const { generateMagicSquare, printMagicSquare, isMagicSquare } = require('magic-squares-generator');

// Generate a magic square of order 5
const n = 5;
const square = generateMagicSquare(n);

// Print the generated magic square
console.log("Generated Magic Square:");
printMagicSquare(square);

// Checks if a square is magic 
console.log('Is Magic Square:', isMagicSquare(square)); // This will print true or false

This code snippet generates a 5x5 magic square, prints it to the console, and then verifies if the generated square is indeed a magic square.

API Reference

generateMagicSquare(n) Generates a magic square of order n. The order n can be any odd number or a doubly even number (divisible by 4).

  • Parameters: n (number) - The order of the magic square.
  • Returns: A 2D array representing the generated magic square.

printMagicSquare(square) Prints a given magic square to the console in a formatted manner.

  • Parameters: square (Array<Array>) - A 2D array representing a magic square.

isMagicSquare(square) Determines whether a given square matrix is a magic square.

  • Parameters: square (Array<Array>) - A 2D array representing a square matrix.
  • Returns: true if the square is a magic square, otherwise false.

Contributing

Contributions to the Magic Square Generator are welcome! Please feel free to submit issues, pull requests, or suggestions to improve the package.

License

This project is licensed under the MIT License - see the LICENSE file for details.