This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Lettuce's profile picture

[SOLVED]How do I compare two table's values?

Started by Lettuce, 13 September 2012 - 09:57 PM
Lettuce #1
Posted 13 September 2012 - 11:57 PM
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…
Cranium #2
Posted 14 September 2012 - 12:03 AM
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:

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.
Lettuce #3
Posted 14 September 2012 - 12:07 AM
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
Cranium #4
Posted 14 September 2012 - 12:10 AM
I have no intention of closing that thread. I hope to have more people accepting my challenge.