|
| 12 Nov 2013 07:35 PM |
How would I scramble a word with string manipulation?
For example my word is:
word
Then i scramble and get something
rwdo |
|
|
| Report Abuse |
|
|
|
| 12 Nov 2013 07:36 PM |
| Then I scramble it and get something like:* |
|
|
| Report Abuse |
|
|
| |
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 12 Nov 2013 07:55 PM |
| Show us what you go so far |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 12 Nov 2013 07:56 PM |
Oh pssht, you want one.
I guess you can just use a loop |
|
|
| Report Abuse |
|
|
|
| 12 Nov 2013 07:56 PM |
Nothing, I'm not very good with string manipulation.
Could gsub be used? |
|
|
| Report Abuse |
|
|
|
| 12 Nov 2013 07:59 PM |
| Cnt, what would I put in the loop? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 12 Nov 2013 08:01 PM |
This is probably a bad way but:
local str = "hello" local random = ""
local history = {} for i = 1, #str do repeat rnd = math.random(1, #str) until not history[rnd] random = random .. str:sub(rnd, rnd) end |
|
|
| Report Abuse |
|
|
|
| 12 Nov 2013 08:30 PM |
How would I make one that mixes up every word in a string? for example, string normal would be "I am a string" and string mixed up would be "i ma a trsign'
|
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 12 Nov 2013 08:40 PM |
local str = "hello there" local random = ""
local z = {} for x in str:gmatch("%S+") do table.insert(z, x) end
local history = {}
for i = 1, #z do for x = 1, #z[i] do repeat rnd = math.random(1, #z[i]) until not history[rnd] random = random .. z[i]:sub(rnd, rnd) end random = random .. " " end
probably won't work but w/e
|
|
|
| Report Abuse |
|
|
|
| 12 Nov 2013 08:46 PM |
function scramble(string) local pivot = math.random(#string / 2, #string) estring = "" for i = 1, #string do estring = string:sub(pivot, pivot)..estring pivot = pivot+1 if pivot > #string then pivot = 1 end end print(estring) end scramble("word") |
|
|
| Report Abuse |
|
|
|
| 12 Nov 2013 08:53 PM |
Cnt, your function kept the same length on either word but the word was compromised of random letters from the entire string.
Anybody else have an idea? |
|
|
| Report Abuse |
|
|
|
| 12 Nov 2013 08:59 PM |
function scramble(string) estring = "" for z in string:gmatch("%w+") do for y in string:gmatch("%s") do local pivot = math.random(#z / 2, #z) for i = 1, #z do estring = estring..z:sub(pivot, pivot) pivot = pivot+1 if pivot > #z then pivot = 1 end end estring = estring..y end end print(estring) end scramble("word hi")
Output:
rdwo ih |
|
|
| Report Abuse |
|
|
| |
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 12 Nov 2013 09:04 PM |
local input = "Hello There" local output = ""
local splittedInput = {} local lastHistory = {}
for value in input:gmatch("%S+") do table.insert(splittedInput, value) end
for word = 1, #splittedInput do for index = 1, #splittedInput[word] do repeat randomNumber = math.random(#splittedInput[word]) until not lastHistory[randomNumber] lastHistory[randomNumber] = true output = output .. splittedInput[word]:sub(randomNumber, randomNumber) end output = output .. " " lastHistory = {} end
print(output) |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 12 Nov 2013 09:05 PM |
| pssht I was late, stupid d/c'd internet |
|
|
| Report Abuse |
|
|
|
| 12 Nov 2013 09:07 PM |
This works better actually as there was a weird error with my 2nd.
function check(table, string) for i,v in pairs(table) do if v ~= string then return true end end return false end
function scramble(string) estring, check2 = "", {} for z in string:gmatch("%w+") do check(check2, z) table.insert(check2, z) local pivot = math.random(#z / 2, #z) for i = 1, #z do estring = estring..z:sub(pivot, pivot) pivot = pivot+1 if pivot > #z then pivot = 1 end end estring = estring.." " end print(estring) end scramble("word hi k pop") |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 12 Nov 2013 09:15 PM |
| Mine is shorted and more swaggy |
|
|
| Report Abuse |
|
|
|
| 12 Nov 2013 10:16 PM |
| One more question, would there be a way to change the amount of characters scrambled per string? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
|
| 12 Nov 2013 10:43 PM |
| TBH, I have alchohol im my game and a custom chat GUI. The more tipsy you get, the more jumbled your speech. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
| |
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 12 Nov 2013 11:03 PM |
| You are probably going to be banned but it really depends how you are going to use it |
|
|
| Report Abuse |
|
|
|
| 12 Nov 2013 11:42 PM |
The drinks are all named "SomeColorHere Drink"
The bartender tells you, after buying a drink, 'Don't drink to much, you'll get dizzy!'
I've childproofed the heck out of it. Can you help me out with the last request or not> |
|
|
| Report Abuse |
|
|