aboutsummaryrefslogtreecommitdiff
path: root/challenge-266/2colours/php/ch-1.php
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-266/2colours/php/ch-1.php')
-rw-r--r--challenge-266/2colours/php/ch-1.php14
1 files changed, 14 insertions, 0 deletions
diff --git a/challenge-266/2colours/php/ch-1.php b/challenge-266/2colours/php/ch-1.php
new file mode 100644
index 0000000000..3079fd5dff
--- /dev/null
+++ b/challenge-266/2colours/php/ch-1.php
@@ -0,0 +1,14 @@
+<?php
+
+echo '$line1 = ';
+$line1 = preg_split('/\s+/', rtrim(fgets(STDIN)));
+echo '$line2 = ';
+$line2 = preg_split('/\s+/', rtrim(fgets(STDIN)));
+
+$word_frequencies = array_count_values($line1);
+foreach (array_count_values($line2) as $key => $value) {
+ @$word_frequencies[$key] += $value;
+}
+
+$solution = array_keys(array_filter($word_frequencies, fn($freq) => $freq === 1)) ?: [''];
+var_dump($solution);