You are on page 1of 5

Programming

Instructions

➔ Time limit for the event is two hours. Reached the venue late? Nope, no
extra time for you.
➔ There are four problems in this paper. No, they are NOT questions.
They are problems, because you'll have to sweat it out to solve them.
➔ The questions problems are NOT arranged in the order of difficulty.
That's for you to figure out.
➔ When you think you've solve a problem correctly, raise BOTH of your
hands and shout out "I'm a carrot!". Anyone who does not follow this
rule will get minus 30 points for being a disobedient little brat.
➔ For each correct attempt you get 100 points. However, you need to
watch out because for each incorrect attempt you get minus 50 points.
➔ In case of a tie in scores among different teams, the time taken to
attempt the problems will be considered.
➔ Be scared. Be very very scared indeed.

Problem paper by Naman Bagga (www.namanb.com)


Programmer, Code Warriors Batch of 2008

irritatingStuffTM powered by 6by9media

www.code-warriors.org
DNA. Nothing to do with Douglas Noel Adams.
Thankfully.

After the excessive dose of Douglas Noel Adams (aka DNA) in Code Wars 2007,
we perfectly understand if some of you feel paranoid about coming across
those three letters in that permutation. We decided to give something you'd
surely hate equally – biology.

A DNA (deoxyribonucleic acid – remember it, the guy who comes to check your
program might ask you this) molecule is formed by two nucleotide chains of
equal length. Each nucleotide in the first chain must form a bond with the
nucleotide at the same position in the second chain. There are four types of
nucleotides: A, C, G and T. Each type of nucleotide can only form a bond with
one other type: A can only bond with T, and G can only bond with C. These
pairs – AT and CG – are called complementary pairs. No other bonds are
allowed.

You are given aString as input, where each character is an available


nucleotide. Return the length of the longest DNA molecule that can be created
using only the available nucleotides. The length of a DNA molecule is the
number of nucleotides in either one of its chains. If no DNA molecule can be
created, return 0. aString will contain between 1 and 50 characters,
inclusive. Each character in aString will be 'A','C','G' or 'T'.

Examples

1. AGGCA returns 1.
2. GGTACAGTTT returns 3.
3. ACCACCAACCA returns 0.

www.code-warriors.org
Persian Clock. Made of gold, obviously.

You bought a golden Persian digital wall clock, but while hanging it on the wall,
you mounted it upside-down by mistake (obviously, because you're stupid). To
make things worse, the clock has a complicated mechanism inside that makes
it go slow when it is upside-down (just to make you feel miserable), needing X
seconds (an integer value between 61 and 1000, inclusive) to advance a
minute instead of 60 seconds. Note that even at the moment you hang the
clock on the wall, it is not necessarily set at the correct time. The clock itself
only displays hours (from 00 to 23) and minutes (from 00 to 59), including any
leading zeros.

You are given an input of currentTime (a character string) in the form


HH:MM, representing the actual (correct) time at which the clock is mounted on
the wall, and an input clockTime (also a character string in the form HH:MM),
representing the time the clock is displaying when it is mounted on the wall
(the time that you would see if the clock was mounted normally, not upside-
down). Assume in both times that the seconds part is 0, i.e., the time just
changed to currentTime and the clock just advanced to clockTime. You
have to compute the first time after the clock is mounted on the wall that the
clock shows the correct time (i.e., the display as shown now that the clock is
mounted upside-down represents the correct time) and return this in the form
HH:MM (a character string...duh, need we say this all the time?), including any
leading zeros. If the clock never shows the correct time, returns
This...is...Sparta!!!

When the clock time is read upside-down, the digits 0, 1, 2, 5 and 8 are the
same, 6 is shown as 9 and 9 is shown as 6. The digits 3, 4 and 7 do not show
any meaningful digits when read upside-down.

Examples

1. 01:10 (currentTime), 21:09 (clockTime), 61 (X) – returns 01:12


2. 12:34, 23:45, 300 – returns This...is...Sparta!!!

www.code-warriors.org
Chandra Yawn – The Space Race

It is a common practice in cryptography to remove the spaces from a message


before encoding it to help to disguise its structure. Even after it is then
decoded, you are left with the problem of putting the spaces back in the
message. No, you won't have to decrypt anything today (we're kind people) –
but you will have to join the space race.

Create a program that takes an array of strings theDictionary (containing 1


to 10 elements, inclusive; each element will be distinct) of possible words and
a character string theMessage as inputs. Return message with single spaces
inserted to divide theMessage into words from theDictionary. If there is
more than one way to insert spaces, return AMBIGUOUS!; if there is no way to
insert spaces, then return IMPOSSIBLE! (The returned string should never
have any leading or trailing spaces.)

Note: Every character in theMessage and in each element of theDictionary


will be an uppercase letter 'A' to 'Z'. Inclusive, dumbass.

Examples

1. {"HI", "YOU", "SAY"} (theDictionary), HIYOUSAYHI


(theMessage), returns HI YOU SAY HI.
2. {"IMPOSS", "SIBLE", "S"}, IMPOSSIBLE, returns IMPOSSIBLE!

www.code-warriors.org
Gridlock'd

There is a rectangular grid of coins, with heads being represented by the


value 1 and tails being represented by the value 0. You represent this on the
computer using a 2D integer array table (between 1 to 10 rows, inclusive).
Neat-o! Now you make your move (NOT on that chick / guy sitting next to you,
dammit!).

In each move, you choose any single cell (R, C) in the grid (R-th row, C-th
column) and flip the coins in all cells (r, c), where r is between 0 and R,
inclusive, and c is between 0 and C, inclusive. Flipping a coin means inverting
the value of a cell from zero to one and vice versa. Here we would like to pre-
empt those trying act smart by asking "But what if when I flip a coin the result
is neither head or tail?" by saying this: this is Sparta Code Wars 2008, not
bloody Sholay.

Return the minimum number of moves required to change all the cells in the
grid to tails. This will always be possible – unless of course you don't have the
brains to do it.

Examples

1. 1111
1111
returns: 1

2. 01
01
returns: 2

www.code-warriors.org

You might also like