Saturday, July 9, 2016

My First Python Program

Hi Folks,

Greetings to all of you. I haven't post anything since a long time. I am passionate about learning new things. In the due course, I started to learn another programming language "Python". I heard a lot of buzz about this due to the Data Analytics.

Anyway, I am just taking the baby steps towards a big journey. During my baby steps, I tried to write a python program which demonstrates the basic arithmetic operations on integers. Below is the program.

# !/usr/bin/python

#################################################################################
# Program   : IntMathOpsDemo                                                              #
# Purpose    : Demonstrate the Basic Arithmetic Operations on Integers using sub-routines #
#             ( Addition, Subtraction, Multiplication and Division which also supports    #
#             Exception Handling of ZeroDivideError)                                      #
# Author    : Kamesh Akundi                                                               #
# Date      : 08th July, 2016                                                             #
#################################################################################


# sub-routine to add two integers
def addition(a, b) -> object:
    if a == 0:
        return b
    elif b == 0:
        return a
    else:
        return a + b


# sub-routine to subtract two integers
def subtraction(a, b):
    if a == 0:
        return -1 * b
    elif b == 0:
        return a
    else:
        return a - b


# sub-routine to multiply two integers
def multiplication(a, b):
    if a == 1:
        return b
    elif b == 1:
        return a
    else:
        return a * b


# sub-routine to divide two integers
def division(a, b):
    try:
        if a == 0:
            return 0
        else:
            return a / b
    except ZeroDivisionError:
        err_msg = 'Division with Zero Denominator is an Error!'
        return err_msg


# sub-routine to divide two integers
def modulos_division(a, b):
    try:
        if a == 0:
            return 0
        else:
            return a % b
    except ZeroDivisionError:
        err_msg = 'Modulo with Zero is an Error!'
        return err_msg


# sub-routine to call all the operations
def demo_operations(a, b):
    print("Sum of ", a, ",", b, "is :", addition(a, b))
    print("Difference between ", a, ",", b, "is :", subtraction(a, b))
    print("Product of ", a, ",", b, "is :", multiplication(a, b))
    print("Dividend of ", a, ",", b, "is :", division(a, b))
    print("Remainder of ", a, ",", b, "is :", modulos_division(a, b))


# main routine to demonstrate the integer arithmetic operations
while True:
    try:
        x = input("Enter a number: ")
        a = int(x)
        break
    except ValueError:
        print(x, " is not a valid integer!")

while True:
    try:
        y = input("Enter another number: ")
        b = int(y)
        break
    except ValueError:
        print(y, " is not a valid integer!")
print('================================================================\n')
print('You entered two integers', a, b)
print('\nNow it is good to proceed with Arithmetic Operations...\n')
print('================================================================\n')
print('Results are:')
demo_operations(a, b)

Monday, October 20, 2014

Is India Secular ?

After watching the Result Day Live show, I was gazing at the green vegetation of Chandaka Elephant Reserve and was about take a sip of my evening of Coffee. Suddenly,I recollected that during their psephological analysis, many times the channels were quoting “caste – a social group” and then a question has popped up  .

“Is India Secular?”

As citizens of this India we proudly say, India is a secular country. (Guys, don’t misunderstand me, but frankly, I feel the proud adjective is used as an exaggreration for Indians.)

To recall our memory, we have been introduced to this word, “Secularism” during our primary or upper primary social sciences classes. I believe it was not the right age to study it in depth and to understand its pros and cons.

Further, as the time passes, we are least bothered about the same as we are not from the Arts steam.  Although, it was flushed out of our minds, once in a while, it flashes into our memory  when the media flashes a breaking news about some riots or electoral process or on National Festivals(Independence day  & Republic Day).

I believe that, the first and foremost responsibility of any citizen of any country is to understand, his/her country's constitution. Unfortunately, none of the Indians dare to do so. It is a waste of time for them. This helps to understand their stand towards Patriotism.

Sorry,Perhaps I am deviating from the base point. Before, finding out whether India is really secular or not? We should try to understand the terms “Secularism”, “Secularization” , “Secular State”
Wikipedia defines these terms as follows:

Secularism is the principle of the separation of government institutions and persons mandated to represent the state from religious institutions and religious dignitaries. Source: http://en.wikipedia.org/wiki/Secularism

Secularization or secularisation is the transformation of a society from close identification with religious values and institutions toward nonreligious (or irreligious) values and secular institutions Source: http://en.wikipedia.org/wiki/Secularization

A Secular State is a concept of secularism, whereby a state or country purports to be officially neutral in matters of religion, supporting neither religion nor irreligion.[1] A secular state also claims to treat all its citizens equally regardless of religion, and claims to avoid preferential treatment for a citizen from a particular religion/nonreligion over other religions/nonreligion. Secular states do not have a state religion (established religion) or equivalent, although the absence of a state religion does not necessarily mean that a state is fully secular; however, a true secular state should steadfastly maintain national governance without influence from religious factions. Source: http://en.wikipedia.org/wiki/Secular_State

As an idealogy, Secularism means the separation of government and its functionaries from the religious values/ faiths. In other words, in the secular society  religion and the religious faiths are insignificant both in theory and practice.

To your knowledge, The words "socialist" and "secular" were added to the definition in 1976 by constitutional amendment . India celebrates the adoption of the constitution on 26 January each year as Republic Day.

It is very pity to say that, we Indians hrap about overselves as Originators of great civilizations. But, we were lack of knowledge to create own Constitution. It is fact that many concepts such as Praliamentary Democracy, Separation of Powers amont the major branches of Government, Distribution of powers between Central and State Governments, Establishment of Supreme Court, Fundamental Rights, Directive Principles, Judicial Review etc., have been adopted from various constituitons (http://en.wikipedia.org/wiki/Constitution_of_India#Adoptions_from_other_constitutions)
Now, we should ask the following questions to ourself.

If  India is declared as secular? Why the reservations?
At first, the answer is “India is a Socialist”. We will discuss it on some other day or some other time.

But, Why the reservations of Caste based rather that Poverty or Social Status based?

I don’t how many of you agree with me. However, as per my understanding, Caste is religiously evolved social section/group of  people. It could be any sub-sections of Hinduism, Christianity, Shikism, Buddhism, Jainism or Islam. Everything is a part of religious faith.

So, I keep this question open to you “Is India Secular?”.

I would request you all to read the Wikipedia article “Secularism in India -http://en.wikipedia.org/wiki/Secularism_in_India” and let me know your views.

Friday, June 21, 2013

My first C# Application

Hey Guys,

After a long time, for fun today, I have developed an application on Windows Platform using C#. Although, I had some hands-on in Visual Basic, this is my first application in C#. I can't comment much on the features of C#, as I am novice to this. But, Visual Studio 2010 IDE is similar to the Visual Studio 6 IDE.

I developed a small calculator application that calculates the Body Mass Index [BMI].

Saturday, July 2, 2011

Generating RATS Sequence

In this blog, my effort is to demonstrate the logic of generating the RATS Sequence.
All the numbers which are in the form of S(n)=( n+R(n)) is called RATS number. The sequence of RATS number is called RATS Sequence.
In the above formula : n denotes an Integer, R(n) denotes the Reversed Number, S(n) is an number , which is the sum of  the number n and its Reversal number R(n) , after sequencing the digits of the number in ascending order .
For further information on RATS Sequence, refer to   http://mathworld.wolfram.com/RATSSequence.html
Below code snippet demonstrates the basic logic for generating the RATS Sequence.

CREATE OR REPLACE PROCEDURE GENERATE_RATS_SEQUENCE(IN_FIRST_TERM IN NUMBER, IN_NTH_TERM IN NUMBER) IS
  lvRATSSequence VARCHAR2(32767):=NULL;
  lnPreviousTerm NUMBER:=0;
  lnRatsNumber NUMBER:=0;
  lnFirstTerm NUMBER:=0;
  FUNCTION GENERATE_RATS_NUMBER (IN_NUMBER IN NUMBER) RETURN NUMBER IS
    lnReverseNumber NUMBER:=0;
  BEGIN
    SELECT REVERSE(TO_CHAR(IN_NUMBER)) INTO lnReverseNumber FROM DUAL;
    RETURN SwapDigits((IN_NUMBER+ lnReverseNumber));
  END GENERATE_RATS_NUMBER;
BEGIN
  IF IN_FIRST_TERM IS NULL THEN
     lnFirstTerm:=1;
  ELSE
     lnFirstTerm:=IN_FIRST_TERM;
  END IF;
  lnPreviousTerm:=lnFirstTerm;
  lvRATSSequence:=lnFirstTerm;
  FOR I IN lnFirstTerm..IN_NTH_TERM LOOP   
    lnRatsNumber:= GENERATE_RATS_NUMBER(lnPreviousTerm);
    lnPreviousTerm:=lnRatsNumber;
    lvRATSSequence:=lvRATSSequence||','||lnPreviousTerm;
  END LOOP;
  DBMS_OUTPUT.PUT_LINE('RATS Sequence starting with '||IN_FIRST_TERM||' upto '||IN_NTH_TERM||' terms is : '||chr(10)||lvRATSSequence);
END GENERATE_RATS_SEQUENCE;

Friday, July 1, 2011

Sorting Collections in PL/SQL

In this blog, I made an attempt to demonstrate the usage of CAST and MULTISET pseudo-functions.  Pseudo functions are usually used with collections such as VARRAYS, NESTED TABLES and PL/SQL TABLES in Oracle. The below statement creates a user-defined Nested Table of primitive data type NUMBER.
CREATE OR REPLACE TYPE SwapTable IS TABLE OF NUMBER NOT NULL;
/
CAST pseudo function converts one collection type to another collection type.
MULTISET pseudo function returns a collection type records as a table.
The usage of CAST and MULTISET pseudo columns retrieves rows from a table as collection type.
The below function arranges the digits of a given number in ascending order.
CREATE OR REPLACE FUNCTION SwapDigits(IN_NUMBER IN NUMBER) RETURN NUMBER IS
ltSwappingTable SwapTable;
 ltSwappedTable SwapTable;
 lvSwappedNumber VARCHAR2(3000):=NULL;
BEGIN
 ltSwappingTable:= SwapTable ();
 ltSwappingTable.EXTEND(LENGTH(TO_CHAR(IN_NUMBER)));
 FOR I IN 1..LENGTH(TO_CHAR(IN_NUMBER)) LOOP
  ltSwappingTable(I):=SUBSTR(TO_CHAR(IN_NUMBER),I,1);
  DBMS_OUTPUT.PUT_LINE(ltSwappingTable(I));
 END LOOP;
 SELECT CAST(MULTISET(SELECT * FROM TABLE(ltSwappingTable) ORDER BY 1 ASC) AS SwapTable )
   INTO ltSwappedTable
   FROM DUAL;
 FOR J IN ltSwappedTable.FIRST..ltSwappedTable.LAST LOOP
  DBMS_OUTPUT.PUT_LINE(ltSwappedTable(J));
  lvSwappedNumber:=lvSwappedNumber||ltSwappedTable(J);
 END LOOP;
 RETURN TO_NUMBER(lvSwappedNumber);  
END SwapDigits;

Wednesday, June 29, 2011

Program to Generate the Catalan Series


Hi!
I would like to share some interesting programs related to the number theory. Here I am posting a Oracle PL/SQL program to generate the Catalan Series. This procedure takes an input parameter IN_UPPER_BOUND. This denotes the 'n' th term of the Catalan Series, where n is a integer number. By default, the lower bound is taken as 1.

Briefly, Catalan Series is defined as follows "A sequence of natural numbers which are named after the Beligian mathematician Eugène Charles Catalan".
Please follow the following link: http://en.wikipedia.org/wiki/Catalan_number for more information about the Catalan series.

Source Code:

CREATE OR REPLACE PROCEDURE GENERATE_CATALAN_SERIES(IN_UPPER_BOUND IN NUMBER) IS
 lvCatalanSeries VARCHAR2(32767):=NULL;
FUNCTION CATALAN(IN_NUMBER IN NUMBER) RETURN NUMBER IS
lnCatalan NUMBER:=0;
lnCatalanBound NUMBER:=0;
BEGIN
IF
IN_NUMBER=0 OR IN_NUMBER=1 THEN
lnCatalan:=1;
ELSE
lnCatalanBound:=IN_NUMBER-1;
lnCatalan:= ((((lnCatalanBound*2)+1)*2)/(lnCatalanBound+2)) * CATALAN(lnCatalanBound);
IF TO_NUMBER(SUBSTR(TO_CHAR(lnCatalan),INSTR(TO_CHAR(lnCatalan),'.')+1,LENGTH(TO_CHAR(lnCatalan)))) > 50 THEN
lnCatalan:=CEIL(lnCatalan);
ELSE
lnCatalan:=FLOOR(lnCatalan);
END IF;
END IF;
RETURN
lnCatalan;
END CATALAN;

BEGIN
FOR
i IN 0..IN_UPPER_BOUND LOOP
IF
lvCatalanSeries IS NULL THEN
lvCatalanSeries:=CATALAN(I);
ELSE
lvCatalanSeries:=lvCatalanSeries'->' CATALAN(I);
END IF;
END LOOP;
DBMS_OUTPUT.PUT_LINE('Catalan Series upto 'IN_UPPER_BOUND' is : 'CHR(10)lvCatalanSeries);
END GENERATE_CATALAN_SERIES;

Here the function CATALAN is a recursive function.