-
Notifications
You must be signed in to change notification settings - Fork 183
/
01 - Matching {x} Repetitions.py
36 lines (29 loc) · 1.17 KB
/
01 - Matching {x} Repetitions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# ========================
# Information
# ========================
# Direct Link: https://www.hackerrank.com/challenges/matching-x-repetitions/problem
# Difficulty: Easy
# Max Score: 20
# Language: Python
# ========================
# Solution
# ========================
import re
regex_pattern = r'^[a-zA-Z24680]{40}[13579\s]{5}$'
# Regex Pattern:
# .
# ├── ^
# │ └── Denotes the start of the line
# ├── [a-zA-Z24680]{40}
# │ ├── a-z - Denotes a single character in the range of a and z
# │ ├── A-Z - Denotes a single character in the range of A and Z
# │ ├── 24680 - Denotes any single character included in the list '24680'
# │ └── {40} - Denotes the above expression for 40 times
# ├── [13579\s]{5}
# │ ├── 13579 - Denotes any single character included in the list '13579'
# │ ├── \s - Denotes any non-whitespace character (equal to [^\r\n\t\f\v ])
# │ └── {5} - Denotes the above expression for 5 times
# └── $
# └── Denotes the end of the line
# Example: 2222222222aaaaaaaaaa2222222222aaaaaaaaaa13 57
print(str(bool(re.search(regex_pattern, input()))).lower())