Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Scramble words in a string
- using Random
- function ScrambleWord(word::AbstractString)
- n = length(word)
- letters = split(word, "")
- upper = falses(n)
- for i = 1:n
- if letters[i] == uppercase(letters[i]); upper[i] = true; end
- end
- letters = letters[randperm(n)]
- for i = 1:n
- if upper[i]
- letters[i] = uppercase(letters[i])
- else
- letters[i] = lowercase(letters[i])
- end
- end
- return join(letters, "")
- end
- function main(s::AbstractString)
- dividers = [' ', ',', '.', ';', ':', '!', '`', '\"', '\'', '-', '(', ')']
- N = length(s)
- Z = Array{AbstractString}(undef, N)
- c = 0
- ind = 1
- for i = 1:N
- if s[i] in dividers
- c += 1
- Z[c] = ScrambleWord(s[ind:(i-1)])
- c += 1
- Z[c] = string(s[i])
- ind = i + 1
- end
- end
- return join(Z[1:c], "")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement