Blog

Latin Square of English Alphabets in C++

While teaching programming in C++ to a student from USA, I encountered an assignment given to him based on the array in which it was asked to produce a latin square of English alphabets. Basically a latin square consists of sets of the numbers/characters arranged in such a way that no orthogonal (row or column) contains the same number/character twice. So naturally it can be implemented with the help of a two-dimensional array having equal number of rows and columns. The challange is to generate a random set of alphabets so that the same alphabet should not be present in same row and column. For example if the size of the square is 2 then a latin square can be any one of the following:

AB
BA

OR

BA
AB

Similarly if the size is 3 then it can be any one of the following:

CBA
ACB
BAC

OR

ABC
CAB
BCA

OR

BAC
CBA
ACB

In order to implement this program, I used the rand() function to generate a random number like below:

ch = rand() % SIZE + 1; //Randon number between 1 to SIZE

In order to make this rand() function working I called the function srand(time(0)); in the very beginning of the main function.

Then to make sure that every alphabet added to the array is unique in its row as well as in its column, I used two variables found_in_row and found_in_column. When a alphabet is found either in current row or in current column then the alphabets in current row are filled up again with another set of random alphabets. This process is done till the randomly generated alphabet becomes unique in current row and column. Using this type of iteration, a latin square of a given size is generated with English alphabets. Here is the complete code for reference:

#include<iostream>
#include<time.h>
using namespace std;

int main()
{
    srand(time(0));
    const int SIZE = 3;
    char arr[SIZE][SIZE];
    char ch;
    bool found_in_row, found_in_column;
    for (int i = 0; i < SIZE; i++)
    {
        col:
        for (int j = 0; j < SIZE; j++)
        {
            while (true)
            {
                found_in_row = false;
                found_in_column = false;
                ch = rand() % SIZE + 1; // 1-3

                for (int k = 0; k < j; k++) // row
                {
                    if (arr[i][k] == (ch + 64))
                    {
                        found_in_row = true;
                        break;
                    }
                }

                for (int k = 0; k < i; k++) //column
                {
                    if (arr[k][j] == (ch + 64))
                    {
                        found_in_column = true;
                        break;
                    }
                }
                if(found_in_column || found_in_row) goto col;
                if (found_in_row == false && found_in_column==false ) break;
            }
            arr[i][j] = ch + 64;
        }
    }
    
    for (int i = 0; i < SIZE; i++)
    {
        for (int j = 0; j < SIZE; j++)
        {
            cout << arr[i][j];
        }
        cout << endl;
    }
    
    return 0;
}

 

Role of max_input_vars in php.ini

Today while working on a project, after submitting a form, the array $_POST was not displaying value of all variables of the form. Since the method of the form was POST and so first of all I increased the value of the parameter post_max_size in php.ini file. But even after that the array $_POST was not storing value of all variables. Then I started looking for all other parameters related to variables in php.ini. I found that the value of the parameter max_input_vars was set to 1000. So due to this, the array $_POST was containing the value of first 1000 variables only. I then increased this value to 3000. Then the program started working perfectly. So while changing the value of post_max_size we should also check the value of max_input_vars parameter in php.ini file.

Launch of PoonamKalam.in

It is a great privilege and honor for me that I got opportunity to develop a website for a great personality in the world of Hindi literature respected Poonam Madam (https://www.facebook.com/ajaypunamsingh). Recently I read her poem in the "Aajkal" magzine. She has written several stories and poems in various magazines. I have developed her website (https://poonamkalam.in/) in the simplest CMS of the world namely GetSimpleCMS (http://get-simple.info/). I have selected this CMS due to its simplicity. It is really very exciting experience while using this CMS to see how simply the facility to develop and update a website have been provided in this environment. It is as much customizable as  its simplicity. I think that due the simplicity of this CMS, after few attempts our most respected Ajay Sir (https://www.facebook.com/profile.php?id=100011021826523) will be able to update the content of this website himself.
 

Simplest CMS

While searching for a simple CMS in PHP, I encountered a CMS at http://get-simple.info/ whose slogan is "The Simplest Content Management System. Ever.". I just downloaded it and tested it on my local system. I realized that it is really the simplest CMS of the world. I quickly configured the website of a school using this CMS which can be seen at https://nunuvatipublicschool.org/. Then I also installed this CMS on this website. The admin section of this CMS is very much simple and intuitive. I have seen its code and it is following the coding style of WordPress but it has made the WordPress much more simpler. I am planning to extend features of this CMS by developing plugins and themes for it. I love the possibility of customization of this CMS and have started to offer a introductory website to my hosting customers. If you also want to set up a website with all basic functionalities in 5 minutes then you must try it.

Share:  Add to Facebook Tweet This Add to Delicious Submit to Digg Stumble This

Published on  December 18th, 2019

Quick Notes

  • cat man displays the content of man
  • man cat displays the manual of cat
  • date displays both date and time
  • vi is visual editor in text mode