Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MarkDown to restructuredText and pep8

  • Loading branch information...
commit 8faedf550995a9c6297844cd3826a53f7b238830 1 parent 6ff184e
@igalarzab authored
View
89 codejam/2011-bot_trust/README.md
@@ -1,89 +0,0 @@
-Bot Trust
-==================
-
-Description
-------------
-
-Blue and Orange are friendly robots. An evil computer mastermind has locked
-them up in separate hallways to test them, and then possibly give them cake.
-
-Each hallway contains 100 buttons labeled with the positive integers {1, 2,
-..., 100}. Button k is always k meters from the start of the hallway, and the
-robots both begin at button 1. Over the period of one second, a robot can walk
-one meter in either direction, or it can press the button at its position once,
-or it can stay at its position and not press the button. To complete the test,
-the robots need to push a certain sequence of buttons in a certain order. Both
-robots know the full sequence in advance. How fast can they complete it?
-
-For example, let's consider the following button sequence:
-
- O 2, B 1, B 2, O 4
-
-Here, O 2 means button 2 in Orange's hallway, B 1 means button 1 in Blue's
-hallway, and so on. The robots can push this sequence of buttons in 6 seconds
-using the strategy shown below:
-
- Time | Orange | Blue
- ------------+------------------+-----------------
- 1 | Move to button 2 | Stay at button 1
- 2 | Push button 2 | Stay at button 1
- 3 | Move to button 3 | Push button 1
- 4 | Move to button 4 | Move to button 2
- 5 | Stay at button 4 | Push button 2
- 6 | Push button 4 | Stay at button 2
-
-Note that Blue has to wait until Orange has completely finished pushing O 2
-before it can start pushing B 1.
-
-
-Input
----------
-
-The first line of the input gives the number of test cases, T. T test cases
-follow.
-
-Each test case consists of a single line beginning with a positive integer N,
-representing the number of buttons that need to be pressed. This is followed by
-N terms of the form "Ri Pi" where Ri is a robot color (always 'O' or 'B'), and
-Pi is a button position.
-
-
-Output
--------
-
-For each test case, output one line containing "Case #x: y", where x is the
-case number (starting from 1) and y is the minimum number of seconds required
-for the robots to push the given buttons, in order.
-
-
-Limits
--------
-
- 1 <= Pi <= 100 for all i.
-
-Small dataset
-
- 1 <= T <= 20.
- 1 <= N <= 10.
-
-Large dataset
-
- 1 <= T <= 100.
- 1 <= N <= 100.
-
-
-Sample
---------
-
-Input
-
- 3
- 4 O 2 B 1 B 2 O 4
- 3 O 5 O 8 B 100
- 2 B 2 B 1
-
-Output
-
- Case #1: 6
- Case #2: 100
- Case #3: 4
View
92 codejam/2011-bot_trust/README.rst
@@ -0,0 +1,92 @@
+Bot Trust
+=========
+
+Description
+-----------
+
+Blue and Orange are friendly robots. An evil computer mastermind has locked them
+up in separate hallways to test them, and then possibly give them cake.
+
+Each hallway contains 100 buttons labeled with the positive integers ``{1, 2,
+..., 100}``. Button ``k`` is always ``k`` meters from the start of the hallway,
+and the robots both begin at button 1. Over the period of one second, a robot
+can walk one meter in either direction, or it can press the button at its
+position once, or it can stay at its position and not press the button. To
+complete the test, the robots need to push a certain sequence of buttons in
+a certain order. Both robots know the full sequence in advance. How fast can
+they complete it?
+
+For example, let's consider the following button sequence::
+
+ O 2, B 1, B 2, O 4
+
+Here, ``O 2`` means button 2 in Orange's hallway, ``B 1`` means button 1 in
+Blue's hallway, and so on. The robots can push this sequence of buttons in
+6 seconds using the strategy shown below::
+
+ Time | Orange | Blue
+ ------------+------------------+-----------------
+ 1 | Move to button 2 | Stay at button 1
+ 2 | Push button 2 | Stay at button 1
+ 3 | Move to button 3 | Push button 1
+ 4 | Move to button 4 | Move to button 2
+ 5 | Stay at button 4 | Push button 2
+ 6 | Push button 4 | Stay at button 2
+
+Note that Blue has to wait until Orange has completely finished pushing ``O 2``
+before it can start pushing ``B 1``.
+
+
+Input
+-----
+
+The first line of the input gives the number of test cases, ``T``. ``T`` test
+cases follow.
+
+Each test case consists of a single line beginning with a positive integer
+``N``, representing the number of buttons that need to be pressed. This is
+followed by ``N`` terms of the form ``Ri Pi`` where ``Ri`` is a robot color
+(always ``O`` or ``B``), and ``Pi`` is a button position.
+
+
+Output
+-------
+
+For each test case, output one line containing ``Case #x: y``, where ``x`` is
+the case number (starting from 1) and ``y`` is the minimum number of seconds
+required for the robots to push the given buttons, in order.
+
+
+Limits
+------
+
+General::
+
+ 1 <= Pi <= 100 for all i.
+
+Small dataset::
+
+ 1 <= T <= 20.
+ 1 <= N <= 10.
+
+Large dataset::
+
+ 1 <= T <= 100.
+ 1 <= N <= 100.
+
+
+Sample
+------
+
+Input::
+
+ 3
+ 4 O 2 B 1 B 2 O 4
+ 3 O 5 O 8 B 100
+ 2 B 2 B 1
+
+Output::
+
+ Case #1: 6
+ Case #2: 100
+ Case #3: 4
View
7 codejam/2011-bot_trust/sol.py
@@ -10,6 +10,7 @@
import sys
+
def solve(movements):
copy = movements[:]
blue, orange = ([], [])
@@ -30,7 +31,7 @@ def solve(movements):
bpos += 1
elif blue and bpos > movements[blue[0]][1]:
bpos -= 1
- else: # ==
+ else: # ==
if copy and copy[0][0] == 'B':
mblue = True
@@ -65,7 +66,7 @@ def solve(movements):
for i in xrange(cases):
line = sys.stdin.readline().split()[1:]
- movs = [(line[j], int(line[j+1])) for j in xrange(0, len(line), 2)]
- print("Case #%d: %d" % (i+1, solve(movs)))
+ movs = [(line[j], int(line[j + 1])) for j in xrange(0, len(line), 2)]
+ print("Case #%d: %d" % (i + 1, solve(movs)))
# vim: ai ts=4 sts=4 et sw=4
View
55 codejam/2011-candy_splitting/README.md → codejam/2011-candy_splitting/README.rst
@@ -1,23 +1,23 @@
Candy Splitting
-================
+===============
Description
-------------
+-----------
Sean and Patrick are brothers who just got a nice bag of candy from their
parents. Each piece of candy has some positive integer value, and the children
-want to divide the candy between them. First, Sean will split the candy into
-two piles, and choose one to give to Patrick. Then Patrick will try to
-calculate the value of each pile, where the value of a pile is the sum of the
-values of all pieces of candy in that pile; if he decides the piles don't have
-equal value, he will start crying.
+want to divide the candy between them. First, Sean will split the candy into two
+piles, and choose one to give to Patrick. Then Patrick will try to calculate the
+value of each pile, where the value of a pile is the sum of the values of all
+pieces of candy in that pile; if he decides the piles don't have equal value, he
+will start crying.
- Unfortunately, Patrick is very young and doesn't know how to add properly. He
+Unfortunately, Patrick is very young and doesn't know how to add properly. He
almost knows how to add numbers in binary; but when he adds two 1s together, he
always forgets to carry the remainder to the next bit. For example, if he wants
to sum 12 (1100 in binary) and 5 (101 in binary), he will add the two rightmost
bits correctly, but in the third bit he will forget to carry the remainder to
-the next bit:
+the next bit::
1100
+ 0101
@@ -26,7 +26,7 @@ the next bit:
So after adding the last bit without the carry from the third bit, the final
result is 9 (1001 in binary). Here are some other examples of Patrick's math
-skills:
+skills::
5 + 4 = 1
7 + 9 = 14
@@ -41,43 +41,45 @@ possible value of Sean's pile.
Input
-----------
+-----
-The first line of the input gives the number of test cases, T. T test cases
-follow. Each test case is described in two lines. The first line contains a
-single integer N, denoting the number of candies in the bag. The next line
-contains the N integers Ci separated by single spaces, which denote the value
-of each piece of candy in the bag.
+The first line of the input gives the number of test cases, ``T``. ``T`` test
+cases follow. Each test case is described in two lines. The first line contains
+a single integer ``N``, denoting the number of candies in the bag. The next line
+contains the ``N`` integers ``Ci`` separated by single spaces, which denote the
+value of each piece of candy in the bag.
Output
---------
+------
-For each test case, output one line containing "Case #x: y", where x is the
-case number (starting from 1). If it is impossible for Sean to keep Patrick
-from crying, y should be the word "NO". Otherwise, y should be the value of the
-pile of candies that Sean will keep.
+For each test case, output one line containing ``Case #x: y``, where ``x`` is
+the case number (starting from 1). If it is impossible for Sean to keep Patrick
+from crying, ``y`` should be the word ``NO``. Otherwise, ``y`` should be the
+value of the pile of candies that Sean will keep.
Limits
-------
+General::
+
1 <= T <= 100.
1 <= Ci <= 106.
-Small dataset
+Small dataset::
2 <= N <= 15.
-Large dataset
+Large dataset::
2 <= N <= 1000.
Sample
-----------
+------
-Input
+Input::
2
5
@@ -85,8 +87,7 @@ Input
3
3 5 6
-Output
+Output::
Case #1: NO
Case #2: 11
-
View
8 codejam/2011-candy_splitting/sol.py
@@ -10,21 +10,21 @@
import sys
+
def solve(movements):
- if reduce(lambda x,y: x^y, movements):
+ if reduce(lambda x, y: x ^ y, movements):
return "NO"
movements.sort()
return str(sum(movements[1:]))
-
if __name__ == '__main__':
cases = int(sys.stdin.readline())
for i in xrange(cases):
- ncandies = int(sys.stdin.readline()) # Ignore :P
+ ncandies = int(sys.stdin.readline()) # Ignore :P
candies = map(int, sys.stdin.readline().split())
- print("Case #%d: %s" % (i+1, solve(candies)))
+ print("Case #%d: %s" % (i + 1, solve(candies)))
# vim: ai ts=4 sts=4 et sw=4
View
49 codejam/2011-gorosort/README.md → codejam/2011-gorosort/README.rst
@@ -1,11 +1,11 @@
GoroSort
-===========
+========
Description
-------------
+-----------
Goro has 4 arms. Goro is very strong. You don't mess with Goro. Goro needs to
-sort an array of N different integers. Algorithms are not Goro's strength;
+sort an array of ``N`` different integers. Algorithms are not Goro's strength;
strength is Goro's strength. Goro's plan is to use the fingers on two of his
hands to hold down several elements of the array and hit the table with his
third and fourth fists as hard as possible. This will make the unsecured
@@ -13,10 +13,9 @@ elements of the array fly up into the air, get shuffled randomly, and fall back
down into the empty array locations.
Goro wants to sort the array as quickly as possible. How many hits will it take
-Goro to sort the given array, on average, if he acts intelligently when
-choosing which elements of the array to hold down before each hit of the table?
-Goro has an infinite number of fingers on the two hands he uses to hold down
-the array.
+Goro to sort the given array, on average, if he acts intelligently when choosing
+which elements of the array to hold down before each hit of the table? Goro has
+an infinite number of fingers on the two hands he uses to hold down the array.
More precisely, before each hit, Goro may choose any subset of the elements of
the array to freeze in place. He may choose differently depending on the
@@ -25,44 +24,46 @@ random. Each permutation is equally likely.
Input
----------
+-----
-The first line of the input gives the number of test cases, T. T test cases
-follow. Each one will consist of two lines. The first line will give the number
-N. The second line will list the N elements of the array in their initial
-order.
+The first line of the input gives the number of test cases, ``T``. ``T`` test
+cases follow. Each one will consist of two lines. The first line will give the
+number ``N``. The second line will list the ``N`` elements of the array in their
+initial order.
Output
--------
+------
-For each test case, output one line containing "Case #x: y", where x is the
-case number (starting from 1) and y is the expected number of hit-the-table
-operations when following the best hold-down strategy. Answers with an absolute
-or relative error of at most 10-6 will be considered correct.
+For each test case, output one line containing ``Case #x: y``, where ``x`` is
+the case number (starting from 1) and ``y`` is the expected number of
+hit-the-table operations when following the best hold-down strategy. Answers
+with an absolute or relative error of at most 10-6 will be considered correct.
Limits
---------
+------
+
+General::
1 <= T <= 100;
-The second line of each test case will contain a permutation of the N smallest
+The second line of each test case will contain a permutation of the ``N`` smallest
positive integers.
-Small dataset
+Small dataset::
1 <= N <= 10;
-Large dataset
+Large dataset::
1 <= N <= 1000;
Sample
----------
+------
-Input
+Input::
3
2
@@ -72,7 +73,7 @@ Input
4
2 1 4 3
-Output
+Output::
Case #1: 2.000000
Case #2: 2.000000
View
7 codejam/2011-gorosort/sol.py
@@ -10,11 +10,12 @@
import sys
+
def solve(numbers):
errors = 0
for i in xrange(len(numbers)):
- if numbers[i] != i+1:
+ if numbers[i] != i + 1:
errors += 1
return errors
@@ -24,8 +25,8 @@ def solve(numbers):
cases = int(sys.stdin.readline())
for i in xrange(cases):
- nnumbers = int(sys.stdin.readline()) # Ignore :P
+ nnumbers = int(sys.stdin.readline()) # Ignore :P
numbers = map(int, sys.stdin.readline().split())
- print("Case #%d: %.6f" % (i+1, solve(numbers)))
+ print("Case #%d: %.6f" % (i + 1, solve(numbers)))
# vim: ai ts=4 sts=4 et sw=4
View
104 codejam/2011-magicka/README.md
@@ -1,104 +0,0 @@
-Magicka
-==========
-
-Description
--------------
-
-As a wizard, you can invoke eight elements, which are the "base" elements. Each
-base element is a single character from {Q, W, E, R, A, S, D, F}. When you
-invoke an element, it gets appended to your element list. For example: if you
-invoke W and then invoke A, (we'll call that "invoking WA" for short) then your
-element list will be [W, A].
-
-We will specify pairs of base elements that combine to form non-base elements
-(the other 18 capital letters). For example, Q and F might combine to form T.
-If the two elements from a pair appear at the end of the element list, then
-both elements of the pair will be immediately removed, and they will be
-replaced by the element they form. In the example above, if the element list
-looks like [A, Q, F] or [A, F, Q] at any point, it will become [A, T].
-
-We will specify pairs of base elements that are opposed to each other. After
-you invoke an element, if it isn't immediately combined to form another
-element, and it is opposed to something in your element list, then your whole
-element list will be cleared.
-
-For example, suppose Q and F combine to make T. R and F are opposed to each
-other. Then invoking the following things (in order, from left to right) will
-have the following results:
-
- QF -> [T] (Q and F combine to form T)
- QEF -> [Q, E, F] (Q and F can't combine because they were never at the end of the element list together)
- RFE -> [E] (F and R are opposed, so the list is cleared; then E is invoked)
- REF -> [] (F and R are opposed, so the list is cleared)
- RQF -> [R, T] (QF combine to make T, so the list is not cleared)
- RFQ -> [Q] (F and R are opposed, so the list is cleared)
-
-
-Given a list of elements to invoke, what will be in the element list when you're done?
-
-
-Input
---------
-
-The first line of the input gives the number of test cases, T. T test cases
-follow. Each test case consists of a single line, containing the following
-space-separated elements in order:
-
-First an integer C, followed by C strings, each containing three characters:
-two base elements followed by a non-base element. This indicates that the two
-base elements combine to form the non-base element. Next will come an integer
-D, followed by D strings, each containing two characters: two base elements
-that are opposed to each other. Finally there will be an integer N, followed by
-a single string containing N characters: the series of base elements you are to
-invoke. You will invoke them in the order they appear in the string (leftmost
-character first, and so on), one at a time.
-
-
-Output
----------
-
-For each test case, output one line containing "Case #x: y", where x is the
-case number (starting from 1) and y is a list in the format "[e0, e1, ...]"
-where ei is the ith element of the final element list. Please see the sample
-output for examples.
-
-
-Limits
----------
-
- 1 <= T <= 100.
-
-Each pair of base elements may only appear together in one combination, though
-they may appear in a combination and also be opposed to each other. No base
-element may be opposed to itself. Unlike in the computer game Magicka, there
-is no limit to the length of the element list.
-
-Small dataset
-
- 0 <= C <= 1.
- 0 <= D <= 1.
- 1 <= N <= 10.
-
-Large dataset
-
- 0 <= C <= 36.
- 0 <= D <= 28.
- 1 <= N <= 100.
-
-
-Sample
-----------
-
-Input
-
- 2
- 5
- 1 2 3 4 5
- 3
- 3 5 6
-
-Output
-
- Case #1: NO
- Case #2: 11
-
View
107 codejam/2011-magicka/README.rst
@@ -0,0 +1,107 @@
+Magicka
+=======
+
+Description
+-----------
+
+As a wizard, you can invoke eight elements, which are the "base" elements. Each
+base element is a single character from ``{Q, W, E, R, A, S, D, F}``. When you
+invoke an element, it gets appended to your element list. For example: if you
+invoke ``W`` and then invoke ``A``, (we'll call that "invoking ``WA``" for
+short) then your element list will be ``[W, A]``.
+
+We will specify pairs of base elements that combine to form non-base elements
+(the other 18 capital letters). For example, ``Q`` and ``F`` might combine to
+form ``T``. If the two elements from a pair appear at the end of the element
+list, then both elements of the pair will be immediately removed, and they will
+be replaced by the element they form. In the example above, if the element list
+looks like ``[A, Q, F]`` or ``[A, F, Q]`` at any point, it will become ``[A,
+T]``.
+
+We will specify pairs of base elements that are opposed to each other. After you
+invoke an element, if it isn't immediately combined to form another element, and
+it is opposed to something in your element list, then your whole element list
+will be cleared.
+
+For example, suppose ``Q`` and ``F`` combine to make ``T``. ``R`` and ``F`` are
+opposed to each other. Then invoking the following things (in order, from left
+to right) will have the following results::
+
+ QF -> [T] (Q and F combine to form T)
+ QEF -> [Q, E, F] (Q and F can't combine because they were never at the end of the element list together)
+ RFE -> [E] (F and R are opposed, so the list is cleared; then E is invoked)
+ REF -> [] (F and R are opposed, so the list is cleared)
+ RQF -> [R, T] (QF combine to make T, so the list is not cleared)
+ RFQ -> [Q] (F and R are opposed, so the list is cleared)
+
+
+Given a list of elements to invoke, what will be in the element list when you're
+done?
+
+
+Input
+-----
+
+The first line of the input gives the number of test cases, ``T``. ``T`` test
+cases follow. Each test case consists of a single line, containing the following
+space-separated elements in order:
+
+First an integer ``C``, followed by ``C`` strings, each containing three
+characters: two base elements followed by a non-base element. This indicates
+that the two base elements combine to form the non-base element. Next will come
+an integer ``D``, followed by ``D`` strings, each containing two characters: two
+base elements that are opposed to each other. Finally there will be an integer
+``N``, followed by a single string containing ``N`` characters: the series of
+base elements you are to invoke. You will invoke them in the order they appear
+in the string (leftmost character first, and so on), one at a time.
+
+
+Output
+------
+
+For each test case, output one line containing ``Case #x: y``, where x is the
+case number (starting from 1) and ``y`` is a list in the format ``[e0, e1,
+...]`` where ei is the ith element of the final element list. Please see the
+sample output for examples.
+
+
+Limits
+------
+
+General::
+
+ 1 <= T <= 100.
+
+Each pair of base elements may only appear together in one combination, though
+they may appear in a combination and also be opposed to each other. No base
+element may be opposed to itself. Unlike in the computer game Magicka, there is
+no limit to the length of the element list.
+
+Small dataset::
+
+ 0 <= C <= 1.
+ 0 <= D <= 1.
+ 1 <= N <= 10.
+
+Large dataset::
+
+ 0 <= C <= 36.
+ 0 <= D <= 28.
+ 1 <= N <= 100.
+
+
+Sample
+------
+
+Input::
+
+ 2
+ 5
+ 1 2 3 4 5
+ 3
+ 3 5 6
+
+Output::
+
+ Case #1: NO
+ Case #2: 11
View
14 codejam/2011-magicka/sol.py
@@ -10,6 +10,7 @@
import sys
+
def solve(reductions, deletions, letters):
s = letters[0]
i = 1
@@ -21,10 +22,10 @@ def solve(reductions, deletions, letters):
# First, all the possible reductions
try:
while make_reductions:
- if reductions.has_key(s[-1]+s[-2]):
- s = s[:-2] + reductions[s[-1]+s[-2]]
- elif reductions.has_key(s[-2]+s[-1]):
- s = s[:-2] + reductions[s[-2]+s[-1]]
+ if s[-1] + s[-2] in reductions:
+ s = s[:-2] + reductions[s[-1] + s[-2]]
+ elif s[-2] + s[-1] in reductions:
+ s = s[:-2] + reductions[s[-2] + s[-1]]
else:
make_reductions = False
except:
@@ -59,10 +60,11 @@ def solve(reductions, deletions, letters):
reductions[line[j][0:2]] = line[j][2]
offset = 1 + int(line[0])
- for j in xrange(offset+1, offset + int(line[offset]) + 1):
+ for j in xrange(offset + 1, offset + int(line[offset]) + 1):
deletions.append(line[j])
offset += 1 + int(line[offset])
- print("Case #%d: %s" % (i+1, solve(reductions, deletions, line[offset+1])))
+ print("Case #%d: %s" % (i + 1,
+ solve(reductions, deletions, line[offset + 1])))
# vim: ai ts=4 sts=4 et sw=4
Please sign in to comment.
Something went wrong with that request. Please try again.