|
| 13 May 2014 07:24 PM |
First off, if this is the wrong sub-forum, kindly guide me there.
-- Rules --
1. Must only ban players with a number "8" and a word "oreo" in their name.
2. This should also run effectively(meaning it doesn't break if something is nil and would be most ideal to use).
3. I will not judge, this is purely for fun.
I will post mine first:
str,str2 = "Player","1"game.Players.PlayerAdded:connect(function(p)if p.Name:lower():match(str)and p.Name:match(str2)then p:Kick()end end)
|
|
|
| Report Abuse |
|
|
|
| 13 May 2014 07:25 PM |
str,str2 = "oreo","8"game.Players.PlayerAdded:connect(function(p)if p.Name:lower():match(str)and p.Name:match(str2)then p:Kick()end end)
changed strings |
|
|
| Report Abuse |
|
|
|
| 13 May 2014 07:28 PM |
game.Players.ChildAdded:connect(function(p)if p.Name:lower():find("oreo")and p.Name:find("8")then p:Kick()end end)
115 as opposed to 137 of OP's solution (though his can be trivially reduced by 11 characters by only refactoring) |
|
|
| Report Abuse |
|
|
TexasOreo
|
  |
| Joined: 08 Apr 2014 |
| Total Posts: 25 |
|
|
| 13 May 2014 07:34 PM |
Why u hate oreos
game.Players.ChildAdded:connect(function(p)if p.Name:lower():find("oreo","8")then p:Kick()end end)
I win |
|
|
| Report Abuse |
|
|
TexasOreo
|
  |
| Joined: 08 Apr 2014 |
| Total Posts: 25 |
|
|
| 13 May 2014 07:39 PM |
even shorter Players:connect(while ChildAdded(function(c))if c.Name:find("oreo%d+")then c:Kick()end end) |
|
|
| Report Abuse |
|
|
|
| 13 May 2014 07:44 PM |
^first post on forums(if that is a main)
and I do not think those work. |
|
|
| Report Abuse |
|
|
MettaurSp
|
  |
| Joined: 20 Mar 2010 |
| Total Posts: 3179 |
|
|
| 13 May 2014 08:17 PM |
Don't see the point of this challenge, but:
while 1 do p=game.Players.PlayerAdded:wait()if p.Name:lower():find(".*8?.*oreo.*8?.*")then p:Kick()end end
106 characters |
|
|
| Report Abuse |
|
|
Insoul
|
  |
| Joined: 04 May 2014 |
| Total Posts: 66 |
|
|
| 13 May 2014 10:18 PM |
function dohax(user)user:kick();end; dohax(game.Players.localPlayer)
won
herro Im syKo |
|
|
| Report Abuse |
|
|
Oreoism
|
  |
| Joined: 11 Apr 2014 |
| Total Posts: 64 |
|
| |
|
|
| 14 May 2014 12:22 PM |
In a LocalScript:
if string.lower(Players.LocalPlayer.Name):match('%d')==8 then Players.LocalPlayer:Kick() end |
|
|
| Report Abuse |
|
|
200AB
|
  |
| Joined: 24 Aug 2010 |
| Total Posts: 1604 |
|
|
| 14 May 2014 01:07 PM |
game.Players.ChildAdded:connect(function(p) g=function(m) return p.Name:lower():match(m) end if g"oreo" and g"8" then p:Kick() end end)
Do I win? |
|
|
| Report Abuse |
|
|
|
| 14 May 2014 02:20 PM |
Didnt win with the shortest one now did I :(
\103\97\109\101\46\80\108\97\121\101\114\115\46\67\104\105\108\100\65\100\100\101\100\58\99\111\110\110\101\99\116\40\102\117\110\99\116\105\111\110\40\112\41\32\103\61\102\117\110\99\116\105\111\110\40\109\41\32\114\101\116\117\114\110\32\112\46\78\97\109\101\58\108\111\119\101\114\40\41\58\109\97\116\99\104\40\109\41\32\101\110\100\32\105\102\32\103\34\111\114\101\111\34\32\97\110\100\32\103\34\56\34\32\116\104\101\110\32\112\58\75\105\99\107\40\41\32\101\110\100\32\101\110\100\41 |
|
|
| Report Abuse |
|
|
MettaurSp
|
  |
| Joined: 20 Mar 2010 |
| Total Posts: 3179 |
|
| |
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 14 May 2014 03:19 PM |
while{}do p=game.Players.PlayerAdded:wait()n=p.Name:lower()if n:find'oreo'and n:find'8'then p:Kick()end end
-> 108 characters
I'm pretty sure that this is the optimal functional solution, for kicking from a server script at least. Some of the solutions here are shorter but don't actually work. Some points:
- Unfortunately there isn't any way to I can see to check for both 8 *and* oreo using a single string function call: If it were or you could use some tricks, but for and you probably need two calls.
- There's definitely not room for you to make and function definitions. Each function definition costs you _at least_ 13 characters, and you actually have to call that function after you define it, which adds additional parenthesis unless you're clever. So, your function would have to be saving you a lot of characters to actually be worth it.
- Looping through all of the players is definitely out of the question, too much space adding an additional loop, so using PlayerAdded is the right approach.
- With no room for function defs,:wait() is definitely better than :connect()
- The best loop to use is a while loop: repeat ... until ... takes one more character than while ... do ... end
- The shortest looping construct you can use for the forever loop is "while{}do", there is no shorter symbol than 2 characters that can fit in the condition space and not combine with the keywords.
- My proposed solution is whitespace minimizing: The problem requires that you have some elements for sure: * An "and", in order to test both the 8 and oreo strings, since none of the built in string operations let you test for both in a single call. * An "if", to decide whether to call kick. With a more complex problem it's likely that you'd have possibility to use some sort of table index trick to avoid ifs, but there's no space to consider that sort of thing for this simple problem. * A "do" for the while loop * A "then" on the if. * Two "ends", one on the if, one on a loop of some sort. None of these constructs can have anything "useful" after them that won't combine with them, so they require spaces after them. My solution has only 5 spaces in it, after each of those necessary constructs.
|
|
|
| Report Abuse |
|
|
|
| 14 May 2014 03:35 PM |
If we eliminate the if and instead of use short-circuiting:
while{}do p=game.Players.PlayerAdded:wait()n=p.Name:lower();k=n:find"8"and n:find"oreo"and p:Kick()end
103 characters |
|
|
| Report Abuse |
|
|
MettaurSp
|
  |
| Joined: 20 Mar 2010 |
| Total Posts: 3179 |
|
|
| 14 May 2014 03:45 PM |
while{}do p=game.Players.PlayerAdded:wait()if p.Name:lower():find(".*8?.*oreo.*8?.*")then p:Kick()end end
105 characters and it does work. Thanks for the while{}do trick stravant. |
|
|
| Report Abuse |
|
|
MettaurSp
|
  |
| Joined: 20 Mar 2010 |
| Total Posts: 3179 |
|
|
| 14 May 2014 03:48 PM |
while{}do p=game.Players.PlayerAdded:wait()b=p.Name:lower():find(".*8?.*oreo.*8?.*")and p:Kick()end
99 characters. |
|
|
| Report Abuse |
|
|
|
| 14 May 2014 03:51 PM |
| Doesn't work. Kicks "oreo" because both 8's are optional. |
|
|
| Report Abuse |
|
|
Oysi
|
  |
| Joined: 06 Jul 2009 |
| Total Posts: 9058 |
|
|
| 14 May 2014 03:51 PM |
^ stop it, that's not the proper matching.
print( ("oreo"):match(".*8?.*oreo.*8?.*") ) |
|
|
| Report Abuse |
|
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 14 May 2014 03:52 PM |
":find(".*8?.*oreo.*8?.*")"
This doesn't work for either the "and" or the "or" case: - It does find strings with "8" _and_ "oreo" in them - It does find strings with just "oreo" in them - It does not find strings with just "8" in them
And there's no way to fix it while leaving it as a single expression. "or" / "and" like operations on multi-character patterns aren't supported by Lua's pattern matching within a single match. The idea is that you use multiple matches for those cases. |
|
|
| Report Abuse |
|
|
MettaurSp
|
  |
| Joined: 20 Mar 2010 |
| Total Posts: 3179 |
|
|
| 14 May 2014 03:53 PM |
| True, forgot that. Still experimenting with em so I often forget restrictions. |
|
|
| Report Abuse |
|
|
MettaurSp
|
  |
| Joined: 20 Mar 2010 |
| Total Posts: 3179 |
|
|
| 14 May 2014 04:08 PM |
| Blue's solution can be shortened by one character by removing the semicolon, but it still is his solution. |
|
|
| Report Abuse |
|
|
Bassics
|
  |
| Joined: 24 Apr 2012 |
| Total Posts: 415 |
|
|
| 14 May 2014 04:15 PM |
| Couldn't "ChildAdded" be used instead of "PlayerAdded" for one less character? |
|
|
| Report Abuse |
|
|
|
| 14 May 2014 04:18 PM |
Yea, I noticed that, and have been looking for any other improvements.
while{}do p=game.Players.PlayerAdded:wait()n=p.Name;k=n:find"8"and n:lower():find"oreo"and p:Kick()end
102 characters (a shortened version of stravant's submission)
The only redundancy I see is in "find" and in the number of assignments. Unfortunately, apparently comma separated variables in an assignment are updated based on previous values, so chaining these assignments together can't be done (it would be nice if this could be done with `k`, since its name is not even used; but since it relies on `n` it can't be chained into that)
Bassics: I suggested that much earlier. Technically, yes, but it is wrong as a robust solution, since other instances *can* be added to Players, and the winning script shouldn't process them. If we're being so pedantic, it probably should also be required for us to use GetService, too... |
|
|
| Report Abuse |
|
|
|
| 14 May 2014 04:52 PM |
| Can't you use a localscript instead of PlayerAdded? |
|
|
| Report Abuse |
|
|