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
Saturday, April 6, 2019
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
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
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
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
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
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
Subscribe to:
Posts (Atom)
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...
-
The name of computer is named by the word "compute". Basically the role of computer cannot be fulfilled without compute. Okay....
-
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. ...