[ create a new paste ] login | about

Link: http://codepad.org/T2cG3fe1    [ raw code | output | fork ]

Ruby, pasted on Aug 27:
def morse(str,morse)
	decode_array = [["A","._"],["B","_..."],["C","_._."],["D","_.."],["E","."],["F",".._."],["G","__."],["H","...."],["I",".."],["J",".___"],["K","_._"],["L","._.."],["M","__"],["N","_."],["O","___"],["P",".__."],["Q",".._."],["R","._."],["S","..."],["T","_"],["U",".._"],["V","..._"],["W",".__"],["X","_.._"],["Y","_.__"],["Z","__.."],["1",".____"],["2","..___"],["3","...__"],["4","...._"],["5","....."],["6","_...."],["7","__..."],["8","___.."],["9","____."],["10","_____"]]
	n_arr = []
	if morse == true
		str = str.split(" ")
		for i in str
			p = 0
			while p < decode_array.length
				if i == decode_array[p][1]
					n_arr << decode_array[p][0] << " "
				end
				p += 1
			end
		end
	else
		str = str.split(//)
		for i in str
			p = 0
			while p < decode_array.length
				if i == decode_array[p][0]
					n_arr << decode_array[p][1] << " "
				end
				p += 1
			end
		end
	end
	return n_arr.join
end

puts morse("S O S",false)


Output:
1
... ___ ... 


Create a new paste based on this one


Comments: