generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: FindLargestSubstring

Previous Thread :: Next Thread 
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
17 Oct 2015 05:38 AM
When a function is 19 lines long, I can't help but feel I went overboard. Is there a simpler way of accomplishing it?

My code is here: http://pastebin.com/Mz3Q9hei

It takes a table of strings as the argument, and finds the largest substring that exists in each one. If there are multiple strings that are larger than the rest, but of equal length, it will return a tuple.
Report Abuse
FlyNormal is not online. FlyNormal
Joined: 30 Sep 2015
Total Posts: 344
17 Oct 2015 06:35 AM
That is pretty impressive. I'm not sure if I can attain a more efficient and a shorter code than that. The logic used behind your function is pretty strict and effective.
Report Abuse
brados123 is not online. brados123
Joined: 24 Nov 2012
Total Posts: 2143
17 Oct 2015 06:42 AM
congrats lol.


thanks guys
Report Abuse
IllegallyBlind is not online. IllegallyBlind
Joined: 07 Nov 2010
Total Posts: 1691
17 Oct 2015 06:45 AM
u just showin off


i make u math.sqrt()
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
17 Oct 2015 07:47 AM
lol Thanks guys, but are you sure there isn't a better way? I'm certainly not the best scripter here, for sure there's a shorter way? My function takes over half the script editor XD
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
17 Oct 2015 07:49 AM
I think I can change those 2 if statements to an if-elseif, because if it doesn't match, it'll break anyway.
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
17 Oct 2015 08:06 AM
I'm I'm positive it's not the most efficient. I sacrificed some efficiency to make it take up less of the script editor.
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
17 Oct 2015 08:09 AM
Yeah, here's an 18 liner:

http://pastebin.com/4GpCe7i2
Report Abuse
Kapitanovas is not online. Kapitanovas
Joined: 09 Sep 2012
Total Posts: 4216
17 Oct 2015 08:11 AM
well, I'm not a master at reading someone elses code, so to actually come up with an accurate diagnoses, I'd have to recreate it myself, which I feel lazy to do, but from what I saw though, it's all pretty good

"My Life is going Good... but..."
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
17 Oct 2015 08:19 AM
I can't help but feel as if this part here can be simplified:


for i = 1, #firststring do
for ii = i, #firststring do
matches[#matches+1] = firststring:sub(i, ii)
end
end


Can that be turned into 1 loop?
Report Abuse
Joe11Joe99 is not online. Joe11Joe99
Joined: 22 May 2011
Total Posts: 34458
17 Oct 2015 09:26 AM
yeah, OF COURSE THERE IS!
just shove it all into one line
Report Abuse
Joe11Joe99 is not online. Joe11Joe99
Joined: 22 May 2011
Total Posts: 34458
17 Oct 2015 09:30 AM
function FindLargestSubstring(strings)
local matches, substrings, length, firststring = {}, {}, 0, strings[1]; for i = 1, #firststring do; for ii = i, #firststring do; matches[#matches+1] = firststring:sub(i, ii);end end for i,v in pairs(matches) do; for ii,vv in pairs(strings) do; if not vv:match(v) then break; end if not next(strings, ii) then; length, substrings, substrings[#substrings+1] = #v > length and #v or length, #v > length and {v} or substrings, #v == length and v or nil; end end end ; return unpack(substrings)
end

there you go buddy
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
17 Oct 2015 09:58 AM
@Above I can make that shorter by removing ;s and some whitespace.

Besides, when beautified that still expands out. It don't count lol.
Report Abuse
Joe11Joe99 is not online. Joe11Joe99
Joined: 22 May 2011
Total Posts: 34458
17 Oct 2015 10:04 AM
"I can make that shorter by removing ;s and some whitespace.

Besides, when beautified that still expands out. It don't count lol."


the ;s end the variables so that you aren't including random values

and what does this term 'beautified' mean
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
17 Oct 2015 10:07 AM
You clearly don't understand the use of ;

And beautified means when a working beautifier plugin runs it, it creates a new script, and instead of 1 line, it will look readable.
Report Abuse
Joe11Joe99 is not online. Joe11Joe99
Joined: 22 May 2011
Total Posts: 34458
17 Oct 2015 10:08 AM
"You clearly don't understand the use of ;"
its to close off lines/variables, of course
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
17 Oct 2015 10:11 AM
The only REAL use of ; is to solve ambiguous syntax errors
Report Abuse
Joe11Joe99 is not online. Joe11Joe99
Joined: 22 May 2011
Total Posts: 34458
17 Oct 2015 10:12 AM
"The only REAL use of ; is to solve ambiguous syntax errors"

I'm pretty sure I know my python and c# code :/
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
17 Oct 2015 10:14 AM
But sadly not Lua
Report Abuse
Joe11Joe99 is not online. Joe11Joe99
Joined: 22 May 2011
Total Posts: 34458
17 Oct 2015 10:24 AM
"But sadly not Lua"

I'm pretty sure I know lua too :/

it is used to end lines and variables so that they don't get confused

just like in python and c#
but lua automatically puts it at the end of lines for you invisibly, anyways
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
17 Oct 2015 10:26 AM
Lua does no such thing...
Report Abuse
Joe11Joe99 is not online. Joe11Joe99
Joined: 22 May 2011
Total Posts: 34458
17 Oct 2015 10:28 AM
"Lua does no such thing..."

think what you want dude :/
but lua is a scripting language and it is designed to already do all these tthings for you :////
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
17 Oct 2015 10:36 AM
Lua doesn't insert semicolons. cntkillme said that. If you want to argue with him go ahead but I swear the only thing semicolons do (and no; they don't improve speed!) is solve ambiguous syntax errors.
Report Abuse
Happywalker is not online. Happywalker
Joined: 05 Mar 2010
Total Posts: 3672
17 Oct 2015 10:39 AM
"but lua automatically puts it at the end of lines for you invisibly, anyways"

trolol
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
20 Oct 2015 04:49 PM
Bump
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image