Show Posts
|
|
Pages: [1] 2 3 ... 8
|
|
1
|
Calculator Community / TI-Nspire Projects / Re: Scramble/Boggle Lua
|
on: 13 August, 2012, 06:20:03
|
Errors happen much less frequently now that letterkeys is defined. There are still a couple errors. If I press, release, and then hold tab while I push a letter key, I get an error on line 228. dx is a nil value. If I rapidly jam the tab button (or get unlucky every once in a while), there's an error on line 212. word is an empty string. This causes an arithmetic error because string.byte is returning nothing. Holding tab doesn't work as well on the student software as on the handheld. This isn't a big concern. This game is really coming along. Good work so far! 
|
|
|
|
|
2
|
Calculator Community / TI-Nspire Projects / Re: Scramble/Boggle Lua
|
on: 07 August, 2012, 03:15:52
|
I tried it out, but it kept giving errors around line 212. This is what the console says 212: attempt to index global 'letterkeys' (a nil value) and 212: attempt to perform arithmetic on a nil value It seems that letterkeys isn't defined anymore.
|
|
|
|
|
4
|
Calculator Community / TI-Nspire Projects / Re: Scramble/Boggle Lua
|
on: 28 July, 2012, 05:22:28
|
When I load the script with the pre-generated table, Lua is using ~20 MB of the 64 MB of operating memory. TI probably set the max level lower than full capacity. So, maybe the table by itself is just small enough to fit in under their max but when the rest of the program is running, Lua uses even more memory and that signals to Lua to throw an error. I can attach the program I used to generate the table and you can experiment with shorter tables. I was looking at the 12dicts wordlists. Here's a download link: http://downloads.sourceforge.net/wordlist/alt12dicts-4.zip. They come with some symbols to catagorize some of them, but I just deleted them all. I just used the replace feature in Notepad++ and turned on regular expressions. I had it find [^a-z] and replace it with nothing. I also had it replace \r\n with "," and added the brackets to make it a table. Then, I assigned the result to the variable "list" in the attached program and ran it using Lua (on the computer). It will write to (or overwrite) a file called pregendict.txt (in the current directory) with the code for the pre-generated table.
|
|
|
|
|
6
|
Calculator Community / TI-Nspire Projects / Re: Scramble/Boggle Lua
|
on: 25 July, 2012, 04:35:36
|
|
Figures. The student software must allow for more memory to be used. One thing that could be done is generate the table before hand. It would be faster and there wouldn't be two lists of words. 100,000 words is a bit excessive, so a dictionary with less words would also work. I tried actually sending this to my nspire cx, so as long as the rest of the program isn't massive, this should work. There are 81536 words. I'll attach the file of the pre-generated table.
Edits:
It takes a little more than 20 seconds for my calculator to open the document with the script. Indexing the table, however, takes less than a millisecond.
Also, don't forget to assign this table to a variable.
I wouldn't say "shrunken." This dictionary is probably larger than an array with the words. It just indexes a lot faster than an array since most of the guess and check is avoided.
|
|
|
|
|
8
|
Calculator Community / TI-Nspire Projects / Re: Scramble/Boggle Lua
|
on: 24 July, 2012, 18:56:52
|
Notepad++ took more like a whole second to paste everything (over 1,000,000 characters after all).  Notepad++ is kind of the exception. It's a very lightweight program  . Bulky IDEs like the script editor in the student software tend to crash (or come very close) when I paste in the code, though. I don't even think the syntax highlighting can be turned off in the student software to avoid this issue.  That's why I had to use the old scripting tools and Notepad++. I clarified this in my previous post.
|
|
|
|
|
10
|
Calculator Community / TI-Nspire Projects / Re: Scramble/Boggle Lua
|
on: 24 July, 2012, 04:57:29
|
|
I tested this way on the student software and it took about 3 seconds to load my list of ~100,000 words and convert it to the table. From there it was able to index any word very quickly (including long words like symptomatologically). The overall memory is a tad bulky (but there's only so much you can shrink 100,000 words). Each key, however, only points to a table containing, at most, 27 new keys.
A warning: don't paste tables like this into programs bulky IDEs with syntax highlighting. I pasted a table into the student software, walked away for an hour, came back and it was still trying to highlight everything. I eventually gave up and used the old scripting tools to test out the method.
I'll attach the code I tried with.
EDIT: I just realized that there are two lists in this program. There is still a table with all 100,000 words in it. I haven't sent this code to my calculator, so I'm not 100% sure that there won't be any memory issues.
EDIT2: I just realized, if one wanted definitions included with this structure, the values of the endofs (or _s) would just need to be changed from true to the definition. This wouldn't really apply to Boggle, but it could be used elsewhere.
EDIT3: loadstring is intended to be more for accepting code from the user. oclua is a good example of this. Tables and strings should be able to handle this problem without loadstring.
|
|
|
|
|
11
|
Calculator Community / TI-Nspire Projects / Re: Scramble/Boggle Lua
|
on: 24 July, 2012, 02:02:43
|
If the plan is to have large dictionaries, this might be useful.  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| function editDictionary(dictionary, old_dict) local data = old_dict or {} for _, word in ipairs(dictionary) do local curchar = data for i = 1, #word do local char = word:sub(i, i) if not curchar[char] then curchar[char] = {endof = i == #word and true or nil} elseif not curchar[char].endof then curchar[char].endof = i == #word and true or nil end curchar = curchar[char] end end data.lookup = function(tbl, str) local function lookup(str) local curchar = data for i = 1, #str do curchar = curchar[str:sub(i, i)] end return curchar.endof end err, ret = pcall(lookup, str) return err and ret or nil end return data end
|
It takes a table like 1 2
| list={"carbon","cars","car","cat","cats"}
|
and creates a table like 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| dictionary = { c={ a={ r={ b={ o={ n={endof = true} } } s={endof = true} endof = true } t = { s={endof = true} endof = true } } } lookup = function(tbl, str) --blah blah blah end }
|
lookup takes a string and rapidly returns a true or nil value based on if the word is in the list of acceptable words. Here's an example: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| dict = {"cat", "cats", "dog", "mouse"}
dictionary = editDictionary(dict)
print("d:", dictionary:lookup("d")) print("do:", dictionary:lookup("do")) print("dog:", dictionary:lookup("dog")) print("dogs:", dictionary:lookup("dogs")) print("dogz:", dictionary:lookup("dogz"))
amendment = {"dogs"} dictionary = editDictionary(amendment, dictionary) print("\nAmendment: dogs added!\n")
print("d:", dictionary:lookup("d")) print("do:", dictionary:lookup("do")) print("dog:", dictionary:lookup("dog")) print("dogs:", dictionary:lookup("dogs")) print("dogz:", dictionary:lookup("dogz"))
|
prints 1 2 3 4 5 6 7 8 9 10 11 12 13 14
| d: nil do: nil dog: true dogs: nil dogz: nil
Amendment: dogs added!
d: nil do: nil dog: true dogs: true dogz: nil
|
What I like about this way is that it narrows the search down for each letter in the string instead of searching for the whole string in a giant table or string. It could be potentially bulky, though. Worst case scenario, it could end up indexing something like dictionary.p.n.e.u.m.o.n.o.u.l.t.r.a.m.i.c.r.o.s.c.o.p.i.c.s.i.l.i.c.o.v.o.l.c.a.n.o.c.o.n.i.o.s.i. s.endof but most of that searching would be handled by Lua itself. This is case sensitive, but if it makes a difference it would only take a simple metatable to fix. EDIT: Reread the first post and testing a few things first
|
|
|
|
|
13
|
General Discussion / Introduce Yourself! / Re: New user
|
on: 17 July, 2012, 21:37:27
|
Welcome! What brings you to Omnimaga? It seems like you have quite a bit of experience in assembly already. There's also a language called Axe that's pretty popular around here. Do you have any projects in mind? Also, here's some more peanuts  : 
|
|
|
|
|
14
|
Calculator Community / TI-Nspire Projects / Re: Matrix Library
|
on: 16 July, 2012, 21:03:53
|
|
I think I'm okay for now. I'm sort of taking a crash course in linear algebra before I finish up the next version. I do have a lot of new things added, so I'll post what I have so far and update the first post.
|
|
|
|
|
|