Programmer's Garden
Being a professional software developer, you cannot risk exposing yourself to the harsh non-artificial light of the sun, but you also have a soft spot for flowers, and want to keep your garden in good shape all year round.
To this end, a gardener is hired each month to tidy up the flowerbed at the foot of your house. However you need to make sure the gardener is doing his job properly, and work out a suitable payment for the hard working fellow. Naturally a software solution is best.
Input
Your program will be fed input describing the flowerbed as it appears current, and details of items that need to be removed. The program must output the garden devoid of the clutter, and print out a breakdown of the gardeners pay. The input can be either be from STDIN, or as a single command line argument.
The first line of input is of the format
width height unwanted_item_type_count
where width
is the width of the flowerbed, height
is the height of the flowerbed (both in ASCII characters), and unwanted_item_type_count
tells you how many lines will following containing a description of a type of item to be removed from the garden.
Each line for each unwanted type of item is of the format
width height string_representation name fee_per_item
where width
is the width of the item, height
is the height of the item (both in ASCII characters), string_representation
is the string representation of the item without line breaks, name
is an identifier for the type of item (spaces will be replaced with underscores), and fee_per_item
is how much the gardener must be paid for the removal of each type of item.
For example
3 2 .R.\|/ rouge_flower 3
Represents an item type of name rouge_flower
, which costs 3 to remove, and looks like this:
.R.
\|/
The items will not contain spaces, and no item may have a border consisting entirely of dots, and the string representation will also be the exact size described. Thusly, all of the following are invalid inputs:
3 1 ( ) space 0
1 1 . dot 0
2 1 .! bang 0
3 2 .@.\|/. plant 0
Note that 0 is however a valid fee (fees will always be integers greater than -1).
Note also that the flowerbed is predominately made up of dots (.
) rather than spaces, and you can safely use whitespace as delimitation for all the inputs. The flowerbed is always bounded by dots itself.
After the unwanted item types are listed, then comes the ASCII representation of the flowerbed of given width and height.
Output
Output should be to STDOUT, or suitable alternative if your language doesn't support it.
The output starts with a print-out of the flowerbed, but with all unwanted items removed (replaced with dots), so you can see how it should appear and check the gardener has done his job. Each item in the flowerbed will be surrounded by a rectangle of dots, and will be one-contiguous item (i.e. there will be no separating dots inside the item). For example
.....
.#.#.
.....
shows 2 separate items
.....
.\@/.
.....
shows 1 item
......
.#....
....|.
....|.
.o--/.
......
is invalid, as while the stone (#) can be matched, the snake (you couldn't tell it was a snake?) cannot because the stone interferes with the required surrounding of dots.
...
\@.
...
This is also invalid, as the snail is on the edge of the flowerbed, and the edge must always be bounded by dots in a valid input.
After this, there should be a listing of each type of unwanted item, giving the count, the cost per item, and costs for all the items (count * cost per item), in the format:
<count> <name> at <cost_per_item> costs <cost>
After this, there should be a single line yielding the total cost (the sum of the costs for unwanted items):
total cost <total_cost>
Example
For this given input
25 18 3
4 2 .\/.\\// weeds 5
2 1 \@ snails 2
1 1 # stones 1
.........................
.\@/.................\@..
............\/...........
......O....\\//..^|^.....
.#...\|/.........^|^.....
..................|......
.................\|/.....
..\@.....\/...........#..
........\\//....#........
....*....................
...\|/......\/......\@/..
...........\\//..........
..................*......
.......\@/.......\|/.....
...O.....................
..\|/.......*............
.......#...\|/....\@.....
.........................
The program should produce this output
.........................
.\@/.....................
.........................
......O..........^|^.....
.....\|/.........^|^.....
..................|......
.................\|/.....
.........................
.........................
....*....................
...\|/..............\@/..
.........................
..................*......
.......\@/.......\|/.....
...O.....................
..\|/.......*............
...........\|/...........
.........................
3 weeds at 5 costs 15
3 snails at 2 costs 6
4 stones at 1 costs 4
total cost 25
The output must be terminated by a line-break.
This is code-golf, may the shortest code win.
Additional test case
Edit: this used to contain Unicode, which isn't allowed in the flowerbed, far too modern. This has been rectified, sorry about that.
25 15 5
5 3 ..@..\\|//.\|/. overgrown_plants 3
5 3 @-o....|...\|/. semi-articulated_plant 4
3 2 .|.\@/ mutant_plants 5
1 1 $ dollars 0
1 1 # stones 1
.........................
........@................
....$..\|/...........@...
............|.......\|/..
...#.......\@/...........
.........................
.........................
......@.......@......@...
.....\|/....\\|//...\|/..
.............\|/.........
.#....................#..
.........$.......|.......
...\/.......\/..\@/..\/..
..\\//.....\\//.....\\//.
.........................
Expected Output:
.........................
........@................
.......\|/...........@...
....................\|/..
.........................
.........................
.........................
......@..............@...
.....\|/............\|/..
.........................
.........................
.........................
...\/.......\/.......\/..
..\\//.....\\//.....\\//.
.........................
1 overgrown_plants at 3 costs 3
0 semi-articulated_plants at 4 costs 0
2 mutant_plants at 5 costs 10
2 dollars at 0 costs 0
3 stones at 1 costs 3
total cost 16
\@
and@/
for example.. Or are they bound to point eternally to west? \$\endgroup\$