8000 added solution · dotmarn/algorithm-solution@33ce858 · GitHub
[go: up one dir, main page]

Skip to content

Commit 33ce858

Browse files
committed
added solution
1 parent b8c554a commit 33ce858

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

Morse code string to Words/index.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
function get_morse() {
3+
return $morse_codes = array(
4+
"A"=>".-",
5+
"B"=>"-...",
6+
"C"=>"-.-.",
7+
"D"=>"-..",
8+
"E"=>".",
9+
"F"=>"..-.",
10+
"G"=>"--.",
11+
"H"=>"....",
12+
"I"=>"..",
13+
"J"=>".---",
14+
"K"=>"-.-",
15+
"L"=>".-..",
16+
"M"=>"--",
17+
"N"=>"-.",
18+
"O"=>"---",
19+
"P"=>".--.",
20+
"Q"=>"--.-",
21+
"R"=>".-.",
22+
"S"=>"...",
23+
"T"=>"-",
24+
"U"=>"..-",
25+
"V"=>"...-",
26+
"W"=>".--",
27+
"X"=>"-..-",
28+
"Y"=>"-.--",
29+
"Z"=>"--..",
30+
"0"=>"-----",
31+
"1"=>".----",
32+
"2"=>"..---",
33+
"3"=>"...--",
34+
"4"=>"....-",
35+
"5"=>".....",
36+
"6"=>"-....",
37+
"7"=>"--...",
38+
"8"=>"---..",
39+
"9"=>"----.",
40+
"."=>".-.-.-",
41+
","=>"--..--",
42+
"?"=>"..--..",
43+
"/"=>"-..-.",
44+
" "=>" "
45+
);
46+
}
47+
48+
function possibilities($signals) {
49+
50+
$signals = str_replace(['.','?'],['\.','[.-]'],$signals);
51+
$regexp = '~^'.$signals.'$~';
52+
$morse_codes = get_morse();
53+
$result = [];
54+
55+
foreach ($morse_codes as $key => $value) {
56+
if (preg_match($regexp, $value)) {
57+
$result[$value] = $key;
58+
}
59+
}
60+
krsort($result);
61+
return array_values($result);
62+
63+
}

Morse code string to Words/question.md

Whitespace-only changes.

0 commit comments

Comments
 (0)
0