aboutsummaryrefslogtreecommitdiff
path: root/make.rb
blob: a06692726a7f26b40512aff1fb8326c90d0f0202 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#!/usr/bin/env ruby

require 'json'
Products = JSON.parse(DATA.read)
Productindex = Products.keys

ingredientsstack = []
buildstack = {}

build = ARGV.shift
if build.nil? then
  puts "Build what?"
  exit 1
end

quantity = ARGV.shift
if quantity.nil? then
  quantity = 1
else
  quantity = quantity.to_i
end

ingredientsstack.push build

while ingredientsstack.count > 0 do
  build = ingredientsstack.pop
  product = Products[build]
  if product.nil? then
    puts "#{build} is not a product"
    exit 1
  end
  product.each do |key, value|
    value.times do
      ingredientsstack.push key
    end
  end
  if buildstack[build].nil? then
    buildstack[build] = 1
  else
    buildstack[build] += 1
  end
end

buildstack.keys.sort { |a, b|
  Productindex.index(a) <=> Productindex.index(b)
}.each do |key|
  puts "%4d: %s" % [buildstack[key] * quantity, key]
end

__END__
{
  "Cardboard": {},
  "Concrete": {},
  "Magnet": {},
  "Metal": {},
  "Paint": {},
  "Plastic": {},
  "Rare metal": {},
  "Rubber": {},
  "Wire": {},

  "Adv concrete": {
    "Concrete": 2,
    "Metal": 2
  },
  "Belt": {
    "Rubber": 2
  },
  "Box": {
    "Cardboard": 4
  },
  "Cable": {
    "Metal": 1
  },
  "Circuit": {
    "Plastic": 2,
    "Wire": 1
  },
  "Gear": {
    "Metal": 2
  },
  "Hose": {
    "Rubber": 2
  },
  "Metal wheel": {
    "Metal": 2
  },
  "Motor": {
    "Magnet": 2,
    "Metal": 1,
    "Wire": 2
  },
  "Plastic wheel": {
    "Plastic": 2
  },
  "Pump": {
    "Metal": 2,
    "Plastic": 1,
    "Rubber": 1
  },
  "Garden gnome": {
    "Concrete": 1,
    "Paint": 1,
    "Box": 1
  },
  "Speakers": {
    "Magnet": 2,
    "Plastic": 2,
    "Wire": 1,
    "Box": 1
  },
  "Toaster": {
    "Metal": 2,
    "Wire": 2,
    "Box": 1
  },
  "Air gun": {
    "Metal": 4,
    "Hose": 2
  },
  "Arm": {
    "Metal": 2,
    "Circuit": 1,
    "Motor": 2
  },
  "Conveyor": {
    "Belt": 1,
    "Gear": 2,
    "Metal wheel": 8,
    "Motor": 1
  },
  "Lifter": {
    "Metal": 3,
    "Cable": 2,
    "Hose": 2,
    "Motor": 1,
    "Pump": 1
  },
  "Logic unit": {
    "Wire": 5,
    "Circuit": 4
  },
  "Mover": {
    "Metal": 3,
    "Gear": 4,
    "Metal wheel": 4,
    "Motor": 2
  },
  "Road": {
    "Concrete": 4,
    "Adv concrete": 2
  },
  "Support": {
    "Metal": 2,
    "Adv concrete": 2
  },
  "Thing-a-ma-jig": {
    "Circuit": 3,
    "Hose": 2,
    "Motor": 1,
    "Pump": 2
  },
  "Widget": {
    "Metal": 1,
    "Plastic": 4,
    "Wire": 2,
    "Circuit": 1
  },
  "Toy car": {
    "Metal": 1,
    "Paint": 1,
    "Plastic": 3,
    "Plastic wheel": 4,
    "Box": 1
  },
  "Water gun": {
    "Paint": 1,
    "Plastic": 6,
    "Hose": 2,
    "Box": 1
  },

  "Adv logic unit": {
    "Wire": 4,
    "Circuit": 4,
    "Logic unit": 2
  },
  "Assembly line": {
    "Air gun": 2,
    "Arm": 2,
    "Conveyor": 3,
    "Lifter": 1,
    "Mover": 1
  },
  "Jet engine": {
    "Metal": 8,
    "Wire": 12,
    "Hose": 6,
    "Pump": 4,
    "Thing-a-ma-jig": 1
  },
  "Sensor": {
    "Rare metal": 2,
    "Wire": 1,
    "Circuit": 1,
    "Logic unit": 1
  },
  "Bridge": {
    "Road": 6,
    "Support": 6
  },
  "Forklift": {
    "Metal": 6,
    "Rubber": 8,
    "Metal wheel": 4,
    "Motor": 2,
    "Box": 4
  },
  "Radio tower": {
    "Metal": 12,
    "Wire": 6,
    "Support": 4
  },
  "Tablet computer": {
    "Plastic": 1,
    "Wire": 3,
    "Circuit": 3,
    "Logic unit": 1,
    "Box": 1
  },

  "Drone": {
    "Plastic": 4,
    "Rare metal": 1,
    "Motor": 4,
    "Adv logic unit": 1,
    "Sensor": 2
  },
  "Jet": {
    "Metal": 24,
    "Wire": 18,
    "Adv logic unit": 6,
    "Jet engine": 4,
    "Sensor": 8
  },
  "Oculus rift": {
    "Plastic": 2,
    "Rare metal": 2,
    "Wire": 4,
    "Widget": 2,
    "Sensor": 2
  },

  "Builder: Tier 1": {
    "Motor": 1,
    "Arm": 2,
    "Conveyor": 1,
    "Thing-a-ma-jig": 1
  },
  "Builder: Tier 2": {
    "Motor": 1,
    "Arm": 3,
    "Conveyor": 1,
    "Thing-a-ma-jig": 1,
    "Widget": 2
  },
  "Builder: Tier 3": {
    "Logic unit": 1,
    "Thing-a-ma-jig": 1,
    "Widget": 4,
    "Assembly line": 1
  },
  "Builder: Tier 4": {
    "Widget": 2,
    "Adv logic unit": 2,
    "Assembly line": 1,
    "Sensor": 6
  },
  "Builder: Builders": {
    "Arm": 2,
    "Logic unit": 1,
    "Thing-a-ma-jig": 4,
    "Widget": 1,
    "Assembly line": 1
  },
  "Builder: Taskers": {
    "Thing-a-ma-jig": 2,
    "Widget": 2,
    "Adv logic unit": 1,
    "Assembly line": 1
  },
  "Builder: Universal": {
    "Arm": 4,
    "Thing-a-ma-jig": 2,
    "Widget": 4,
    "Adv logic unit": 2,
    "Assembly line": 2
  },

  "Tasker: Purchasing": {
    "Paint": 1,
    "Wire": 6,
    "Circuit": 4,
    "Logic unit": 1,
    "Widget": 1
  },
  "Tasker: Sales": {
    "Paint": 1,
    "Wire": 8,
    "Logic unit": 2,
    "Widget": 1,
    "Adv logic unit": 1
  }
}