-
Notifications
You must be signed in to change notification settings - Fork 183
/
04 - Forward References.php
47 lines (36 loc) · 1.1 KB
/
04 - Forward References.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
<?php
// ========================
// Information
// ========================
// Direct Link: https://www.hackerrank.com/challenges/forward-references/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 = '/^(\\2tic|(tac))*$/'
// Regex Pattern:
// .
// ├── ^
// │ └── Denotes the start of the line
// ├── (\\2tic|(tac))
// │ ├── \\ - Denotes a '\' character
// │ ├── 2tic - Denotes the '2tic' string
// │ ├── | - Denotes a boolean OR operator
// │ └── (tac) - Denotes the 'tac' string
// ├── *
// └── Denotes the above expression for 0 or unlimited times, same as {0,}
// └── $
// └── Denotes the end of the line
// Example: tactactic
$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)
?>