TORONTO KIDS COMPUTER CLUB | Aurora Saturday 14:30 Python Practice 20.12.12.
post-template-default,single,single-post,postid-18850,single-format-standard,ajax_fade,page_not_loaded,,no_animation_on_touch,qode-theme-ver-7.6.2,wpb-js-composer js-comp-ver-6.10.0,vc_responsive

Aurora Saturday 14:30 Python Practice 20.12.12.

16 Dec Aurora Saturday 14:30 Python Practice 20.12.12.

Please email your code to before Jan 3rd, 2021

The TOP 3 students will get a small gift!

Question 1:
In a card game, each player’s hand is made up of 13 cards. Each hand has a total point value determined by the number of cards that have a point value. The cards which are worth points are the Ace (4 points), King (3 points), Queen (2 points) and Jack (1 point). The other cards (2, 3, 4, 5, 6, 7, 8, 9, 10) have no point value.

There are four of each type of card, one in each of the four suits. The suits are called clubs (C), diamonds (D), hearts (H), and spades (S). As well, points are assigned for each suit which has a void (3 points), a singleton (2 points), or a doubleton (1 point). A void in a suit means that there are no cards of that suit (e.g. a hand with no spades). A singleton in a suit means that there is only one card in that suit (e.g. a hand with only one diamond). A doubleton in a suit means that there are only two cards in that suit.

Write a program to read a set of thirteen cards in the form of a string, then evaluate the number of points in the hand. The suits will appear in increasing alphabetical order. Within each suit there will be no duplicate cards.

The output is to be the hand and the point value shown in a table form as below. Your output should list the cards in the same order as the input. Note that 10 is represented by the character T in both the input and the output.

Sample Input 1

Sample Output 1
Cards Dealt       Points
Clubs 2 5 8 T J K      4
Diamonds 6 9 Q A       6
Hearts                 3
Spades T J A           5
                Total 18

Sample Input 2

Sample Output 2
Cards Dealt        Points
Clubs A                 6
Diamonds 5 7 8 K A      7
Hearts A                6
Spades 4 7 T Q K A      9
                 Total 28

Note: your output does not need to match exactly. The spacing is up to you.

Question 2:
In order to increase your performance on the ABC (Another Buying Contest), you decide that you need a new computer. When determining which computer to buy, you narrow your search categories to:

    • RAM (in gigabytes), denoted as R;
    • CPU speed (in megahertz), denoted as S;
    • disk drive space (in gigabytes), denoted as D.

You perform some analysis and determine that the most preferred machine is the machine that has the largest value of the formula 2R+3S+D.

Your task is to read a given list of computers and output the top two computers in order of preference, from highest preference to lowest preference.

Input Specification
The first line of input will be an integer n (0≤n≤10000). Each of the remaining n lines of input will contain a computer specification. A computer specification is of the form:

    • computer name (a string of less than 20 characters)
    • the RAM available (an integer R with 1≤R≤128)
    • the CPU speed (an integer S with 1≤S≤4000)
    • the disk drive space (an integer D with 1≤D≤3000)

There is one space between the name, RAM, CPU speed and disk drive space on each line.

Output Specification
The output is the name of the top two preferred computers, one name per line, sorted in decreasing order of preference. If there is a tie in the rankings, pick the computer(s) whose name(s) are lexicographically smallest (i.e., Apple is smaller than Dell). If there is only one computer, output that computer on one line (i.e., do not print it twice).

Sample Input
ABC 13 22 1
DEF 10 20 30
GHI 11 2 2
JKL 20 20 20

Output for Sample Input

Explanation of Output for Sample Input
Computer ABC has a computed value of 93. 
Computer DEF has a computed value of 110. 
Computer GHI has a computed value of 30. 
Computer JKL has a computed value of 120. 
Therefore, computer JKL is the most preferred, followed by computer DEF.

Question 3:

You are hosting a party and do not have room to invite all of your friends. You use the following unemotional mathematical method to determine which friends to invite.

Number your friends 1,2,…,K and place them in a list in this order. Then perform m rounds. In each round, use a number to determine which friends to remove from the ordered list.

The rounds will use numbers r1,r2,…,rm. In round i remove all the remaining people in positions that are multiples of ri (that is, ri,2ri,3ri,…) The beginning of the list is position 1.

Output the numbers of the friends that remain after this removal process.

Input Specification
The first line of input contains the integer K (1≤K≤100). The second line of input contains the integer m (1≤m≤10), which is the number of rounds of removal. The next m lines each contain one integer. The ith of these lines (1≤i≤m) contains ri (2≤ri≤100) indicating that every person at a position which is multiple of ri should be removed.

Output Specification
The output is the integers assigned to friends who were not removed. One integer is printed per line in increasing sorted order.

Sample Input

Output for Sample Input

Explanation of Output for Sample Input
Initially, our list of invitees is {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}. 
There will be two rounds of removals. After the first round of removals, 
we remove the even positions (i.e., every second position), 
which causes our list of invitees to be {1, 3, 5, 7, 9}. 
After the second round of removals, we remove every 3rd remaining invitee:
 thus, we keep 1 and 3, remove 5 and keep 7 and 9, which leaves us with an invitee list of {1, 3, 7, 9}.

Question 4:
Jack purchased a new microprocessor. Unfortunately, he soon learned that many of his programs that he wrote for his old processor didn’t work on the new processor.

Deep inside the technical documentation for both processors, he found an explanation. In order to work faster, the new processor imposes certain constraints on the machine code of programs, constraints that never existed on the previous model.

The machine code of a processor consists of instructions that are executed sequentially. Each instruction uses a byte of memory. Also, instructions can have zero or more parameters, each of which uses an additional byte of memory. In machine code, parameters immediately follow an instruction.

When formatted as text, machine code instructions are uppercase letters, while parameters are lowercase letters. For example:

This program consists of four instructions; the first takes three parameters, the second two, the third none and the fourth takes four parameters. The program uses 13 bytes of memory.

The new processor model fetches memory in four-byte chunks so each instruction must start at a memory address that is divisible by four (the first byte in memory is address 0). To achieve that, we can insert NOP (no operation) instructions into the old program, instructions that do nothing and are not limited to memory locations divisible by four. The above program, adapted to run on the new processor, can look like this:

The instructions A, B, C and D are now at memory locations 0, 4, 8 and 12, which satisfies the processor’s constraints.

Write a program that determines the smallest number of NOP instructions that need to be inserted for the given program to work on the new processor model.

Input Specification
The input contains the machine code of the program written for the old processor model. The program will consist of at most 200 English letters.

The program will always start in an instruction i.e. the first letter in the machine code will be uppercase. If an instruction appears more than once in the machine code, it will always take the same number of parameters.

Output Specification
Output the smallest number of NOP instructions needed to adapt the program for the new processor.

Sample Input 1

Sample Output 1

Sample Input 2

Sample Output 2

Sample Input 3

Sample Output 3
No Comments

Sorry, the comment form is closed at this time.