-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Solve Vehicular Restriction in python
- Loading branch information
1 parent
24d3faa
commit 8c12c51
Showing
6 changed files
with
2,110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import re | ||
|
||
def is_valid_plate(plate): | ||
match = re.match(r'^[A-Z]{3}-\d{4}$', plate) | ||
return bool(match) | ||
|
||
def get_restricted_day(plate): | ||
match tuple(plate): | ||
case [*_, '1' | '2']: | ||
return 'MONDAY' | ||
case [*_, '3' | '4']: | ||
return 'TUESDAY' | ||
case [*_, '5' | '6']: | ||
return 'WEDNESDAY' | ||
case [*_, '7' | '8']: | ||
return 'THURSDAY' | ||
case [*_, '9' | '0']: | ||
return 'FRIDAY' | ||
|
||
n = int(input()) | ||
for _ in range(n): | ||
plate = input() | ||
if is_valid_plate(plate): | ||
print(get_restricted_day(plate)) | ||
else: | ||
print('FAILURE') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
LOWER_CASE_LETTERS=(a b c d e f g h i j k l m n o p q r s t u v w x y z) | ||
UPPER_CASE_LETTERS=(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) | ||
TESTCASES=1000 | ||
|
||
function generate_valid_car_plate { | ||
echo -n "${UPPER_CASE_LETTERS[$((RANDOM % 26))]}" | ||
echo -n "${UPPER_CASE_LETTERS[$((RANDOM % 26))]}" | ||
echo -n "${UPPER_CASE_LETTERS[$((RANDOM % 26))]}" | ||
echo -n "-" | ||
echo -n "$((RANDOM % 10))" | ||
echo -n "$((RANDOM % 10))" | ||
echo -n "$((RANDOM % 10))" | ||
echo "$((RANDOM % 10))" | ||
} | ||
|
||
function generate_probably_invalid_car_plate { | ||
for _ in $(seq $((RANDOM % 6 + 1))); do | ||
if [[ $((RANDOM % 2)) -eq 0 ]]; then | ||
echo -n "${UPPER_CASE_LETTERS[$((RANDOM % 26))]}" | ||
else | ||
echo -n "${LOWER_CASE_LETTERS[$((RANDOM % 26))]}" | ||
fi | ||
done | ||
if [[ $((RANDOM % 2)) -eq 0 ]]; then | ||
echo -n "-" | ||
fi | ||
for _ in $(seq $((RANDOM % 6 + 1))); do | ||
echo -n "$((RANDOM % 10))" | ||
done | ||
echo | ||
} | ||
|
||
echo "${TESTCASES}" | ||
for _ in $(seq "${TESTCASES}"); do | ||
if [[ $((RANDOM % 2)) -eq 0 ]]; then | ||
generate_valid_car_plate | ||
else | ||
generate_probably_invalid_car_plate | ||
fi | ||
done |
Oops, something went wrong.