Don't you hate it when you can't remember how to craft something in Minecraft? Well, time to remedy that!
Task
Your task is to take an input, either as a 1D or 2D list and output what item is a result of the crafting table!
Input
You may take input as either a string or a list of length 9
or a 2D nested array.
If you take input as a...
String
Each item in the table is 1 char in the printable ASCII character (0x20
to 0x7E
). To represent an empty space, you use a -
e.g. WWW-W-WWW
would be the same as a crafting table like
+------+------+------+
| Wood | Wood | Wood |
+------+------+------+
| | Wood | |
+------+------+------+
| Wood | Wood | Wood |
+------+------+------+
You may also take input as a multiline string as long as all spaces are preserved e.g.
WWW
W
WWW
1D array
You would take the input as a char array where empty spaces on the crafting table would be an empty char e.g. the above table would be ['W','W','W','','W','','W','W','W']
2D array
This time, each list represents a line on the crafting table, where an empty space is an empty char e.g. [['W','W','W'],['','W',''],['W','W','W']]
You can assume that the input will always correspond to an item that can be crafted, and if using array input, you may replace the empty char with any character not used as an abbreviated name.
Output
Output will be the item crafted from the input, in any form you want, as long as it is obvious what it means. (Personally, I would use my 1 letter abbreviations of the items)
Ingredients
For this challenge, wood
means wooden planks, not wooden logs.
You only have to handle the most common items when crafting. These are the ingredients for crafting but may also be products of crafting. The crafting recipe follows the format xxxxxxxxx
like the string input above. If an item cannot be crafted, ---------
is placed instead.
Some recipes are shapeless, meaning that just so long as all items are there, the item will be made. These are denoted be a *
. An example of this would be pumpkin pie
(not one in this challenge) that only needs pumpkin
, sugar
and egg
to be made.
item name | abb. name | crafting recipe
----------------+-----------+------------------
wood | W | ---------
cobblestone | C | ---------
sticks | S | ----W--W-
iron | I | ---------
gold | G | ---------
diamond | D | ---------
redstone | R | ---------
string | N | ---------
coal | Y | ---------
sugar cane | U | ---------
redstone torch | E | -R--S----
paper | P | ---------
book | B | ---PL-PP-
wool | M | ---NN-NN-
obsidian | O | ---------
gunpowder | X | ---------
sand | A | ---------
glass | H | ---------
feather | F | ---------
flint | K | ---------
torch | T | ---------
leather | L | ---------
material blocks | Z | QQQQQQQQQ (here Q represents any in `[G, I, R, D, Y]`
compass | V | -I-IRI-I-
Products
This is a list of all the products that you could handle for crafting. if the item is also an ingredient, it will not be included here but you must still be able to handle it. Each one can be crafted using only the ingredients above and is designated a unique, lowercase letter to identify it. Armour (+
) can use any ingredient in [G, I, L, D]
. Weapons ($
) can be made from [W, C, I, G, D]
. As this is a code-golf site, however, we need to make these lists shorter. [G, I, L, D]
is denoted by a Q
and [W, C, I, G, D]
is denoted by a J
.
item name | abb. name | crafting recipe
----------------+-----------+------------------
crafting table | a | -----WWWW
boots + | b | ---Q-QQ-Q
pants + | c | QQQQ-QQ-Q
chestplate + | d | Q-QQQQQQQ
helmet + | e | QQQQ-Q---
bed | f | ---MMMWWW
chest | g | WWWW-WWWW
wood door | h | WW-WW-WW-
iron door | i | II-II-II-
furnace | j | CCCC-CCCC
trap door | k | ---WW-WW-
TNT | l | XAXAXAXAX
anvil | m | ZZZ-I-III
axe $ | n | -JJ-SJ-S-
sword $ | o | -J--J--S-
pickaxe $ | p | JJJ-S--S-
hoe $ | q | JJ--S--S-
shovel $ | r | -J--S--S-
arrow | s | -K--S--F-
bow | t | SN-S-NSN-
bowl | u | ---W-W-W-
gold nugget * | v | ----G----
bucket | w | ---I-I-I-
clock | y | -G-GRG-G-
map | z | PPPPVPPPP
fishing rod | 1 | --S-SNS-N
flint and steel | 2 | ----I---K
shears | 3 | ---I---I-
wood button * | 4 | ----W----
dropper | 5 | CCCC-CCRC
stone button * | 6 | ----C----
jukebox | 7 | WWWWDWWWW
lever | 8 | ----S--C-
noteblock | 9 | WWWWRWWWW
piston | 0 | WWWCICCRC
pressure plate | ! | ------WW- (W can also be replaced with C/I/G)
repeater | @ | ---ERECCC
tripwire hook | # | -I--S--W-
activator rail | ( | ISIIEIISI
boat | % | ---W-WWWW
minecart | ^ | ---I-IIII
powered rail | & | G-GGSGGRG
rail | ) | I-IISII-I
stone wall | { | ---CCCCCC
fence gate | } | ---SWSSWS
fence panel | [ | ---SSSSSS
glass pane | ] | ---HHHHHH
iron bars | ; | ---IIIIII
item frame | : | SSSSLSSSS
ladder | ' | S-SSSSS-S
sandstone | " | -----AAAA
slabs | | | ---CCC---
stairs | < | W--WW-WWW
bookshelves | > | WWWBBBWWW
carpet | . | -------MM
painting | , | SSSSMSSSS
sign | ? | WWWWWW-S-
cauldron | / | I-II-IIII
enchant. table | ` | -B-DODOOO
glass bottle | ~ | ---H-H-H-
rocket * | _ | -----PXXX
Scoring
As it would be unreasonable to ask you to do all of these recipes, you only have to do the ones that you want! But of course, the more that you do, the better your score.
Score is defined as
score = length of program in bytes / number of working recipes squared
For example, this could be a submission.
input()
print('S')
As you can assume that the input passed will be one that it can handle (----W--W-
), it will always output S
, which is equivalent to sticks
. This would score 18 / 1 = 18.
You must take input to be a valid program and you must be able to handle at least 5 different inputs.
The person with the lowest score wins.
Rules
- Lowest score wins
- You may take input using any accepted method (function parameters, STDIN etc)
- You can only take input in one of the above forms. It isn't too restrictive and should be workable
- Standard loopholes are disallowed
- You must take input
- You must output at least
5
correct results to qualify as competing. - For recipes that are shapeless, e.g. gold nuggets, different combinations do not count as different recipes.
----W----
is the same (recipe-wise) as--W------
and is only 1 recipe. - On the flip side of this, for recipes that use more than one material, such as material blocks, each different material counts as a different recipe, meaning that
IIIIIIIII
is not the same (recipe-wise) asRRRRRRRRR
.
Good luck, Minecrafters!
W--W-----
,-W--W----
,--W--W---
,---W--W--
,----W--W-
, or,-----W--W
. do we need handle only one of these or all of these? \$\endgroup\$