Skip to content

Commit a074652

Browse files
committed
Added problem solution from Google Codejam: Punched cards
1 parent 04d2bfb commit a074652

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Task | Solution
2525
[Qualification Round 2020: ESAb ATAd](https://codingcompetitions.withgoogle.com/codejam/round/000000000019fd27/0000000000209a9e) | [Python](/codejam/2020-04-04/ESAb_ATAd/)
2626
[Qualification Round 2020: Indicium](https://codingcompetitions.withgoogle.com/codejam/round/000000000019fd27/0000000000209aa0) | [Python](/codejam/2020-04-04/Indicium/)
2727
[Round 1B: 2020: Expogo](https://codingcompetitions.withgoogle.com/codejam/round/000000000019fef2/00000000002d5b62) | [Python](/codejam/2020-04-19/Expogo/)
28+
[Qualification Round 2020: Punched Cards](https://codingcompetitions.withgoogle.com/codejam/round/0000000000876ff1/0000000000a4621b) | [Python](/codejam/2022-04-02/Punched_Cards)
2829

2930
## Facebook Hacker Cup
3031
Task | Solution
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
5
2+
3 4
3+
2 2
4+
2 3
5+
1 1
6+
0 0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import sys
2+
from typing import Iterator, List, Tuple
3+
4+
5+
def solution(rows: int, cols: int) -> None:
6+
for row in range(rows * 2 + 1):
7+
data: List[str] = []
8+
for col in range(cols * 2 + 1):
9+
if (row, col) in {(0, 0), (0, 1), (1, 0)}:
10+
data.append(".")
11+
elif row % 2 == 0 and col % 2 == 0:
12+
data.append("+")
13+
elif row % 2 == 0 and col % 2 == 1:
14+
data.append("-")
15+
elif row % 2 == 1 and col % 2 == 0:
16+
data.append("|")
17+
elif row % 2 == 1 and col % 2 == 1:
18+
data.append(".")
19+
20+
print("".join(data))
21+
22+
23+
def read_2_integers(lines: Iterator[str]) -> Tuple[int, int]:
24+
begin, end = next(lines).split()
25+
return int(begin), int(end)
26+
27+
28+
def parse_input(lines: Iterator[str]) -> Iterator[Tuple[int, int]]:
29+
number_of_tests = int(next(lines))
30+
for _ in range(number_of_tests):
31+
yield read_2_integers(lines)
32+
33+
34+
def main():
35+
case = 1
36+
for rows, cols in parse_input(sys.stdin):
37+
# Prints data inside
38+
print(f"Case #{case}:")
39+
solution(rows, cols)
40+
case += 1
41+
42+
43+
if __name__ == "__main__":
44+
main()

0 commit comments

Comments
 (0)