Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ MUSHclient ➜ Lua ➜ Safe Cracker

Safe Cracker

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Biran   (8 posts)  Bio
Date Sat 21 Jan 2023 05:15 AM (UTC)
Message
This could be a long shot but iv been Scouring the forum and iv found nothing similar to what I'm attempting...The mud I'm playing with has a crafting system... there are a total of 30 items to use when attempting to craft.

Example: MINE CRAFT Moonstone Sunstone = Bloodstone Necklace.
If my math holds out 30 items = 1,073,741,823 Possible combinations...maybe you see my problem already. I spent a total of 11 hours Randomly typing in Recipes to no avail so it might be worth making a script to handle this but I'm not 100% sure if this is even possible...only 1,073,741,507 Attempts to go :'(

I'm looking to add 30 items to a table...This script would attempt to "MINE CRAFT AMBER JADE" If it returns "That's not a valid crafting recipe" it will add AMBER JADE to a table let's call it FALSE.table(This table would hold Recipes that don't work so it won't repeat them). else if it returns "You successfully craft "^$" it will add MINE CRAFT Diamond GOLD to True.table for Successful Recipes. Any Advice or direction would be great.
Top

Posted by Nick Gammon   Australia  (23,121 posts)  Bio   Forum Administrator
Date Reply #1 on Sat 21 Jan 2023 06:46 AM (UTC)
Message
How many reagents for each recipe? If there are only two, then you only have 900 combinations (30 x 30) not 1,073,741,823.

It's a little hard to believe that the MUD designers expect each player to try 1,073,741,823 lots of recipes. That would, if nothing else, tie up a lot of server time.

How did you arrive at 1073741823? 30 isn't even a factor of it.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,121 posts)  Bio   Forum Administrator
Date Reply #2 on Sat 21 Jan 2023 06:49 AM (UTC)
Message
If my maths holds up, then if you do indeed need to try 1,073,741,823 recipe combinations, and if you are able to do one a second, it would take 34 years to find all the recipes. Surely the MUD will have shut down by then?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Biran   (8 posts)  Bio
Date Reply #3 on Sat 21 Jan 2023 05:07 PM (UTC)
Message
All the items are listed below..I Should also mention the help file says that they must be in alphabetical order to work...so Moonstone is before Sunstone to craft..so which could narrow down the recipes significantly..I talked to the owner and he said the largest crafting recipe is 8 items and none of the recipes require only 1 item.

Mine Craft (item)(item)(item)(item)ect ect ect



(Glowing) (Humming) a bloodstone necklace
a sunstone
a serpentine gemstone
an onyx gemstone
a moonstone gemstone
a ruby gemstone
a jade gemstone
an amber gem
a turquoise gem
an amethyst gemstone
a diamond
a rose quartz
a cubic zirconia
a garnet stone
a pearl
some slime
a gold nugget
a sliver of silver
a rock
some dust
iron nugget
a crystal
A rock made of obsidian
Some volcanic ash
Some platinum shards
an agate stone
an opal
a topaz gem
a blue sapphire gem
an emerald gemstone
some dirt
Top

Posted by Nick Gammon   Australia  (23,121 posts)  Bio   Forum Administrator
Date Reply #4 on Sat 21 Jan 2023 08:42 PM (UTC)
Message
OK, given those limitations, I see that the calculations would be:


2 items: 29
3 items: 29 * 28 = 812
4 items: 812 * 27 = 21924
5 items: 21924 * 26

and so on ...


So the first item in your list (once you sort it alphabetically) can combine with 29 other items, so that is 29 things to try. And if it has 3 reagents, then for each of those 29 you can combine with a further 28 giving 812 possibilities. For each of those 812 you can combine with another 27, and so on.

I wrote some Lua code to test out how many there would be:


-- work out crafting recipe

MIN_REAGENTS = 1
MAX_REAGENTS = 8

REAGENT_COUNT = 30

local count = 0

for reagent = 1, REAGENT_COUNT - 1 do
  print ()
  print ("Starting with reagent", reagent)
  print ()

  local previous = 1
  for reagents = MIN_REAGENTS, MAX_REAGENTS - 1 do
    local thisCount = previous * (REAGENT_COUNT - reagents - reagent + 1)
    print (string.format ("%i items, combinations = %i", reagents + 1, thisCount))
    previous = thisCount
    count = count + thisCount
  end -- for

end -- for each starting reagent

print ()
print ("Total combinations =", count)


Results:



Starting with reagent	1

2 items, combinations = 29
3 items, combinations = 812
4 items, combinations = 21924
5 items, combinations = 570024
6 items, combinations = 14250600
7 items, combinations = 342014400
8 items, combinations = 7866331200

Starting with reagent	2

2 items, combinations = 28
3 items, combinations = 756
4 items, combinations = 19656
5 items, combinations = 491400
6 items, combinations = 11793600
7 items, combinations = 271252800
8 items, combinations = 5967561600

Starting with reagent	3

2 items, combinations = 27
3 items, combinations = 702
4 items, combinations = 17550
5 items, combinations = 421200
6 items, combinations = 9687600
7 items, combinations = 213127200
8 items, combinations = 4475671200

Starting with reagent	4

2 items, combinations = 26
3 items, combinations = 650
4 items, combinations = 15600
5 items, combinations = 358800
6 items, combinations = 7893600
7 items, combinations = 165765600
8 items, combinations = 3315312000

Starting with reagent	5

2 items, combinations = 25
3 items, combinations = 600
4 items, combinations = 13800
5 items, combinations = 303600
6 items, combinations = 6375600
7 items, combinations = 127512000
8 items, combinations = 2422728000

Starting with reagent	6

2 items, combinations = 24
3 items, combinations = 552
4 items, combinations = 12144
5 items, combinations = 255024
6 items, combinations = 5100480
7 items, combinations = 96909120
8 items, combinations = 1744364160

Starting with reagent	7

2 items, combinations = 23
3 items, combinations = 506
4 items, combinations = 10626
5 items, combinations = 212520
6 items, combinations = 4037880
7 items, combinations = 72681840
8 items, combinations = 1235591280

Starting with reagent	8

2 items, combinations = 22
3 items, combinations = 462
4 items, combinations = 9240
5 items, combinations = 175560
6 items, combinations = 3160080
7 items, combinations = 53721360
8 items, combinations = 859541760

Starting with reagent	9

2 items, combinations = 21
3 items, combinations = 420
4 items, combinations = 7980
5 items, combinations = 143640
6 items, combinations = 2441880
7 items, combinations = 39070080
8 items, combinations = 586051200

Starting with reagent	10

2 items, combinations = 20
3 items, combinations = 380
4 items, combinations = 6840
5 items, combinations = 116280
6 items, combinations = 1860480
7 items, combinations = 27907200
8 items, combinations = 390700800

Starting with reagent	11

2 items, combinations = 19
3 items, combinations = 342
4 items, combinations = 5814
5 items, combinations = 93024
6 items, combinations = 1395360
7 items, combinations = 19535040
8 items, combinations = 253955520

Starting with reagent	12

2 items, combinations = 18
3 items, combinations = 306
4 items, combinations = 4896
5 items, combinations = 73440
6 items, combinations = 1028160
7 items, combinations = 13366080
8 items, combinations = 160392960

Starting with reagent	13

2 items, combinations = 17
3 items, combinations = 272
4 items, combinations = 4080
5 items, combinations = 57120
6 items, combinations = 742560
7 items, combinations = 8910720
8 items, combinations = 98017920

Starting with reagent	14

2 items, combinations = 16
3 items, combinations = 240
4 items, combinations = 3360
5 items, combinations = 43680
6 items, combinations = 524160
7 items, combinations = 5765760
8 items, combinations = 57657600

Starting with reagent	15

2 items, combinations = 15
3 items, combinations = 210
4 items, combinations = 2730
5 items, combinations = 32760
6 items, combinations = 360360
7 items, combinations = 3603600
8 items, combinations = 32432400

Starting with reagent	16

2 items, combinations = 14
3 items, combinations = 182
4 items, combinations = 2184
5 items, combinations = 24024
6 items, combinations = 240240
7 items, combinations = 2162160
8 items, combinations = 17297280

Starting with reagent	17

2 items, combinations = 13
3 items, combinations = 156
4 items, combinations = 1716
5 items, combinations = 17160
6 items, combinations = 154440
7 items, combinations = 1235520
8 items, combinations = 8648640

Starting with reagent	18

2 items, combinations = 12
3 items, combinations = 132
4 items, combinations = 1320
5 items, combinations = 11880
6 items, combinations = 95040
7 items, combinations = 665280
8 items, combinations = 3991680

Starting with reagent	19

2 items, combinations = 11
3 items, combinations = 110
4 items, combinations = 990
5 items, combinations = 7920
6 items, combinations = 55440
7 items, combinations = 332640
8 items, combinations = 1663200

Starting with reagent	20

2 items, combinations = 10
3 items, combinations = 90
4 items, combinations = 720
5 items, combinations = 5040
6 items, combinations = 30240
7 items, combinations = 151200
8 items, combinations = 604800

Starting with reagent	21

2 items, combinations = 9
3 items, combinations = 72
4 items, combinations = 504
5 items, combinations = 3024
6 items, combinations = 15120
7 items, combinations = 60480
8 items, combinations = 181440

Starting with reagent	22

2 items, combinations = 8
3 items, combinations = 56
4 items, combinations = 336
5 items, combinations = 1680
6 items, combinations = 6720
7 items, combinations = 20160
8 items, combinations = 40320

Starting with reagent	23

2 items, combinations = 7
3 items, combinations = 42
4 items, combinations = 210
5 items, combinations = 840
6 items, combinations = 2520
7 items, combinations = 5040
8 items, combinations = 5040

Starting with reagent	24

2 items, combinations = 6
3 items, combinations = 30
4 items, combinations = 120
5 items, combinations = 360
6 items, combinations = 720
7 items, combinations = 720
8 items, combinations = 0

Starting with reagent	25

2 items, combinations = 5
3 items, combinations = 20
4 items, combinations = 60
5 items, combinations = 120
6 items, combinations = 120
7 items, combinations = 0
8 items, combinations = 0

Starting with reagent	26

2 items, combinations = 4
3 items, combinations = 12
4 items, combinations = 24
5 items, combinations = 24
6 items, combinations = 0
7 items, combinations = 0
8 items, combinations = 0

Starting with reagent	27

2 items, combinations = 3
3 items, combinations = 6
4 items, combinations = 6
5 items, combinations = 0
6 items, combinations = 0
7 items, combinations = 0
8 items, combinations = 0

Starting with reagent	28

2 items, combinations = 2
3 items, combinations = 2
4 items, combinations = 0
5 items, combinations = 0
6 items, combinations = 0
7 items, combinations = 0
8 items, combinations = 0

Starting with reagent	29

2 items, combinations = 1
3 items, combinations = 0
4 items, combinations = 0
5 items, combinations = 0
6 items, combinations = 0
7 items, combinations = 0
8 items, combinations = 0

Total combinations =	31039364129


So that is 31,039,364,129 combinations, assuming I got that right. I still think it will take too long. You might want to ask the boss-person of the MUD if they really want you to hit their MUD with 31,039,364,129 attempts to work out their crafting system, or maybe to save everyone a lot of effort, make a post telling you what the recipes are. :)

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,121 posts)  Bio   Forum Administrator
Date Reply #5 on Thu 02 Feb 2023 09:43 PM (UTC)
Message
Just for fun, I submitted your request as I understood it to ChatGPT to see what it would do. Here is my first request:

Quote:

write lua code to generate crafting combinations. There are a total of 30 materials which can be combined, with a minimum of two and a maximum of six. Each material can only be combined with one alphabetically higher.


I got this result:

Quote:


Here's a sample code in Lua to generate all possible combinations of crafting materials that can be combined, given the constraints you specified:


-- Define the total number of materials
local total_materials = 30

-- Define the minimum and maximum number of materials to combine
local min_materials = 2
local max_materials = 6

-- Function to generate combinations
local function generate_combinations(selected, remaining, result)
  -- If the number of selected materials is equal to the maximum, add it to the result table
  if #selected == max_materials then
    table.insert(result, selected)
    return
  end

  -- If the number of remaining materials is less than the minimum, return
  if #remaining < min_materials - #selected then
    return
  end

  -- Loop through the remaining materials
  for i, material in ipairs(remaining) do
    -- If the current material is greater than the previous one, select it
    if #selected == 0 or material > selected[#selected] then
      local new_selected = {unpack(selected)}
      table.insert(new_selected, material)
      local new_remaining = {unpack(remaining)}
      table.remove(new_remaining, i)
      generate_combinations(new_selected, new_remaining, result)
    end
  end
end

-- Initialize the materials list
local materials = {}
for i = 1, total_materials do
  materials[i] = i
end

-- Initialize the result table
local result = {}

-- Call the function to generate combinations
generate_combinations({}, materials, result)

-- Print the result table
for i, combination in ipairs(result) do
  print(unpack(combination))
end


This code defines a function generate_combinations that takes in 3 arguments:


  • selected: a table that holds the currently selected materials
  • remaining: a table that holds the remaining materials
  • result: a table that holds all the combinations of materials


The function generates all possible combinations by using a recursive approach. It selects a material, adds it to the selected table, and removes it from the remaining table. The process repeats until either the selected table has reached the maximum number of materials or the remaining table has no more materials to select. The final result is stored in the result table, which is printed at the end.



The first few lines of the results were:


1       2       3       4       5       6
1       2       3       4       5       7
1       2       3       4       5       8
1       2       3       4       5       9
1       2       3       4       5       10
1       2       3       4       5       11
1       2       3       4       5       12
1       2       3       4       5       13
1       2       3       4       5       14
1       2       3       4       5       15
1       2       3       4       5       16
1       2       3       4       5       17
1       2       3       4       5       18
1       2       3       4       5       19
1       2       3       4       5       20
1       2       3       4       5       21
1       2       3       4       5       22
1       2       3       4       5       23
1       2       3       4       5       24
1       2       3       4       5       25
1       2       3       4       5       26
1       2       3       4       5       27
1       2       3       4       5       28
1       2       3       4       5       29
1       2       3       4       5       30
1       2       3       4       6       7
1       2       3       4       6       8
1       2       3       4       6       9
1       2       3       4       6       10
1       2       3       4       6       11
1       2       3       4       6       12
1       2       3       4       6       13
1       2       3       4       6       14
1       2       3       4       6       15
1       2       3       4       6       16
1       2       3       4       6       17
1       2       3       4       6       18
1       2       3       4       6       19
1       2       3       4       6       20
1       2       3       4       6       21
1       2       3       4       6       22
1       2       3       4       6       23
1       2       3       4       6       24
1       2       3       4       6       25
1       2       3       4       6       26
1       2       3       4       6       27
1       2       3       4       6       28
1       2       3       4       6       29
1       2       3       4       6       30


Let's assume that each number represents an entry in your materials table, which we assume is sorted into alphabetic order. By doing a simple lookup we could convert those number back into actual materials.

However I note that the generated code always generated six items, whereas I understand that you might use only two.

(Note, I told ChatGPT six rather than eight, but that is a constant in the code you could easily change.)

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,121 posts)  Bio   Forum Administrator
Date Reply #6 on Thu 02 Feb 2023 09:47 PM (UTC)
Message
I then modified my request to tell it that it did not need to necessarily output six reagents, as follows:

Quote:

write lua code to generate crafting combinations. There are a total of 30 materials which can be combined, with a minimum of two and a maximum of six. Each material can only be combined with one alphabetically higher. The result does not have to contain all six materials.



This gave the results:

Quote:


Here's a sample code in Lua to generate all possible combinations of crafting materials that can be combined, given the constraints you specified:


-- Define the total number of materials
local total_materials = 30

-- Define the minimum and maximum number of materials to combine
local min_materials = 2
local max_materials = 6

-- Function to generate combinations
local function generate_combinations(selected, remaining, result)
  -- If the number of selected materials is equal to or greater than the minimum, add it to the result table
  if #selected >= min_materials then
    table.insert(result, selected)
  end

  -- If the number of selected materials is greater than or equal to the maximum, return
  if #selected >= max_materials then
    return
  end

  -- Loop through the remaining materials
  for i, material in ipairs(remaining) do
    -- If the current material is greater than the previous one, select it
    if #selected == 0 or material > selected[#selected] then
      local new_selected = {unpack(selected)}
      table.insert(new_selected, material)
      local new_remaining = {unpack(remaining)}
      table.remove(new_remaining, i)
      generate_combinations(new_selected, new_remaining, result)
    end
  end
end

-- Initialize the materials list
local materials = {}
for i = 1, total_materials do
  materials[i] = i
end

-- Initialize the result table
local result = {}

-- Call the function to generate combinations
generate_combinations({}, materials, result)

-- Print the result table
for i, combination in ipairs(result) do
  print(unpack(combination))
end


This code is similar to the previous one, with a slight modification. In the generate_combinations function, the code adds the selected materials to the result table if the number of selected materials is equal to or greater than the minimum, instead of only if it's equal to the maximum. This allows combinations of less than the maximum number of materials to be added to the result table.



Interestingly, ChatGPT noticed that I had restated the question with different restraints. This time the results when run were:


1       2
1       2       3
1       2       3       4
1       2       3       4       5
1       2       3       4       5       6
1       2       3       4       5       7
1       2       3       4       5       8
1       2       3       4       5       9
1       2       3       4       5       10
1       2       3       4       5       11
1       2       3       4       5       12
1       2       3       4       5       13
1       2       3       4       5       14
1       2       3       4       5       15
1       2       3       4       5       16
1       2       3       4       5       17
1       2       3       4       5       18
1       2       3       4       5       19
1       2       3       4       5       20
1       2       3       4       5       21
1       2       3       4       5       22
1       2       3       4       5       23
1       2       3       4       5       24
1       2       3       4       5       25
1       2       3       4       5       26
1       2       3       4       5       27
1       2       3       4       5       28
1       2       3       4       5       29
1       2       3       4       5       30
1       2       3       4       6
1       2       3       4       6       7
1       2       3       4       6       8
1       2       3       4       6       9
1       2       3       4       6       10
1       2       3       4       6       11
1       2       3       4       6       12
1       2       3       4       6       13
1       2       3       4       6       14
1       2       3       4       6       15
1       2       3       4       6       16
1       2       3       4       6       17
1       2       3       4       6       18
1       2       3       4       6       19
1       2       3       4       6       20
1       2       3       4       6       21
1       2       3       4       6       22
1       2       3       4       6       23
1       2       3       4       6       24
1       2       3       4       6       25
1       2       3       4       6       26
1       2       3       4       6       27
1       2       3       4       6       28
1       2       3       4       6       29
1       2       3       4       6       30


This seems better, as it allowed for less than six materials for each attempt.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,121 posts)  Bio   Forum Administrator
Date Reply #7 on Thu 02 Feb 2023 09:51 PM (UTC)

Amended on Thu 02 Feb 2023 09:53 PM (UTC) by Nick Gammon

Message
To use the actual material names, simply change the part:



-- Initialize the materials list
local materials = {}
for i = 1, total_materials do
  materials[i] = i
end


to be:


-- Initialize the materials list
local materials = {
  "a bloodstone necklace",
  "a sunstone",
  "a serpentine gemstone",
  "an onyx gemstone",
  "a moonstone gemstone",
  "a ruby gemstone",
  "a jade gemstone",
  "an amber gem",
  "a turquoise gem",
  "an amethyst gemstone",
  "a diamond",
  "a rose quartz",
  "a cubic zirconia",
  "a garnet stone",
  "a pearl",
  "some slime",
  "a gold nugget",
  "a sliver of silver",
  "a rock",
  "some dust",
  "iron nugget",
  "a crystal",
  "A rock made of obsidian",
  "Some volcanic ash",
  "Some platinum shards",
  "an agate stone",
  "an opal",
  "a topaz gem",
  "a blue sapphire gem",
  "an emerald gemstone",
  "some dirt",
}

table.sort (materials)


Now the results look like this:


A rock made of obsidian Some platinum shards
A rock made of obsidian Some platinum shards    Some volcanic ash
A rock made of obsidian Some platinum shards    Some volcanic ash       a bloodstone necklace
A rock made of obsidian Some platinum shards    Some volcanic ash       a bloodstone necklace   a blue sapphire gem
A rock made of obsidian Some platinum shards    Some volcanic ash       a bloodstone necklace   a blue sapphire gem     a crystal
A rock made of obsidian Some platinum shards    Some volcanic ash       a bloodstone necklace   a blue sapphire gem     a cubic zirconia
A rock made of obsidian Some platinum shards    Some volcanic ash       a bloodstone necklace   a blue sapphire gem     a diamond
A rock made of obsidian Some platinum shards    Some volcanic ash       a bloodstone necklace   a blue sapphire gem     a garnet stone
A rock made of obsidian Some platinum shards    Some volcanic ash       a bloodstone necklace   a blue sapphire gem     a gold nugget
A rock made of obsidian Some platinum shards    Some volcanic ash       a bloodstone necklace   a blue sapphire gem     a jade gemstone
A rock made of obsidian Some platinum shards    Some volcanic ash       a bloodstone necklace   a blue sapphire gem     a moonstone gemstone

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,121 posts)  Bio   Forum Administrator
Date Reply #8 on Thu 02 Feb 2023 09:55 PM (UTC)
Message
Biran said:

This could be a long shot but iv been Scouring the forum and iv found nothing similar to what I'm attempting...The mud I'm playing with has a crafting system... there are a total of 30 items to use when attempting to craft.


You listed 31 items, by the way.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,121 posts)  Bio   Forum Administrator
Date Reply #9 on Thu 02 Feb 2023 09:57 PM (UTC)

Amended on Thu 02 Feb 2023 10:02 PM (UTC) by Nick Gammon

Message
Running the above code (second version) gave 942,617 lines of results, so it looks like I was wrong about the total number of combinations.

However it only returned 768,181 lines when I pared the table back to 30 items rather than 31.

And when I changed it to a maximum of 8 reagents it generated 8,656,906 combinations (and took somewhat longer to run - about 36 seconds).

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Biran   (8 posts)  Bio
Date Reply #10 on Sun 26 Feb 2023 03:06 AM (UTC)
Message
Nick Gammon said:

Running the above code (second version) gave 942,617 lines of results, so it looks like I was wrong about the total number of combinations.

However, it only returned 768,181 lines when I pared the table back to 30 items rather than 31.

And when I changed it to a maximum of 8 reagents it generated 8,656,906 combinations (and took somewhat longer to run - about 36 seconds).



I just wanted to thank you for all your help! I didn't forget about it! XD with ChatGPT your help and ALOT of tweaking I was able to unlock 8 Recipes on this mud...while that's not all of them it was a huge start. I took what you posted and added a few basic triggers and also manually adjusted the trigger so it would do recipes 2,3,4,5,6 ect if that makes sense. I am still mindblown about how powerful chatgpt can be...Unrelated comment, I used it to write a resume and cover letter that landed me a job bookkeeping job.
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


10,653 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.