RosettaCodeData/Task/Morse-code/V-(Vlang)/morse-code.v

21 lines
969 B
Coq
Raw Permalink Normal View History

2024-10-16 18:07:41 -07:00
const morse_code = [["a", ".-"], ["b", "-..."], ["c", "-.-."], ["d", "-.."], ["e", "."],
2026-04-30 12:34:36 -04:00
["f", "..-."], ["g", "--."], ["h", "...."], ["i", ".."], ["j", ".---"],
["k", "-.-"], ["l", ".-.."], ["m", "--"], ["n", "-."], ["o", "---"],
["p", ".--."], ["q", "--.-"], ["r", ".-."], ["s", "..."], ["t", "-"],
["u", "..-"], ["v", "...-"], ["w", ".--"], ["x", "-..-"], ["y", "-.--"],
["z", "--.."], ["0", "-----"], ["1", ".----"], ["2", "..---"], ["3", "...--"],
["4", "....-"], ["5", "....."], ["6", "-...."], ["7", "--..."], ["8", "---.."],
["9", "----."]]
2024-10-16 18:07:41 -07:00
fn main() {
2026-04-30 12:34:36 -04:00
str := "this is a test text"
mut strmorse := ""
for n, _ in str {
if str[n].ascii_str() ==" " {strmorse += " "}
for m, _ in morse_code {
if morse_code[m][0] == str[n].ascii_str() {strmorse += morse_code[m][1] + "|"}
}
}
println(strmorse.all_before_last("|"))
2024-10-16 18:07:41 -07:00
}