You are on page 1of 6

Programming

Getting Started
● Time allotted: 2 hours and 42 minutes.
● Each question is worth 42 points.
● There are FIVE questions in the paper.
● If your team completes all five questions correctly, you get 42
bonus points.
● Thus, the maximum points a team can get is 252 points.
● Try out your program, and when you think you're ready, shout out
'Forty Two'; please note that if you shout anything stupid like
'Attempt' or anything else, 20 points will be deducted from your
score. The organizers will then check whether your attempt is
correct.
● In case your attempt is incorrect, 30 points will be deducted from
your score.
● Yes, we ARE crazy about the Hitchhiker's Guide to Galaxy, and will
try our level best to get on your nerves by putting an overdose of it
in Code Wars 2007.

Don't Panic!
www.code­warriors.org
The Newer Adventures of He-Man

You are He-Man, 'The Most Powerful Man in the Universe'. You realize
that since this it year 2007 (the 'Bond' year), and you no more need to
fight with Skeletor, using the old sword and tiger, and that fighting with
him in a virtual arena with better customized weapons will be more fun.
So you learn programming in C++ (!!!).

This is your first homework assignment. You are given a character, i.e., a
single letter (either 'a', 'b', or 'c'). After every second of time, all
occurrences of the letter 'a' are replaced with 'acb', all occurrences of the
letter 'b' are replaced with 'baa', and all occurrences of the letter 'c' are
replaced with 'bcb'. These replacements happen simultaneously during
each second. Now why will He-Man care about this is something even we
don't know.

You are given three integers left, right, and time. Take the substring
between positions left and right (both 0-based), inclusive, after n
seconds, and return exactly 3 numbers. The first element is the number
of 'a's in the substring, the second element is the number of 'b's, and the
third element is the number of 'c's. Max-time will not exceed 20 seconds.

Examples
1. Input:
'a' 2 6 2
Output:
0 4 1
If letter = 'a', then after 2 seconds, the string will be
'acbbcbbaa'. If left = 2 and right = 6, the substring is 'bbcbb',
which contains no 'a's, 4 'b's, and 1 'c'. Therefore, you will
return {0, 4, 1}.

2. Input:
'a' 0 2 1
Output:
1 1 1

www.code­warriors.org
return porky;

Our old friend Porky Pig is back, begging you to solve his simple
problem. He will give you a number N. He wants you to find him the
smallest integer that starts with N and is divisible by every non-zero digit
of N (all in decimal notation). 1 <= N <= 1,00,00,00,000

Examples
1. Input:
13
Output:
132
We need a number that starts with 13 and is divisible by 1 (always
true) and by 3. The smallest one is 132.

2. Input:
648
Output:
648

www.code­warriors.org
No time waste problem*
"In Euclidean geometry, a circle is the set of all points in a plane at
a fixed distance, called the radius, from a given point, the centre.
Circles are simple closed curves which divide the plane into an
interior and exterior. The circumference of a circle means the
length of the circle, and the interior of the circle is called a disk. An
arc is any continuous portion of a circle."

"A circle is a special ellipse in which the two foci coincide (i.e., are
the same point). Circles are conic sections attained when a right
circular cone is intersected with a plane perpendicular to the axis of
the cone."

"A 'lattice point' is defined as 'a point in a coordinate plane with


integer coordinates'."

You are given the radius r of a circle centered at the origin. Your task is
to return the number of lattice points (points whose coordinates are both
integers) on the circle. The number of pairs of integers (x, y) that satisfy
x2 + y2 = n is given by the formula 4*(d1(n) - d3(n)), where di(n)
denotes the number of divisors of n that leave a remainder of i when
divided by 4. Note: 1<= r <= 2*109.

Examples
1. Input:
1
Output:
4
The only lattice points on the circle are (0,1), (1,0), (-1,0), (0,-1)

2. Input:
2000000000
Output:
76

* No irrelevant story in this problem!

www.code­warriors.org
Speed

You are in the real world, and you are neither Neo, nor Morpheus. You
don't own the red Lamborghini, but you have a few colorful guitars. Each
guitar has a unique serial number. You want to be able to look up serial
numbers quickly, so you decide to sort the entire list as follows.
Each serial number consists of uppercase letters ('A' - 'Z') and digits ('0'
- '9'). To see if serial number A comes before serial number B, use the
following steps:

1. If A and B have a different length, the one with the shortest length
comes first.
2. Else if sum of digits in (A) differs from sum of digits in (B), the one
with the lowest sum comes first.
3. Else compare them alphabetically, where digits come before letters.

Examples
1. Input:
ABCD
145C
A
A910
Z321
Output:
A
ABCD
Z321
145C
A910

2. Input:
Z19
Z20
Output:
Z20
Z19

www.code­warriors.org
ROTten Question
There exists a basic encryption method known as ROT13. One property
of ROT13 is that the encryption and decryption processes are exactly the
same. These processes work by doing a simple transformation from one
letter of the alphabet to another. The letters A through M become N
through Z, such that A -> N, B -> O, ..., M -> Z. The letters N through Z
become A through M, such that N -> A, O -> B, ..., Z -> M. One of the
problems with most implementations is that everything is converted to
upper case. Another problem is that numbers are ignored completely,
leaving them unencrypted. One way to overcome these limitations is to
extend ROT13 to cover lowercase letters as well as numbers.

Here is how our extended ROT transformations will work:


Characters... ...Become
A-M N-Z
N-Z A-M
a-m n-z
N-z a-m
0-4 5-9
5-9 0-4
You have intercepted a message which you believe to be encrypted using
this process. Create a class SuperRot with a method decoder that takes
a string message and returns the decoded message as a string.

Examples
1. Input:
Uryyb 28
Output:
Hello 73
Notice that the spaces were left as is.

2. Input:
5678901234
Output:
0123456789

www.code­warriors.org

You might also like