Skip to content

Commit

Permalink
Solve Vehicular Restriction in python
Browse files Browse the repository at this point in the history
  • Loading branch information
deniscostadsc committed Sep 23, 2024
1 parent 24d3faa commit 8c12c51
Show file tree
Hide file tree
Showing 6 changed files with 2,110 additions and 0 deletions.
26 changes: 26 additions & 0 deletions solutions/beecrowd/2712/2712.py
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')
44 changes: 44 additions & 0 deletions solutions/beecrowd/2712/generate_in.sh
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
Loading

0 comments on commit 8c12c51

Please sign in to comment.