Learning LUA in anticipation for NS2?

WhiteZeroWhiteZero That Guy Join Date: 2004-06-24 Member: 29511Members, Constellation
<div class="IPBDescription">Roll call!</div>I've always had an interest in programming but never got that deep into it (mostly a bit of VisualBasic in highschool). But now I'm committing myself to spend at least an hour per day studying C++ and LUA. Sense the two languages go hand-in-hand and I have a couple C++ books lying around, I figured I'd start learning both.

Has anyone else started to try to learn LUA in preparation for NS2 modding? I'm sure there are a few people here that already know some LUA after messing with GMOD. <img src="style_emoticons/<#EMO_DIR#>/biggrin-fix.gif" style="vertical-align:middle" emoid=":D" border="0" alt="biggrin-fix.gif" />

Comments

  • JAmazonJAmazon Join Date: 2009-02-21 Member: 66503Members
    I wanna try getting my hands on mapping. I never really mapped seriously for any game, but i really want to try and squeeze out at least one real map for NS2.
  • Nima_Nima_ Join Date: 2007-08-30 Member: 62083Members
    I might delve into the depths of another language. I'm tipping LUA will be a breeze. The hardest thing is learning the infrastructure of the code already existing.
  • homicidehomicide Join Date: 2003-11-10 Member: 22451Members
    How does LUA and C++ go hand in hand?

    I have almost no experience with LUA, but from what I can tell it looks nothing like the C++ I am familiar with.
  • Dalin SeivewrightDalin Seivewright 0x0000221E Join Date: 2007-10-20 Member: 62685Members, Constellation
    edited June 2009
    I decided to sum up my post for once. <img src="style_emoticons/<#EMO_DIR#>/biggrin-fix.gif" style="vertical-align:middle" emoid=":D" border="0" alt="biggrin-fix.gif" />
    1. Get a game you know has some support for Lua scripting. G-Mod, as you say, is one. WoW is another. Vendetta Online is yet another.
    2. Most integrated Lua systems will be just slightly different than the next, as they would have in-house modifications, and restrictions, etc. (you don't want a Lua script to be able to access the operating system of the client for example)
    3. Once you've learned the basic syntax <a href="http://www.lua.org/manual/5.1/" target="_blank">(reading assignment)</a> its probably a good idea to move on to Lua in its own seperate environment. You can do so by building the Lua interpreter/compiler from its source or download the binaries directly. Some downloads (particularly Lua for Windows) will come with some nice "modules" that will allow you to create interfaces, connect to a database, etc. Links can be found <a href="http://www.lua.org/download.html" target="_blank">here</a>
    4. Find some small projects (<a href="http://projecteuler.net/" target="_blank">Project Euler</a> anyone?) that would present some sort of challenge for you and try to implement it with Lua. I've done some pretty neat stuff myself and there is no task Lua can't accomplish (almost).
    5. Pray that the devs made Object Oriented programing with Lua friendlier than it is out of the box.

    A note about its syntax: If you're familiar at all with Java/C++/Python, you'll pick up on the syntax fairly immediately. Lua does away with braces however and might look more like Basic. Its a snap once you start working with it though.
    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->function MyFunction(a,b,c)
        print(a,b,c)
    end

    if(Test ~= nil ) then
      print("Yay!")
    end

    myArray = {}
    myArray["Associative Arrays Are Pwnage!"] = "omgzor?  wow!"
    print(myArray["Associative Arrays Are Pwnage!"])
    --> "omgzor? wow!"<!--c2--></div><!--ec2-->
  • StreptoStrepto Join Date: 2005-01-07 Member: 33571Members
    Thanks Dalin for those links, has helped me get going with LUA.

    <b>ALL CREDIT FOR THIS GOES TO DALIN!</b>

    And for those that are sort of interested in LUA but don't know where to start ("WHERE IS THE COMPILER?!?"), you can start doing some Euler projects on the LUA:Demo site.

    Euler problems (these you try to solve with LUA):
    <a href="http://projecteuler.net/index.php?section=problems" target="_blank">http://projecteuler.net/index.php?section=problems</a>

    LUA:Demo allows you to run simple LUA code in your browser:
    <a href="http://www.lua.org/cgi-bin/demo" target="_blank">http://www.lua.org/cgi-bin/demo</a>


    Just to have a stab at it I did the first Euler problem (I am not an experienced programmer)

    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->-- Euler project
    -- Problem 1

    a = 3
    b = 5
    sum = 0

    top_a = math.floor(1000/a)
    top_b = math.floor(1000/b)

    for i=1,top_a,1 do sum = sum + i*a end
    for i=1,top_b,1 do sum = sum + i*b end

    io.write("Finding the sum of all the multiples of 3 or 5 below 1000\n")
    io.write("The highest multiple for the number ", a ,", without going over 1000 is: ", top_a,"\n")
    io.write("The highest multiple for the number ", b ,", without going over 1000 is: ", top_b,"\n\n")

    io.write("The sum of all multiples of 3 and 5 below 1000 is: ", sum)<!--c2--></div><!--ec2-->

    Executed on LUA:Demo you get:

    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->Finding the sum of all the multiples of 3 or 5 below 1000
    The highest multiple for the number 3, without going over 1000 is: 333
    The highest multiple for the number 5, without going over 1000 is: 200

    The sum of all multiples of 3 and 5 below 1000 is: 267333<!--c2--></div><!--ec2-->


    Would be nice to get a forum up for LUA learners soon, it's more fun to learn together <img src="style_emoticons/<#EMO_DIR#>/wink-fix.gif" style="vertical-align:middle" emoid=";)" border="0" alt="wink-fix.gif" />
  • Dalin SeivewrightDalin Seivewright 0x0000221E Join Date: 2007-10-20 Member: 62685Members, Constellation
    edited June 2009
    Note: If you're still looking for the "compiler" for Windows (which isn't exactly correct... Lua is an interpreted language so you'd be looking for the interpreter but Lua comes with a bytecode cmpiler that turn your code into byte-code that the Lua interpreter can read...) you can head over to <a href="http://luabinaries.luaforge.net/download.html" target="_blank">LuaBinaries</a>. Find the appropriate download link and unzip it into a folder (I believe this is the version you don't need to install to use, unlike Lua For Windows).
    To use the interpreter, you can either run the lua5.1.exe directly from the command prompt, after which it will run like the Lua Demo on the Lua site, or you can pass it a filename from the command prompt. This will then execute the interpreter and have it interpret the code inside MyLuaProgram.lua. Its probably best to use a text editor that supports the command-line so you can press a key, execute the lua interpreter, and capture the "output" into the text editor you're using. I prefer <a href="http://www.contexteditor.org/" target="_blank">ConTEXT</a> for this, but dozens of text editors have that very same feature.
    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->>lua5.1.exe C:\MyLuaProgram.lua<!--c2--></div><!--ec2-->


    A very nice attempt Strepto, but there is a small problem with your code. I believe the problem lies when you do the summation of the numbers. The question is "Find the sum of all numbers below 1000 that are multiples of either 3 or 5." and your code assumes that these are exclusive cases. For example, 12 is not a multiple of 5 but it is of 3. If we take a look at 15, we find that it is a multiple of 3 and 5.

    Your code first sums up the numbers that are multiples of 3, (like 15) and then the numbers that are multiples of 5 (like 15). So, while it would be correct if a single number did not have another divisor, but since there are multiple numbers that 3 and 5 both go into evenly, then the final count you get includes these numbers twice.

    Here is my solution (now I didn't know io.write existed, heh, but print = io.write):
    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->--Program that finds the sum of all multiples of 3 or 5 from 1 to 1000.
    sum = 0
    for i = 1, 999 do
        
        --MODULUS
        --result = a - b*floor(a/b)
        
        if( ((i - 3*math.floor(i/3)) == 0) or ((i-5*math.floor(i/5)) == 0) ) then
              sum = sum + i
        end
        

    end
    print("Sum: " .. sum)<!--c2--></div><!--ec2-->
    The correct answer is: 233168.

    "result = a - b*math.floor(i/3)" finds the result of a modulus operation (which I don't think exists in Lua as part of the math library) that is, it finds the remainder of one number divided by another. I think it goes about it in another way though, but if i is a multiple of 3, then "3*math.floor(i/3)" will return i and "i-i" is 0 so we know there is no remainders.

    The if statement itself is pretty simple. If (i - result of modulus check for multiples of 3) is 0 or if (i - result of modulus check for multiples of 5) is 0 then we add i to the sum. This will catch all numbers that are multiples of 3 or 5 and add them once.

    Hope that helps.

    I also suggested there be a Lua forum, but the idea didn't stick. That was a little early in the game then, but perhaps now would be an appropriate time. Then again, there could always just be a running Lua thread for Project Euler <img src="style_emoticons/<#EMO_DIR#>/biggrin-fix.gif" style="vertical-align:middle" emoid=":D" border="0" alt="biggrin-fix.gif" />
  • WhiteZeroWhiteZero That Guy Join Date: 2004-06-24 Member: 29511Members, Constellation
    <!--quoteo(post=1710543:date=Jun 6 2009, 12:50 AM:name=homicide)--><div class='quotetop'>QUOTE (homicide @ Jun 6 2009, 12:50 AM) <a href="index.php?act=findpost&pid=1710543"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->How does LUA and C++ go hand in hand?

    I have almost no experience with LUA, but from what I can tell it looks nothing like the C++ I am familiar with.<!--QuoteEnd--></div><!--QuoteEEnd-->
    From the LUA manual:
    "Lua is implemented as a library, written in clean C (that is, in the common subset of ANSI C and C++)."
  • devicenulldevicenull Join Date: 2003-04-30 Member: 15967Members, NS2 Playtester, Squad Five Blue
    LUA's actually pretty simple once you get over a few completely backwards language "features".. I've actually already written the basics of an admin system, though I'm kind of limited to how far I can go considering I have no idea what the NS2 API looks like.
  • StreptoStrepto Join Date: 2005-01-07 Member: 33571Members
    <!--quoteo(post=1710595:date=Jun 6 2009, 08:09 AM:name=Dalin Seivewright)--><div class='quotetop'>QUOTE (Dalin Seivewright @ Jun 6 2009, 08:09 AM) <a href="index.php?act=findpost&pid=1710595"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->A very nice attempt Strepto, but there is a small problem with your code. I believe the problem lies when you do the summation of the numbers. The question is "Find the sum of all numbers below 1000 that are multiples of either 3 or 5." and your code assumes that these are exclusive cases. For example, 12 is not a multiple of 5 but it is of 3. If we take a look at 15, we find that it is a multiple of 3 and 5.<!--QuoteEnd--></div><!--QuoteEEnd-->

    So very true, guess I shoulda thought about that >.<

    Was trying to figure out a way to calculate the sum without doing the check if a number is the multiple of both 3 and 5 every single time you add to the sum. Which I believe should make the code a little faster?

    Fixed my code, I also didn't take into account that the multiples should be BELOW 1000 (200*5=1000), which further made my calculation erronous. Really wanted to avoid calling functions in the loops. I have no idea if the execution time is lower or not, but perhaps you can tell me that <img src="style_emoticons/<#EMO_DIR#>/wink-fix.gif" style="vertical-align:middle" emoid=";)" border="0" alt="wink-fix.gif" />

    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->a = 3
    b = 5
    c = a*b
    sum = 0

    top_a = math.floor(999/a)
    top_b = math.floor(999/b)
    top_c = math.floor(999/c)

    for i=1,top_a,1 do sum = sum + i*a end
    for i=1,top_b,1 do sum = sum + i*b end
    for i=1,top_c,1 do sum = sum - i*c end<!--c2--></div><!--ec2-->

    Sum is now correctly calculated to 233168

    Anyways, this forum is NS2 General Discussion, and Euler problems aren't really NS2 <img src="style_emoticons/<#EMO_DIR#>/smile-fix.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile-fix.gif" />

    Hopefully we'll see an appropriate forum for LUA in the future.
  • homicidehomicide Join Date: 2003-11-10 Member: 22451Members
    <!--quoteo(post=1710601:date=Jun 6 2009, 06:04 AM:name=WhiteZero)--><div class='quotetop'>QUOTE (WhiteZero @ Jun 6 2009, 06:04 AM) <a href="index.php?act=findpost&pid=1710601"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->From the LUA manual:
    "Lua is implemented as a library, written in clean C (that is, in the common subset of ANSI C and C++)."<!--QuoteEnd--></div><!--QuoteEEnd-->

    Simply because LUA is implemented in C doesn't mean the LUA language itself is anything like C.
    The java virtual machine is also written in C, but that doesn't mean the language is similar. Hell, many languages are implemented in C at their core: Java, Perl, php, etc... Inherently, the entire purpose of these languages is to be different than C.
  • WhiteZeroWhiteZero That Guy Join Date: 2004-06-24 Member: 29511Members, Constellation
    <!--quoteo(post=1710662:date=Jun 6 2009, 04:38 PM:name=homicide)--><div class='quotetop'>QUOTE (homicide @ Jun 6 2009, 04:38 PM) <a href="index.php?act=findpost&pid=1710662"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->Simply because LUA is implemented in C doesn't mean the LUA language itself is anything like C.
    The java virtual machine is also written in C, but that doesn't mean the language is similar. Hell, many languages are implemented in C at their core: Java, Perl, php, etc... Inherently, the entire purpose of these languages is to be different than C.<!--QuoteEnd--></div><!--QuoteEEnd-->
    LUA has a C (C++) API, and thats all I was really meaning. I guess I should have said "They can go hand-in-hand". Don't look too much into it.

    Anyway, yeah Strepto and Dalin, I appreciate your interest in the topic, but please keep the LUA tutorials to the LUA community. Lets keep this on-topic with NS2.
  • JAmazonJAmazon Join Date: 2009-02-21 Member: 66503Members
    Theres a closed form for any sum of like that, you don't need the computationally heavy loops.

    -----------------------

    --Program that finds the sum of all multiples of 3 or 5 from 1 to 1000.

    n = math.floor(1000/3)
    m = math.floor(1000/5)
    p = math.floor(1000/15)

    sum = 3*n*(n+1)/2 + 5*m*(m+1)/2 - 15*p*(p+1)/2

    -----------------------

    and the correct answer is actually 234168. Your programs fail to compensate for the fact that 1000 is also a multiple of 5.
  • areamanareaman Join Date: 2004-06-27 Member: 29584Members, Constellation
    I am a software engineer, if you can master the fundamentals of C++ or Python then you'll be fine for scripting. LUA should be a breeze if you 'get it'
  • descendantdescendant Join Date: 2009-05-30 Member: 67547Members
    JAmazon, i think you made your own little assignment.. The problem goes: "Find the sum of all the multiples of 3 or 5 below 1000." (http://projecteuler.net/index.php?section=problems&id=1). <img src="style_emoticons/<#EMO_DIR#>/smile-fix.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile-fix.gif" />
  • JAmazonJAmazon Join Date: 2009-02-21 Member: 66503Members
    Oops <img src="style_emoticons/<#EMO_DIR#>/tounge.gif" style="vertical-align:middle" emoid=":p" border="0" alt="tounge.gif" /> yeah I copied the problem statement as it is on Dalin's code, which was really ambiguous. Still a closed form though, just replace the 1000's with 999's.
  • homicidehomicide Join Date: 2003-11-10 Member: 22451Members
    I will be working on a project, hopefully to help establish a competitive community. I am not yet sure what capability LUA will have, but I few of the things I would like to implement:

    <b>Competitive Player Database</b>
    A database of registered players, their steam ID, location, and team; designed to facilitate organized pugs, scrims, and matches. Optimistically, expanding into an NS2 league. Accompanied by a plugin that allows servers to easily verify player identity.

    <b>Ingame Pug System</b>
    A server plugin that allows players to sign up for pugs in game, from across many public servers. Once enough players have signed up they will automatically be transferred to a private server. Only players registered with the organized player database will be allowed to signup.

    In order to accomplish these things socket level communication will be required. This all of course depends on how UWE takes things themselves and what tools they offer us, but the premise is obvious.

    Let me know if you are interested in helping is such projects.
  • WhiteZeroWhiteZero That Guy Join Date: 2004-06-24 Member: 29511Members, Constellation
    Great idea, homicide, I hope it works out.

    Maybe by the time we get our hands on NS2 I will have learned LUA and I can do my own MOD. I think I'd like to MOD in a MvM mode. <img src="style_emoticons/<#EMO_DIR#>/biggrin-fix.gif" style="vertical-align:middle" emoid=":D" border="0" alt="biggrin-fix.gif" />
  • FortuneFortune Join Date: 2009-04-27 Member: 67290Members, Constellation
    I already plan on delving into the map editor when it's released, I'm advanced with source and getting pretty good with unreal now. I did look into learning LUA for NS2 though, I'd like to make a few modifications... maybe for a specific map I'll make or an actual gameplay mod. Never really 'got' programming before but I'm pretty committed right at the moment. Those tutorials will help.
  • TinCanTinCan Join Date: 2006-12-11 Member: 59010Members
    I plan to at least have a general understanding how to hack at it to get results needed.
  • JAmazonJAmazon Join Date: 2009-02-21 Member: 66503Members
    I say we get post a weekly programming problem and see who can come up with the most elegant solution. That way we hone our LUA skills and the winner is the program with the least order of divergence.
  • PrivatePrivate Join Date: 2007-06-10 Member: 61204Members, Constellation
    Sounds like a lot of fun. Also, I would like to point out that this probably belongs in the Lua section of the NS2 Creation forum.
    That being said, I would like to propose an exercise.

    You are tasked with solving any Sudoku.

    The program input will be a string representation of any sudoku, the program output is expected to be the same sudoku in a similar format, with no missing numbers.

    Allow me to elaborate; A sudoku:

    2 x x 3 6 7 5 x x
    5 x x 8 x x x 6 x
    3 x x 4 5 x 7 x x
    x 9 x 5 3 x 4 x x
    x 8 x x x x x 7 x
    x x 3 x 7 4 x 5 x
    x x 1 x 2 6 x x 5
    x 3 x x x 5 x x 7
    x x 2 7 8 3 x x 1

    Can be written in a string: (I am terribly sorry about the formatting. Something feels the need to break lines at inappropriate places. I'll break manually and mark the spot with a \)

    "2,,,3,6,7,5,,,5,,,8,,,,6,,3,,,4,5,,7,,,,9,,5,3,,4,,,,8,,,,,,7,,,,3,,7,4,,5\
    ,,,,1,,2,6,,,5,,3,,,,5,,,7,,,2,7,8,3,,,1"

    This is done by simply writing one row after another, starting with the top one, and writing nothing between commas when a space is empty.
    Your task is to write a program that, when fed this sudoku, solves it. Like so, for instance:

    $ lua ./sudoku.lua "2,,,3,6,7,5,,,5,,,8,,,,6,,3\
    >,,,4,5,,7,,,,9,,5,3,,4,,,,8,,,,,,7,,,,3,,7,4,,5,,,,1\
    >,,2,6,,,5,,3,,,,5,,,7,,,2,7,8,3,,,1"
    Solved!
    2,1,9,3,6,7,5,8,4,5,7,4,8,9,2,1,6,3,3,6,8,4,5,1,7,2,9,6,9,\
    7,5,3,8,4,1,2,4,8,5,2,1,9,3,7,6,1,2,3,6,7,4,9,5,8,7,4,1,9,\
    2,6,8,3,5,8,3,6,1,4,5,2,9,7,9,5,2,7,8,3,6,4,1

    Or something like that. The solution (of course) translates into:

    2 1 9 3 6 7 5 8 4
    5 7 4 8 9 2 1 6 3
    3 6 8 4 5 1 7 2 9
    6 9 7 5 3 8 4 1 2
    4 8 5 2 1 9 3 7 6
    1 2 3 6 7 4 9 5 8
    7 4 1 9 2 6 8 3 5
    8 3 6 1 4 5 2 9 7
    9 5 2 7 8 3 6 4 1

    I'm pretty sure I stole this exercise from somewhere, but I can't seem to remember where. What do you think? Would you rather be doing euler problems? Too much? Too little?
  • WhiteZeroWhiteZero That Guy Join Date: 2004-06-24 Member: 29511Members, Constellation
    edited June 2009
    <!--quoteo(post=1711205:date=Jun 8 2009, 04:18 PM:name=JAmazon)--><div class='quotetop'>QUOTE (JAmazon @ Jun 8 2009, 04:18 PM) <a href="index.php?act=findpost&pid=1711205"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->I say we get post a weekly programming problem and see who can come up with the most elegant solution. That way we hone our LUA skills and the winner is the program with the least order of divergence.<!--QuoteEnd--></div><!--QuoteEEnd-->
    Sounds good. But can we please keep it to the Off-Topic forum and this thread NS2-centric? Thanks!
    I'm going to request a MOD move Private and JAmazon's posts to a new thread in Off-Topic just to keep my thread on track...

    <!--quoteo(post=1711166:date=Jun 8 2009, 12:58 PM:name=TinCan)--><div class='quotetop'>QUOTE (TinCan @ Jun 8 2009, 12:58 PM) <a href="index.php?act=findpost&pid=1711166"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->I plan to ... hack ...<!--QuoteEnd--></div><!--QuoteEEnd-->
    :O
    lol j/k
  • JAmazonJAmazon Join Date: 2009-02-21 Member: 66503Members
    sweet, and try to get it webbed!
  • devicenulldevicenull Join Date: 2003-04-30 Member: 15967Members, NS2 Playtester, Squad Five Blue
    <!--quoteo(post=1711231:date=Jun 8 2009, 05:22 PM:name=Private)--><div class='quotetop'>QUOTE (Private @ Jun 8 2009, 05:22 PM) <a href="index.php?act=findpost&pid=1711231"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->Sounds like a lot of fun. Also, I would like to point out that this probably belongs in the Lua section of the NS2 Creation forum.
    That being said, I would like to propose an exercise.

    You are tasked with solving any Sudoku.

    The program input will be a string representation of any sudoku, the program output is expected to be the same sudoku in a similar format, with no missing numbers.

    Allow me to elaborate; A sudoku:

    2 x x 3 6 7 5 x x
    5 x x 8 x x x 6 x
    3 x x 4 5 x 7 x x
    x 9 x 5 3 x 4 x x
    x 8 x x x x x 7 x
    x x 3 x 7 4 x 5 x
    x x 1 x 2 6 x x 5
    x 3 x x x 5 x x 7
    x x 2 7 8 3 x x 1

    Can be written in a string: (I am terribly sorry about the formatting. Something feels the need to break lines at inappropriate places. I'll break manually and mark the spot with a \)

    "2,,,3,6,7,5,,,5,,,8,,,,6,,3,,,4,5,,7,,,,9,,5,3,,4,,,,8,,,,,,7,,,,3,,7,4,,5\
    ,,,,1,,2,6,,,5,,3,,,,5,,,7,,,2,7,8,3,,,1"

    This is done by simply writing one row after another, starting with the top one, and writing nothing between commas when a space is empty.
    Your task is to write a program that, when fed this sudoku, solves it. Like so, for instance:

    $ lua ./sudoku.lua "2,,,3,6,7,5,,,5,,,8,,,,6,,3\
    >,,,4,5,,7,,,,9,,5,3,,4,,,,8,,,,,,7,,,,3,,7,4,,5,,,,1\
    >,,2,6,,,5,,3,,,,5,,,7,,,2,7,8,3,,,1"
    Solved!
    2,1,9,3,6,7,5,8,4,5,7,4,8,9,2,1,6,3,3,6,8,4,5,1,7,2,9,6,9,\
    7,5,3,8,4,1,2,4,8,5,2,1,9,3,7,6,1,2,3,6,7,4,9,5,8,7,4,1,9,\
    2,6,8,3,5,8,3,6,1,4,5,2,9,7,9,5,2,7,8,3,6,4,1

    Or something like that. The solution (of course) translates into:

    2 1 9 3 6 7 5 8 4
    5 7 4 8 9 2 1 6 3
    3 6 8 4 5 1 7 2 9
    6 9 7 5 3 8 4 1 2
    4 8 5 2 1 9 3 7 6
    1 2 3 6 7 4 9 5 8
    7 4 1 9 2 6 8 3 5
    8 3 6 1 4 5 2 9 7
    9 5 2 7 8 3 6 4 1

    I'm pretty sure I stole this exercise from somewhere, but I can't seem to remember where. What do you think? Would you rather be doing euler problems? Too much? Too little?<!--QuoteEnd--></div><!--QuoteEEnd-->

    Isn't sudoku NP-Complete? I seem to remember hearing somewhere that it is. While this doesn't seem terribly hard to code, it could take a very long time to run <img src="style_emoticons/<#EMO_DIR#>/biggrin-fix.gif" style="vertical-align:middle" emoid=":D" border="0" alt="biggrin-fix.gif" />

    Also, feel free to use the LUA section of the site in my signature if you want to post these somewhere <img src="style_emoticons/<#EMO_DIR#>/smile-fix.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile-fix.gif" />
  • JAmazonJAmazon Join Date: 2009-02-21 Member: 66503Members
    Thats why its a good problem. because its not that hard to do, but were trying to go for elegance and run-time. So whoever can make the program that solves it in the least number of computations wins. I actually did this problem before for a math modelling competition, but we were more interested in modeling how a human player would solve a sudoku, so our program had pretty bad run-time. Still solved 20,000 sudokus in 5 min <img src="style_emoticons/<#EMO_DIR#>/biggrin-fix.gif" style="vertical-align:middle" emoid=":D" border="0" alt="biggrin-fix.gif" />
  • NeoSniperNeoSniper Join Date: 2005-06-02 Member: 52976Members
    To OP,

    Actually I've been into mods for a long time. Often spending more time with mods that the actual game that the mod was made for. Most obvious example being NS but also Desert Combat and Red Orchestra are big example of that. So for a while now with all the LUA talk going on in the NS2 blog I've been becoming more and more interested in looking into it.

    Actually the off-topic discussion (as you refer to it) in this thread has gotten me a bit more excited about learning LUA for NS2 and I'll definetly keep an eye out for more "Learning LUA" threads.

    Good topic idea.
  • RobBRobB TUBES OF THE INTERWEB Join Date: 2003-08-11 Member: 19423Members, Constellation, Reinforced - Shadow
    I'd like to get into Mapping, sincce I have some pretty Interesting concepts haunting my Head.

    As for LUA... Try <a href="http://www.zachtronicsindustries.com/pivot/entry.php?id=18" target="_blank">this Game</a>. It may help to Understand the Language.
  • flying_mooseflying_moose Join Date: 2009-06-03 Member: 67676Members, Constellation
    I've been picking up LUA seince the first announced they were using it in NS2 and there are more then a few oddities in LUA that I've never seen in any other language.
    examples:
    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->a,b = b,a<!--c2--></div><!--ec2-->Yup, that works for swapping values

    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->local oldprint = print           -- Store current print function as oldprint
      function print(s)                -- Redefine print function
        if s == "foo" then
          oldprint("bar")
        else
          oldprint(s)
        end
      end<!--c2--></div><!--ec2-->Yup, thats right. dont like how LUA's core functions work? You can re-write them yourself.

    And finally
    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->function makeaddfunc(x)
      -- Return a new function that adds x to the argument
      return function(y)
        return x + y
      end
    end
    plustwo = makeaddfunc(2)
    print(plustwo(5)) -- Prints 7<!--c2--></div><!--ec2-->This ones just strange.

    The more I learn about lua: the more I'm convinced that LUA was used to program skynet. <img src="style_emoticons/<#EMO_DIR#>/tounge.gif" style="vertical-align:middle" emoid=":p" border="0" alt="tounge.gif" />
  • ItalianmagicItalianmagic Join Date: 2008-12-13 Member: 65755Members
    xD! Skynet. i'm looking at the examples you posted. I definately agree. <img src="style_emoticons/<#EMO_DIR#>/biggrin-fix.gif" style="vertical-align:middle" emoid=":D" border="0" alt="biggrin-fix.gif" />
  • devicenulldevicenull Join Date: 2003-04-30 Member: 15967Members, NS2 Playtester, Squad Five Blue
    <!--quoteo(post=1711524:date=Jun 9 2009, 08:07 PM:name=flying_moose)--><div class='quotetop'>QUOTE (flying_moose @ Jun 9 2009, 08:07 PM) <a href="index.php?act=findpost&pid=1711524"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->I've been picking up LUA seince the first announced they were using it in NS2 and there are more then a few oddities in LUA that I've never seen in any other language.
    examples:
    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->a,b = b,a<!--c2--></div><!--ec2-->Yup, that works for swapping values

    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->local oldprint = print           -- Store current print function as oldprint
      function print(s)                -- Redefine print function
        if s == "foo" then
          oldprint("bar")
        else
          oldprint(s)
        end
      end<!--c2--></div><!--ec2-->Yup, thats right. dont like how LUA's core functions work? You can re-write them yourself.

    And finally
    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->function makeaddfunc(x)
      -- Return a new function that adds x to the argument
      return function(y)
        return x + y
      end
    end
    plustwo = makeaddfunc(2)
    print(plustwo(5)) -- Prints 7<!--c2--></div><!--ec2-->This ones just strange.

    The more I learn about lua: the more I'm convinced that LUA was used to program skynet. <img src="style_emoticons/<#EMO_DIR#>/tounge.gif" style="vertical-align:middle" emoid=":p" border="0" alt="tounge.gif" /><!--QuoteEnd--></div><!--QuoteEEnd-->

    Those aren't terribly odd as far as the more popular language now go.. I can only speak for python, but at least the first and third will work in it. The second may, I've never needed to do anything like it. I decided to learn LUA I would start writing the basics of an admin plugin... That keeps me interested moreso then doing things like the project euler challenges. Anyone have comments/suggestions on it? Code is available <a href="http://modns2.net/index.php?topic=3.msg5#new" target="_blank">here</a>.
Sign In or Register to comment.