Friday, September 13, 2019

Superior of partial fraction

What is complex fraction?
Complex fraction is a fraction whereby its numerator or denominator or both consists of fractions.

Partial fraction helps us to solve some problematic question involve complex fractions.

No worries!

There are always patterns in Mathematics.

You may observe and deduce formula from it.

Please download and learn from the exercise - solution below.

Partial Fraction

Monday, June 17, 2019

Advanced book 1 - Accessment

Dear all, here is the wrap up for advanced book 1.

It consists of interesting concept like HCF, LCM, Prime Factors, Divisibility, Complex Fraction, Partial Fraction.

Please get the solution for the accesment .
Answer Advanced Accessment 1

Wednesday, May 1, 2019

Complex fraction

What is fraction?
Imagining you have one whole cake and you need to share the cake among you and your friends.
Here come the problems, to be fair, we should share the cake equally.
I cut the cake equally to eight pieces and share it with 7 of my friends.
Each of us getting 1/8 of the whole cake.
When one of my friend - Lily is sick and refuse to eat the cake. She cake the cake to me.
Then I get 2 / 8 of the whole cake. By simplification, I get 1 / 4 of the whole cake.

When it comes to include operation in fraction, it follows BODMAS rule as whole number.
What is BODMAS ? BODMAS is the precedence rule when we are solving equation. 
B - Bracket
O - Power of / root
D / M - Division / Multiplication (from left to right)
A / S - Addition / Subtraction (from left to right)

So, when there is a equation, we need to solve all those grouped in one bracket, then follow by power of / root of a number , then division / multiplication (left to right because they are in same level of precedence), then addition / subtraction (left to right because they are in same level of precedence as well).

Fraction have numerator / denumenator. 
Remember, division bar / can be treated as division as well.
What is complex fraction ?
Complex fraction is a fraction where numerator or denumenator is also a fraction.
No worry, solving a complex fraction is nothing much more difficult than fraction.

First, simplify the complex fraction to simpler form before doing + / -
You have to treat division bar as division. 
When you divide a fraction a by another fraction b, you may just change to multiplication by reversing numerator and denumerator of fraction b.
You should need to change the fraction to similar denumerator before doing + / -.

In short, please do refer to the notes below for extra explaination.

Saturday, April 6, 2019

Revision Intermediate Level book 1 - 8

After a quite a long and challenging journey, we finally finish the training on Intermediate level book 1 to book 8.

What a relieve huh ?

Along the training, we have go through concept or theory related to Euler Path, Counting, Shortest Path Distance, Gauss Theorem, Tricks in calculation, Logical Thinking Skills, Speed, Marvels of Triangle and etc. Sorry that I could not list down all one by one.

Please refer to the attachment below for revision exercise (answer provided).

Revision Intermediate level Book 1 - 8

I also do provide the python code to solve question 28 - How many times a digits appear in a range of number. If you may use the code to check your answer.

Check the number of occurence of a digit in a range of number

Friday, April 5, 2019

Loops

What is loops ?
What loops do ?

Please do imagine you need go bicycle for 7 days.
There is a loop of 7 iterations, and your statement / activity should be cycling.

Keep it simple.
Loop help us to do job repeatedly in one block of codes.

There are several types of loops. For instance, there are for loop, while loop, do while loop and etc.

The basic / simple loop should be for loop.
You may ask your program to do the loop for how many times using "for" keywords.

Example : you may print number 0 to 4 using the statement below
for ind in range(5) : 
      print (ind)

On the other hand, a while loop will execute the block of codes / statement while / when some condition is fulfilled.

Example : the while loop print "It is true" as long as the condition is true.
Please be reminded that the condition must be true initially, else the while loop will not be executed.
Please be aware that u must have stopping criteria : assign the condition to false in the while loop.
Else you will be having an infinity loop and hit runtime error. (since you never tell the program when should it stops)

condition is true initially
while condition is true : 
       print("It is true")
       if  something happend :
              condition is false

Please do refer to the link below for further details:
Loop

Friday, February 15, 2019

Dictionary

The problems in this set are designed to be more accessible to beginning coders. As a learning aid, walkthroughs discussing how to solve the problems in this set are available by clicking on this link. On completion of this problem set, students should have experience at using arrays to store, search through, and manipulate large data sets.

Dictionary

Input File: dictin.txt
Output File: dictout.txt
Time Limit: 1 second
Integerland and Wholenumberland are alike in many ways: similar culture, similar traditions - they even share the same national dress (the parenthetic pyjamas). Yet despite this, the two nations have never gotten along well. It is widely believed that this is because of their greatest differences - their language. A sentence that sounds perfectly intelligible on one side of the border is complete gibberish on the other side.
For example, if an Integerlander wanted to find out the time, she would ask, "140 2 87 2 3?". On the other hand, a Wholenumberlander would ask "19 71 555 71 556?". As you can see, these languages are very distinctive. It would be impossible to mistake one for the other.
This year's regional trade talks are to be held in Australia. You have been appointed the official translator for the proceedings. Using your trusty Integerlandese-Wholenumberlandese dictionary and your rusty laptop, you must be able to fluently translate from one language to another.

Input

The first line will consist of two integers d and w, separated by a space. You are guaranteed that 0 <= d, w <= 1,000.
The following d lines will each describe an entry in your bilingual dictionary. Each of these lines contains two integers separated by a space: a word in Integerlandese, and its Wholenumberlandese counterpart. All integers will be between -2,000,000,000 and 2,000,000,000 inclusive. You are guaranteed that no Integerlandese word will appear more than once in the dictionary.
The following w lines will each contain a single word in Integerlandese for you to translate.

Output

For each Integerland word you are asked to translate, you must print out a single line containing the corresponding Wholenumberland word. If there is no translation in your dictionary, you should print "C?" for that line.

Please do get the solution by the link below: 

Monday, February 11, 2019

Python Operator


What coding can do?
What coding can help?
How python help us in coding ?

Python Operator is one of those basic but "powerful" problem solving tools.
We may use it to do arithmetic operation like solving our daily Mathematics questions.
We can't deny how powerful is it when it combine with other operators like Assignment operators, Comparison operators, Logical operators, Identity operators, Membership operators and bitwise operator.

Assignment operators, we can guess what it does by its name. Simpy - it do assignment.
Wait a second! What is assignment ?
Remember = means assignment and == means equal in python.
Some  may scratch his or her head when it come to here.
Kind of confusing, huh?
Lets say we have a variable name box, and we put RM 10 into it.
Simply the equation will be as follows:
box = 10 (This is called assignment)

But, is box equal to 10 ? No! box is a container to keep the money.

Then what == do ?
We use == when we need to do comparison, which will be discussed in Comparison Operators.

If my mother give me 3 ringgit more, then i should have:
box = 10
box = box + 3 (total money I got at the moment) (= 13)
This equation is  kind of too long, it could be abbreviated as :
box += 3

Simply, x-=3 means x = x - 3
x * = 2 means x = x*2

You may explore more in the notes provided in the link below.

Okay! Now, we may continue to Comparison operator.
For instance, I would like to check if I got RM 10 in my box.
I use box == 10 (it return true if I got RM 10 else return false)
I had RM 13 now, so the equation will return false.
Obviously, box == 13 will return true.

It could be a super long story if I continue the other operator here.
You may explore more from the link below.
Please do try the humble and simple question provided in the notes as exercise.

Practise Makes Perfect!

Week3 - Python operator

Saturday, October 27, 2018

List in python

In order to store a set of variable, we use a list.

A list can be illustrated as a box queue in a line, and we add our value to each box.

The box can be accessed using the box position. We would call it index.

In python index should start from 0.

So, first element is in index 0, second element is in index 1.. and so on.

We add an element to a list by .append(new value). myList.append("newValue")

We will be able to access an element by []

Let us have a list name myList, to get the first element, we will use myList[], second element, myList[1] and so on.

To remove an element from a list, use .pop(index).
To remove the first element, I use myList.pop(0)
To get the first element of a list and remove it, I use removelement = myList.pop(0)

Please do refer to the example below for better understanding on how to add element to a list , access the element of list. remove an element from a list.

There is another question regarding list.
Encyclopedia question


Maximum / Minimum / Average with python

Programming help us to solve problem. Sometimes, we do need statistics to help us making decision.

For instance, we would like to decide which age range of customers prefer books, games or clothes.
We may also need statistics to show our sales, how popular is our movie produce, how is the  customers response to our food and etc.

It helps us to analyze large data sets. There are functions help us to do job easier and faster. But how?

According to the following example, we use max() , min(), function to get the maximum or minimum number. In order to get the average, do use a for loop to sum up the value and calculate the average

I use .rstrip() to trim the empty string of the input string. 

Please do refer to the link below for example.

dishin problem

Sunday, October 21, 2018

How to use loop to analyze large data sets?

If we have a set of data {1, 3, 5, 6, 10, 12}, this should be no problem to analyze.
We may sum it up to get their total, or calculate their average , get their maximum, minimum or mode during one glance.

However, what about we have datasets with 100 data, or up to 1000 or even much more?
Can we calculate the amount manually?

That is why we use computer to solve our daily problem.
We need to shorten our time to analyze large amount of data.

In order to analyze the data, we use loop to access the data one by one.
For sure, we need stopping criteria to tell the compiler when it should stop the execution,
else we might get run time error (the computer keep repeat the steps and do not know when to stop).

I will be demonstrating how loop helps us by using the sample question from Australian Informatics Olympiad programme sample questions. You may registered and get the training from their training site here Australian Mathematics Trust.

According to the question, we need to access the input data from 'rainin.txt' and output the result to 'rainout.txt'. From the input file, the first line give number of days n and capacity of water tanks in liters c. The remaining n lines shows the amount of rain in litres for the n days.

Here comes the question : What is the number of days for the tank to be filled up?

In this question, you do not need to check or validate the data. The main purpose of the program is to calculate number of days to fill up the tank instead of doing validation on the input data.

So, please refer to the pseudocode below for the steps.

Pseudocode:
1.  Open the input file and assign the data to a list. Remember to close the file.
2.  Obtain number of days n, capacity of water tank c from the first element of the list.
3.  Delete the first element of the list, since we do not need it in the list anymore. We had assigned the data of n and c in variables previously
4. I will be using the for loop to access all the element in the list.
5. During each loop, I sum up the water filled in the tank. I increment the number of days need to fill up the tank.
6. Then, I check if the total amount of water filled in the tank reach or more than the capacity. If so break and exit the loop, else repeat the steps until we get the desired amount of water.
7. Finally, open a output file and write the output string to the file. Close the file.

See, the question might seems difficult and confusing intitially. It become easier when we understand the requirement and break down to smaller part. We might get the result.

The next item we need to worry about is the syntax. No worry, there are resources regarding the language syntax online and it is free! Practice makes perfect. Please do refer the link below for the solution

How to solve drought problem

Friday, October 19, 2018

Python week 2

After we learn the basic syntax of python, we need to proceed to variable.

Variable is very important in programming, since it "acts" like a container to store our value.

The type of variables are integer int, string str and float (for decimal number).

You are an elite if you can conquer the confusion of the data type and the casting and conversion.

Assignment a value into a variable help to store the value we need. So, how to access or retrieve the data is also another challenge. It helps us to proceed to next steps we need to do like doing operation or pass into another function for further action.

I had include the notes, exercise regarding the datatype, and how to access it in the link below.

Have fun!

Python notes_week 2

Code with python - first class

The name of computer is named by the word "compute".

Basically the role of computer cannot be fulfilled without compute.

Okay. Lets make it simple and see how computer compute?

Let's start with the basic.

I would like to introduce coding using language python.

Python is a interpreted, object-oriented, high-level programming language with dynamic semantics.

Among the language I had approached like C#, C++, Java and Python,
I would like to introduce Python for beginner.

In terms of syntax, I consider Python as easier and simpler language for beginner during my first approach to programming.

Furthermore, I suggest Python especially for the use in Mathematics.

I love the package useful for Mathematics that available in Python like Scipy, Pypi, Numpy, Matplotlib and so on.

I had attached the notes on the basic of python in the link below.

Why not trying?  Python First Week Class

Saturday, October 13, 2018

Arithmetic progression

Extra questions regarding arithmetic progression.

Please try!

Arithmetic progression

Numbers

There are numbers. 

Types of numbers can be categorizes as :
  • Natural numbers
  • Positive numbers
  • Negative numbers
  • Prime numbers
  • Rational numbers 
  • Irrational numbers
  • and so on
Please do refer to the attached pdf file below for further information.
Numbers

Thursday, October 4, 2018

How while loop works

This question focus on the understanding regarding the principle of while loop.

while loop is repeating the step under it until you cannot fulfill the condition

Python code 
inputNo = 10
i = 1
while (i <= inputNo):
    outputFile.write(str(i) + '\n')
    i = i + 1

Example
inputNo = 10 : Assign/set 10 to inputNo (inputNo is the name that store value 10)
i = 1 : Assign / set 1 to i (i is the name that store value 1)
while (i <= inputNo): 
means that while you can fulfill the condition in the brackets , that's mean you can find i that is smaller or equal to the inputNo

now i = 1, which is smaller or equal to 10
so do the actions under it 

write i to outputFile ('\n' means enter to the next line)
then i = i + 1 : means we add 1 to i, i is become 2 now

Again while (i <= inputNo): now i = 2 which is smaller than 10
then write 2 to output file
i = 2 + 1 = 3

Now i = 3, i is smaller than 10
write 3 to output file
i = 3 + 1 = 4

Now i = 4, i is smaller than 10
write 4 to output file
i = 4 + 1 = 5


...... (repeat the step)

Now i = 8, i is smaller than 10
write 8 to output file
i = 8 + 1 = 9

Now i = 9, i is smaller than 10
write 9 to output file
i = 9 + 1 = 10 

Now i = 10, i is equal to 10, fulfill the condition too
write 10 to output file
i = 10 + 1 = 11

Now i = 11, i is not smaller than 10, i is not equal to 10
we cannot fulfill the condition.
So, break the loop. We will exit the loop which means we will not repeat the action under the loop.


Counting question

Tak Tak Fruit Problem

This is a question that challenge your understand skill and programming skill.

The Tremendous Tak-Tak Tree
Output File: taktakout.txt
Time Limit: 1 second
Input
Output
Input File: taktakin.txt
Life is simple in the isolated village of Tak-Tak. Free of the noise and bustle of modern life, the villagers spend their days indulging their two great loves: farming and cooking. Their vegetable fields grow strong and tall, and their delicious communal meals brighten many an evening.
In the centre of the village sits a great sprawling tree, whose long boughs provide shade during the hot summers. The fruit of the Tak-Tak tree (as it is affectionately known) is renowned for its sweet, succulent taste.
Unlike normal plants, the Tak-Tak tree is not affected by weather or seasons. Instead, its fruits grow according to the cycles of the moon. Every month when the full moon is at its highest, each fruit on the tree shimmers and turns into two fruits. When the sun rises the villagers wake to find the number of fruits on the tree has doubled.
The villagers are planning a huge feast for this year. On the day of the feast they will remove all the fruit except onefrom the tree. This is to be divided equally between the village's eleven inhabitants, as they are a fair people. (No slicing or dicing is allowed - each villager must receive a whole number of fruits.) Afterwards the one remaining fruit on the Tak-Tak tree is left to begin the cycle anew.
If the villagers cannot evenly share the fruit with one left over, they shall wait until they can. They are very excited about the feast and would like to know how many full moons they must wait.
The input file will consist of a single integer, the number of fruits initially on the tree. This will be between 2 and 1,000,000 inclusive. 
The output file should consist of two integers separated by a space: the least number of full moons the villagers must wait until the feast is possible, and the number of fruits on the tree at that time.
You are guaranteed that it will eventually be possible to hold the feast.

To solve this question:
1. List down the condition given:

  • the number of fruit will be doubled each day
  • must leave exactly one fruit during the harvest day
  • there are 11 inhabitants to share the fruit evenly

2. The input give you the number of fruits on the first day.
3. You need to find out the number of days so that you can harvest and 1 fruit will be left.
4. Build a mathematics formula

  • number of fruits after first day = number of fruits X 2   
    • to check if harvest is allowed : number of fruits after first day / 11 = quotient R 1
    • if not then we need to check for next day


  • number of fruits after second day = number of fruits after first day X 2
  • 5. Do we really need to calculate by our hand until we get the answer? No worry . We might help ourselves by using a customized application / program

     The ways :
    1. Get the input file value - number of fruits on the first day (name it as number of fruits)
    2. we need a looping (what is a looping?? - we repeat the calculation with same formula until we get the anser)
    3. we know that number of inhabitants = 11

    • It could be easy if the answer if 0 day
    • 23 - 23 / 11 = 2 R 1
    • then number of day = 0, total fruit = 23
    • we might not be lucky 

    4. At first number of days = 0
    4. When we find out that

    • if the number of fruits / number of inhabitants = Quotient R 1 
      •  return number of days
      • return number of fruits
    • else
      • number of fruits = number of fruits X 2
      • number of days = number of days  + 1

     Pseudocode (we use english language to plan our program):
    1. get input the number of fruits
    2. set number of inhabitant = 11
    3. set number of days = 0
    4. when number of fruits % number of inhatant != 1
    (!= means not equal to ) (% means modulus - computer the remainder)

    • number of fruits = number of fruits X 2
    • number of days ++ 
    5. Then repeat the no.4 until number of fruits % number of inhatant == 1 (== means equal to )
    6. print the value to output file

    Please refer to the python code below to get the answer: 


    Tak Tak Problem Python Code

    Wednesday, October 3, 2018

    Mind Bending problem


    A Mindbending Scenario

    Input File: bendin.txt
    Output File: bendout.txt
    Time Limit: 0.05 seconds
    Imagine a universe far different to the one we know. One where where people can walk through walls, where politicians don't lie, where the rules of physics itself are bent on a daily basis. Imagine how strange it would be to land in that universe, having to adjust to entirely new laws of reality, and having to integrate yourself into sentient cultures far beyond human comprehension.
    Now, imagine that everything in this universe was suddenly destroyed in a cataclysmic explosion, leaving nothing but two rectangles on an endless plane. These two rectangles have their corners at integer co-ordinates (rational numbers having been destroyed). Your task is to discover the total area of the plane which is covered by these rectangles.
    Beware! Some parts of the plane may be covered by both rectangles. If you merely add the individual areas together, you are surely doomed to incorrect answers!

    Input

    The input file will consist of two lines. Each line will be of the form x1 y1 x2 y2, describing the bottom-left and top-right corners of one rectangle. You are guaranteed that 0 <= x1 < x2 <= 10,000, and 0 <= y1 < y2 <= 10,000. (That is, each rectangle is at least one unit square in size.)

    Output

    Your output file should consist of a single integer: the total area covered by rectangles. (Remember - the rectangles may overlap!)
    Please check on the python code by clicking the link below:  Mind bending problem python code
    You may get the original question from Mind bending problem question

    Monday, October 1, 2018

    Mixed function with python

    Mixed Fraction

    Input File: mixin.txt
    Output File: mixout.txt
    Time Limit: 1 second
    You are sitting at your computer surfing the internet when a chance forum post stirs memories of an idyllic past. There were so many different ways of representing rational numbers back then - percentages, decimals, and of course the mixed fraction. There was always something so wonderful about mixed fractions - the way they quickly told you how big the number was yet still conveyed the subtleties of the fractional part. Such elegance... You shed a silent tear for days long gone.
    In this task you are given a fraction in the form n/d, where 1 <= d < n <= 1,000,000,000. Your task is to find the two integers a and b, where 0 <= b < d and ad + b = n. You do not need to (and shouldn't) simplify the fraction.

    Input

    A single line containing the integers n and d separated by a space.

    Output

    If b is not 0, print a single line in the format a b/d. Otherwise, print a.

    Please click on the python code below:

    Sunday, September 30, 2018

    How to use python to check if a string is anagram?

    Anagram is a word or phrase can be formed by rearranging the letters of another word or phrase. For example, carthorse is anagram of horsecars. Blanks within a phrase will be ignored. orchestra and horse cart are also anagrams.

    Write a program that reads a list of phrases and print all pairs of anagram is demonstrated as follow (it will not work for upper case and lower case checking , "A" is different from "a" in the current program):

    Sample input: 
    carthorse
    horse
    horse cart
    I do not know u
    ok i now donut
    orchestra
    Sample output:
    carthorse = horse cart
    carthorse = orchestra
    horse cart = orchestra
    i do not know u = ok i now donut

    Please get the code and sample input file as below (there are both python and c++ version): 

    Is Anagram Problem

    Sunday, September 16, 2018

    AIO Sample question with answer 2: Sitting or Standing?

    Please click on the link to get the full question. Sitting or Standing ?


    Input File: sitin.txt
    Output File: sitout.txtTime Limit: 1 second
    Input
    Output


    A local musician is putting on a concert to raise money for charity. The concert will be held in the town hall, a spacious venue perfectly suited for such an event. There are r rows of seats, each containing exactly s seats. At most one person can sit on a single seat (that is, two people cannot share a seat).
    There is a problem - the concert may have been overbooked! This means that if everybody who bought tickets comes to the concert, some of them might have to stand. Now the musician has aproached you, not for advice, but for the answer to the following question: if everybody who bought tickets arrives and tries to find a seat, how many people will end up sitting, and how many people will be standing?
    The first line of the input file will consist of the two integers r and s: the number of rows and the number of seats per row in that order. It is guaranteed that 0 <= r, s <= 10,000. The second line will contain a single integer between 0 and 1,000,000,000: the number of tickets that have been bought.
    Your output file should consist of two integers separated by a space: the number of people sitting and standing respectively.
    Remember, everybody tries to sit if they can. If the concert has been overbooked, you will not be able to seat them all.

    I had try the question using Python. 
    The logic of program should be as below:
    • get input data (number of seats per rows, number of rows and number of tickets sold)
    • calculate the number of seats in total provided, number of tickets sold, get the number of standing people, number of sitting people
    • output the result to file
    You may get the code from here python code
    or
    viewing the python code as follows:
    #################################################################################

    # open the input file to obtain the number of rows and seats
    with open('sitin.txt', 'r') as inputFile1: 
        mylist = list(inputFile1) # assign the row to list
        
    inputFile1.close() # remember that always close the file

    # the input data is optained row by row and is assigned to list
    # first list is first line of input file (no.of.rows and seats)
    # second list is second line of input file (no.of.tickets sold)
    row, seats = mylist[0].split(' ', 1)  # split the first element of list to get row and seats per row
    tickets = mylist[1] # second row is only have the no.of.tickets sold

    # calculate the total number of seats provided
    # need to type casting the row and seats to integer datatype
    # if number of seats is smaller or equal to number of tickets sold, number of people sitting = number of sets, the rest will be standing
    # if number of seats is larger than the tickets solds, number of people sitting equal to number of tickets sold , and no people is standing
    noOfSeats = int(row) * int(seats)
    noOfTickets = int(tickets)
    if noOfSeats <= noOfTickets:
        standing = noOfTickets - noOfSeats
        seatNo = noOfSeats
    else:
        seatNo = noOfTickets
        standing = 0

    # open output file, and write the result into it
    # must close the file
    outputFile = open('sitout.txt','w') 
    outputFile.write(str(seatNo) + ' ' + str(standing)); 
    outputFile.close()


    Superior of partial fraction

    What is complex fraction? Complex fraction is a fraction whereby its numerator or denominator or both consists of fractions. Partial frac...