| |
|
»
»
|
|
| |
Re: Scripting Challenge
|
|
|
|
| 13 Apr 2016 11:26 PM |
local Letters = {"F","B","C","G","I","M","Z","V","R"} local Numbers = {0,1,2,3,4,5,6,7,8,9}
Task: Given the tables above create a random code generator that is 7 characters long...
Rules: -Shortest Length Wins -Efficiency
Winner will receive a special prize! |
|
|
| Report Abuse |
|
|
Repotted
|
  |
| Joined: 26 Nov 2011 |
| Total Posts: 4990 |
|
|
| 13 Apr 2016 11:55 PM |
local characters = {"F","B","C","G","I","M","Z","V","R","0","1","2","3","4","5","6","7","8","9"} local string = "" for i = 1, 7 do string = string .. characters[math.random(1,#characters)] end
|
|
|
| Report Abuse |
|
|
|
| 14 Apr 2016 12:04 AM |
Let's say it's not 100% efficient, but if I were to code this in C# I would making a super efficient script
local Letters = {"F","B","C","G","I","M","Z","V","R"} local Numbers = {0,1,2,3,4,5,6,7,8,9} local code = ""; local r = 0;
for i = 1,7 do r = math.random(1,2); if r == 1 then code = code.. Letters[math.random(0,#Letters)]; elseif r == 2 then code = code..tostring(Numbers[math.random(0,#Numbers)]); end end print(code);
~ I fight bosses for a living ~ |
|
|
| Report Abuse |
|
|
Salinas23
|
  |
| Joined: 28 Dec 2008 |
| Total Posts: 37142 |
|
|
| 14 Apr 2016 01:32 AM |
what an easy way to make people script stuff for you lol
disguise it in a "contest" theme
-Salinas con el número 23 |
|
|
| Report Abuse |
|
|
|
| 14 Apr 2016 01:44 AM |
characters = {"F","B","C","G","I","M","Z","V","R","0","1","2","3","4","5","6","7","8","9"} function gen(num) str = ""; repeat srt = str .. characters[math.Random(#characters)]; until string.len(str) == num; return str end
gen(7) |
|
|
| Report Abuse |
|
|
Froast
|
  |
| Joined: 12 Mar 2009 |
| Total Posts: 3134 |
|
|
| 14 Apr 2016 02:25 AM |
k=table.concat t=k(Letters)..k(Numbers) c='' for i=1,7 do r=math.random(1,#t) c=c..t:sub(r,r) end |
|
|
| Report Abuse |
|
|
|
| 14 Apr 2016 07:27 PM |
| It's not a contest, and I do know how to create a script like this. The contest ends in about 3 hours... So if you'd like to try it give it a shot! |
|
|
| Report Abuse |
|
|
|
| 14 Apr 2016 08:07 PM |
tbh only scripting this because there was really nothing to do
math.randomseed(math.floor(os.time())) t = {'A',1,'B',1,'C',2,'D',2,'E',3,'F',3, 'G',4,'H',4,'I',5,'J',6,'K',7,8,'L',9, 'M',1,'N',2,'O',3,'P',4,'Q',5,'R',6, 'S',7,'T',8,'U',9,'V',1,'W',2,'X',3, 'Y',4,'Z',5,'a',6,'b',7,'c',8,'d',9,'e',1,'f',2, 'g',3,'h',4,'i',5,'j',6,'k',7, 'l',8, 'm',9,'n',1,'o',2,'p',3,'q',4,'r', 's',5,'t',6,'u',7,'v',8,'w',9,'x',1, 'y',2,'z',3}
value = ''
for i,v in pairs(t) do if i == 8 then print (value) break end local m = math.random(1,#t) value = value..t[math.random(1,#t)] end
|
|
|
| Report Abuse |
|
|
|
| 14 Apr 2016 08:08 PM |
what an easy way to make people script stuff for you lol
disguise it in a "contest" theme [2]
r+://393244197r+://393244224r+://393244262 |
|
|
| Report Abuse |
|
|
|
| 14 Apr 2016 09:01 PM |
@Trollers
math.randomseed(math.floor(os.time())) local C={"F","B","C","G","L","M","Z","V","R",0,1,2,3,4,5,6,7,8,9} local V = '' for i = 1,7 do V = V..C[math.random(1,#C)] end |
|
|
| Report Abuse |
|
|
|
| 14 Apr 2016 09:27 PM |
@OP 2 people posted the exact same thing.. *noob*
|
|
|
| Report Abuse |
|
|
|
| 14 Apr 2016 09:29 PM |
local Letters = {"F","B","C","G","I","M","Z","V","R"} local Numbers = {0,1,2,3,4,5,6,7,8,9} "Task: Given the TABLES ABOVE create a random code generator that is 7 characters long..."
OP's solution: local C={"F","B","C","G","L","M","Z","V","R",0,1,2,3,4,5,6,7,8,9}
|
|
|
| Report Abuse |
|
|
Froast
|
  |
| Joined: 12 Mar 2009 |
| Total Posts: 3134 |
|
|
| 14 Apr 2016 09:50 PM |
| lol I was thinking the same thing |
|
|
| Report Abuse |
|
|
|
| 14 Apr 2016 10:57 PM |
a={"F","B","C","G","I","M","Z","V","R",0,1,2,3,4,5,6,7,8,9} for i=#a,2,-1 do j=math.random(i)a[i],a[j]=a[j],a[i]end v=select(12,unpack(a))
139 characters
|
|
|
| Report Abuse |
|
|
|
| 14 Apr 2016 11:01 PM |
a={"F","B","C","G","I","M","Z","V","R",0,1,2,3,4,5,6,7,8,9} for i=#a,2,-1 do j=math.random(i)a[i],a[j]=a[j],a[i]end print(select(12,unpack(a)))
|
|
|
| Report Abuse |
|
|
Repotted
|
  |
| Joined: 26 Nov 2011 |
| Total Posts: 4990 |
|
|
| 14 Apr 2016 11:16 PM |
merging lines together doesn't make it 'shorter'
|
|
|
| Report Abuse |
|
|
|
| 14 Apr 2016 11:16 PM |
@Repotted it actually does in some cases.
~ I fight bosses for a living ~ |
|
|
| Report Abuse |
|
|
|
| 14 Apr 2016 11:18 PM |
Assuming I am required to use both tables with those variable names, here's my attempt.
r,s=math.random,""for n=1,7 do a=({Letters,Numbers})[r(2)]s=s..a[r(#a)]end 74 characters
|
|
|
| Report Abuse |
|
|
|
| |
|
|
| |
|
»
»
|
|
|
|
|