You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: puzzles/python3/ascii-art/README.md
+54-25Lines changed: 54 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,15 +2,11 @@
2
2
3
3
## Description
4
4
5
-
"ASCII Art" is a beginner-level coding challenge available on the CodinGame platform. In this challenge, the player is given a string of characters and a font size, and is asked to generate an ASCII art representation of the string using ASCII characters.
5
+
The goal of this puzzle is to simulate an old airport terminal display by displaying a line of text in ASCII art. To solve this challenge, you'll learn how to manage strings and perform array arithmetics. You will practice splitting strings into separate parts, concatenating them into a new string, and using array indexes effectively. By leveraging data structures like arrays or hash tables, you can store and recreate strings to create the ASCII art representation of the input text.
6
6
7
-
The ASCII art output should be a sequence of lines, each line representing a row of the output. Each row should contain the ASCII characters that correspond to the input string, with each character expanded to the specified font size. If a character in the input string is not a letter or cannot be represented in ASCII art, it should be replaced with a question mark.
7
+
## Example Input/Output
8
8
9
-
The challenge consists of writing a program that takes as input the string of characters, the font size, and the ASCII art characters to be used for each letter, and outputs the corresponding ASCII art representation.
10
-
11
-
The challenge is designed to help players learn and practice programming skills such as string manipulation, input/output handling, and ASCII art rendering. It is a fun and engaging way to improve programming skills while solving a challenging and entertaining puzzle.
12
-
13
-
### Example Input
9
+
**Input**
14
10
15
11
```
16
12
4
@@ -24,7 +20,7 @@ CodinGame
24
20
25
21
```
26
22
27
-
### Example Output
23
+
**Output**
28
24
29
25
```
30
26
## # ## ### ### ## # # # ###
@@ -66,28 +62,61 @@ To solve this coding puzzle, you'll need to create a program that takes the widt
66
62
7.**Testing**:
67
63
- Test your program with different input cases, including different widths, heights, and text inputs, to ensure it works correctly.
68
64
69
-
Here's a simplified Python code for the main part of the code:
65
+
## Code Example
70
66
71
67
```python
72
-
defascii_art(L, H, T, ascii_dict):
73
-
result = [''] * H
74
-
75
-
for char in T:
76
-
if char.isalpha():
77
-
index =ord(char.upper()) -ord('A')
78
-
else:
79
-
index =26# '?' character
80
-
81
-
start = index * L
82
-
end = start + L
83
-
for i inrange(H):
84
-
result[i] += ascii_dict[i][start:end]
68
+
L =int(input()) # width of each character
69
+
H =int(input()) # height of the ASCII art
70
+
T =input() # input text to be converted to ASCII art
71
+
72
+
# Read the ASCII art for A-Z and '?'
73
+
ascii_art = []
74
+
for i inrange(H):
75
+
row =input()
76
+
ascii_art.append(row)
77
+
78
+
# Create a dictionary to store the ASCII art for each character
79
+
ascii_dict = {}
80
+
81
+
for i inrange(26): # for A-Z
82
+
ascii_dict[chr(i +ord('A'))] = [ascii_art[j][i*L:(i+1)*L] for j inrange(H)]
83
+
84
+
# '?' will represent any unknown character
85
+
ascii_dict['?'] = [ascii_art[j][26*L:(27)*L] for j inrange(H)]
86
+
87
+
# Convert the input text T to uppercase and handle unknown characters
This pseudocode outlines the key steps to solve the coding puzzle. You need to implement the details, including reading the ASCII art representations and handling edge cases.
104
+
## Explanation of Code Steps
105
+
106
+
1.**Input Parsing**:
107
+
- Read `L` (width of each letter), `H` (height of letters), and `T` (input text).
108
+
- For `H` lines, read the ASCII art representing all characters from A to Z and `?`.
109
+
110
+
2.**Store ASCII Art**:
111
+
- Use a list to store the ASCII art of each character in a structured way.
112
+
- For each character in the string `T`, extract the corresponding ASCII art from this list.
113
+
114
+
3.**Handle Non-alphabet Characters**:
115
+
- Any character outside of the range `[A-Z]` or `[a-z]` should be replaced by the `?` character's ASCII art.
116
+
117
+
4.**Print the ASCII Art**:
118
+
- For each line in the height `H`, concatenate and print the corresponding parts of the ASCII art for each character in `T`.
90
119
91
120
## Edge Cases
92
121
93
-
Test your program by experimenting with an empty ASCII art representation for one or more characters to confirm that it appropriately manages missing character representations. Additionally, try inputting a combination of uppercase and lowercase letters to verify that the program handles case conversion and character lookup accurately. Test different combinations of widths and heights to ensure the program can handle various dimensions without errors or output distortion. Provide a single character input string to assess the program's handling of single-character input and its corresponding ASCII art output. Furthermore, examine input strings containing leading, trailing, and multiple consecutive whitespace characters to ensure proper whitespace handling. Lastly, test input strings where characters overlap in the ASCII art output to confirm the program handles such cases without merging characters or distorting the output. By conducting these tests, you can guarantee that the program gracefully handles various scenarios and produces correct ASCII art output under diverse conditions.
122
+
Test your program by experimenting with an empty ASCII art representation for one or more characters to confirm that it appropriately manages missing character representations. Additionally, try inputting a combination of uppercase and lowercase letters to verify that the program handles case conversion and character lookup accurately. Test different combinations of widths and heights to ensure the program can handle various dimensions without errors or output distortion. Provide a single character input string to assess the program's handling of single-character input and its corresponding ASCII art output. Furthermore, examine input strings containing leading, trailing, and multiple consecutive whitespace characters to ensure proper whitespace handling. In summary, thoroughly test your program with various inputs, including empty ASCII art, mixed case letters, different dimensions, single characters, and strings with whitespace, to ensure it handles all cases accurately.
0 commit comments