-
Notifications
You must be signed in to change notification settings - Fork 183
/
03 - Branch Reset Groups.php
66 lines (55 loc) · 1.99 KB
/
03 - Branch Reset Groups.php
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
// ========================
// Information
// ========================
// Direct Link: https://www.hackerrank.com/challenges/branch-reset-groups/problem
// Difficulty: Easy
// Max Score: 20
// Language: PHP
// ========================
// Solution
// ========================
// This problem does not have the option to be done in Python, hence, PHP was chosen
$Regex_Pattern = '/^\d{2}((-|:|---|.)?)\d{2}\1\d{2}\1\d{2}$/'
// Regex Pattern:
// .
// ├── ^
// │ └── Denotes the start of the line
// ├── \d{2}
// │ ├── \d - Denotes a digit (equal to [0-9])
// │ └── {2} - Denotes the above expression for 2 times
// ├── ((-|:|---|.)?)
// │ ├── (-|:|---|.)
// │ │ ├── - - Denotes a '-' character
// │ │ ├── | - Denotes a boolean OR operator
// │ │ ├── : - Denotes a ':' character
// │ │ ├── | - Denotes a boolean OR operator
// │ │ ├── --- - Denotes a '---' character
// │ │ ├── | - Denotes a boolean OR operator
// │ │ └── . - Denotes any character
// │ └── ? - Denotes the above expression for 0 and 1 times
// ├── \d{2}
// │ ├── \d - Denotes a digit (equal to [0-9])
// │ └── {2} - Denotes the above expression for 2 times
// ├── \1
// │ └── Denotes the first matching group
// ├── \d{2}
// │ ├── \d - Denotes a digit (equal to [0-9])
// │ └── {2} - Denotes the above expression for 2 times
// ├── \1
// │ └── Denotes the first matching group
// ├── \d{2}
// │ ├── \d - Denotes a digit (equal to [0-9])
// │ └── {2} - Denotes the above expression for 2 times
// └── $
// └── Denotes the end of the line
// Example: 12-34-56-78
$handle = fopen("php://stdin", "r")
$Test_String = fgets($handle)
if(preg_match($Regex_Pattern, $Test_String, $output_array)){
print("true")
} else {
print("false")
}
fclose($handle)
?>