How do I compare two table's values? I need to compare two tables to see if a pattern emerges. Like this:
{1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 6} It would need to see {1, 2, 3, 4} occurred x number of times, and 5 came after that pattern the most. So it would predict 5 comes after that this time. How do I compare {1, 2, 3, 4} to the longer table though, to get that pattern?
In case you are wondering what for, it's to make an AI. Cranium, if you are reading this: Challenge Accepted.
.....Just as soon as I can do this...
[SOLVED]How do I compare two table's values?
Started by Lettuce, Sep 13 2012 10:57 PM
3 replies to this topic
#1
Posted 13 September 2012 - 10:57 PM
#2
Posted 13 September 2012 - 11:03 PM
I had this same problem with table comparisons creating my Slots program. Two tables, named differently, but with the same values, are always going to be different, since they are located in two DIFFERENT memory references. You would have to create a for loop to compare the value of cell 1 in table 1 to cell 1 in table 2, and so on. It's a little bit of a pain, and requires more work, but it can be done.
EDIT: I think if you are trying to get a PATTERN, out of a table, you can use this:
EDIT: I think if you are trying to get a PATTERN, out of a table, you can use this:
tab1 = {1,2,3,4,5,1,2,3,4,5,1,2,3,4,6}
tab2 = {1,2,3,4}
pattern = table.concat(tab1)
Using table.concat concatenates the values together from whatever table you are calling, and from there, you can use some sort of string matching i assume.
#3
Posted 13 September 2012 - 11:07 PM
Excellent. I don't need to compare them directly, I just need to find that pattern. Keep your thread open for a little while, I'll post it there first, then to the programs section if I can get it done. I'm working with two more programs though, so it'll be some juggling, but probably next week.
Thank you,
--Lettuce
Thank you,
--Lettuce
#4
Posted 13 September 2012 - 11:10 PM
I have no intention of closing that thread. I hope to have more people accepting my challenge.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











