Advent of Code Day 2: Inventory Management System ---第2天:库存管理系统---

魏航
2023-12-01

                                         Advent of Code 2018

                            --- Day 2: Inventory Management System ---

附上GitHub代码:https://github.com/chq11/Advent-of-Code-2018

注:原文是英文版的,本文的中文使用Google 翻译的,个别词翻译的不是特别准确,但是不影响对题目的理解。

You stop falling through time, catch your breath, and check the screen on the device. "Destination reached. Current Year: 1518. Current Location: North Pole Utility Closet 83N10." You made it! Now, to find those anomalies.

你不停地摔倒,屏住呼吸,检查设备上的屏幕。 “到达目的地。当前年份:1518。当前位置:North Pole Utility Closet 83N10。”你做到了!现在,找到那些异常现象。

Outside the utility closet, you hear footsteps and a voice. "...I'm not sure either. But now that so many people have chimneys, maybe he could sneak in that way?" Another voice responds, "Actually, we've been working on a new kind of suit that would let him fit through tight spaces like that. But, I heard that a few days ago, they lost the prototype fabric, the design plans, everything! Nobody on the team can even seem to remember important details of the project!"

在公用设施壁橱外,你会听到脚步声和声音。 “......我也不确定。但现在有这么多人有烟囱,也许他可以这样偷偷溜走?”另一个声音回应说:“实际上,我们一直在研究一种新型的西装,让他穿过这样的狭窄空间。但是,我听说几天前他们丢失了原型面料,设计方案,一切!团队中的任何人都无法记住项目的重要细节!“

"Wouldn't they have had enough fabric to fill several boxes in the warehouse? They'd be stored together, so the box IDs should be similar. Too bad it would take forever to search the warehouse for two similar box IDs..." They walk too far away to hear any more.

“难道他们没有足够的布料来填充仓库中的几个箱子吗?它们会被存放在一起,因此箱子ID应该是相似的。太糟糕了,在仓库中搜索两个类似的箱子ID需要花费很长时间...... “他们走得太远,不能再听了。

Late at night, you sneak to the warehouse - who knows what kinds of paradoxes you could cause if you were discovered - and use your fancy wrist device to quickly scan every box and produce a list of the likely candidates (your puzzle input).

深夜,你潜入仓库 - 谁知道如果你被发现会导致什么样的悖论 - 并使用你喜欢的手腕设备快速扫描每个盒子并产生一个可能的候选人列表(你的拼图输入)。

To make sure you didn't miss any, you scan the likely candidate boxes again, counting the number that have an ID containing exactly two of any letter and then separately counting those with exactly three of any letter. You can multiply those two counts together to get a rudimentary checksum and compare it to what your device predicts.

为了确保您没有错过任何一个,您再次扫描可能的候选框,计算具有包含任何字母中的两个的ID的数字,然后分别计算具有任何字母的三个的那些。您可以将这两个计数相乘以获得基本校验和,并将其与设备预测的进行比较。

For example, if you see the following box IDs:

  • abcdef contains no letters that appear exactly two or three times.
  • bababc contains two a and three b, so it counts for both.
  • abbcde contains two b, but no letter appears exactly three times.
  • abcccd contains three c, but no letter appears exactly two times.
  • aabcdd contains two a and two d, but it only counts once.
  • abcdee contains two e.
  • ababab contains three a and three b, but it only counts once.

例如,如果您看到以下框ID:

abcdef不包含恰好出现两到三次的字母。
bababc包含两个a和三个b,所以它对两者都很重要。
abbcde包含两个b,但没有一个字母恰好出现三次。
abcccd包含三个c,但没有一个字母恰好出现两次。
aabcdd包含两个a和两个d,但它只计算一次。
abcdee包含两个e。
ababab包含三个a和三个b,但它只计算一次。

Of these box IDs, four of them contain a letter which appears exactly twice, and three of them contain a letter which appears exactly three times. Multiplying these together produces a checksum of 4 * 3 = 12.

在这些盒子ID中,其中四个包含一个完全出现两次的字母,其中三个包含一个恰好出现三次的字母。将这些乘以一起产生4 * 3 = 12的校验和。

What is the checksum for your list of box IDs?

您的箱子ID列表的校验和是多少?

Your puzzle answer was 8820.

你的拼图答案是8820

--- Part Two ---

Confident that your list of box IDs is complete, you're ready to find the boxes full of prototype fabric.

确信您的盒子ID列表已经完成,您已准备好找到装满原型结构的盒子。

The boxes will have IDs which differ by exactly one character at the same position in both strings. For example, given the following box IDs:

abcde
fghij
klmno
pqrst
fguij
axcye
wvxyz

这些框的ID将在两个字符串中的相同位置恰好相差一个字符。例如,给定以下框ID:

ABCDE
FGHIJ
KLMNO
PQRST
fguij
axcye
wvxyz

The IDs abcde and axcye are close, but they differ by two characters (the second and fourth). However, the IDs fghij and fguij differ by exactly one character, the third (h and u). Those must be the correct boxes.

ID abcde和axcye很接近,但它们相差两个字符(第二个和第四个)。但是,ID fghij和fguij恰好相差一个字符,第三个字符(h和u)。那些必须是正确的盒子。

What letters are common between the two correct box IDs? (In the example above, this is found by removing the differing character from either ID, producing fgij.)

两个正确的盒子ID之间有什么共同点? (在上面的例子中,可以通过从任一ID中删除不同的字符来找到它,生成fgij。)

Your puzzle answer was bpacnmglhizqygfsjixtkwudr.

你的谜题答案是bpacnmglhizqygfsjixtkwudr。

 类似资料: