编程题目第4题

电脑技术 电脑技术 2054 人阅读 | 9 人回复 | 2022-12-14

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
以下是摘自adventofcode.com (2022年12月4日)的题目。


一共分两题,但其实是相近的:
--- Day 4: Camp Cleanup ---
Space needs to be cleared before the last supplies can be unloaded from the ships, and so several Elves have been assigned the job of cleaning up sections of the camp. Every section has a unique ID number, and each Elf is assigned a range of section IDs.

However, as some of the Elves compare their section assignments with each other, they've noticed that many of the assignments overlap. To try to quickly find overlaps and reduce duplicated effort, the Elves pair up and make a big list of the section assignments for each pair (your puzzle input).

For example, consider the following list of section assignment pairs:

2-4,6-8
2-3,4-5
5-7,7-9
2-8,3-7
6-6,4-6
2-6,4-8
For the first few pairs, this list means:

Within the first pair of Elves, the first Elf was assigned sections 2-4 (sections 2, 3, and 4), while the second Elf was assigned sections 6-8 (sections 6, 7, 8).
The Elves in the second pair were each assigned two sections.
The Elves in the third pair were each assigned three sections: one got sections 5, 6, and 7, while the other also got 7, plus 8 and 9.
This example list uses single-digit section IDs to make it easier to draw; your actual list might contain larger numbers. Visually, these pairs of section assignments look like this:

.234.....  2-4
.....678.  6-8

.23......  2-3
...45....  4-5

....567..  5-7
......789  7-9

.2345678.  2-8
..34567..  3-7

.....6...  6-6
...456...  4-6

.23456...  2-6
...45678.  4-8
Some of the pairs have noticed that one of their assignments fully contains the other. For example, 2-8 fully contains 3-7, and 6-6 is fully contained by 4-6. In pairs where one assignment fully contains the other, one Elf in the pair would be exclusively cleaning sections their partner will already be cleaning, so these seem like the most in need of reconsideration. In this example, there are 2 such pairs.

In how many assignment pairs does one range fully contain the other?

Your puzzle answer was 453.

--- Part Two ---
It seems like there is still quite a bit of duplicate work planned. Instead, the Elves would like to know the number of pairs that overlap at all.

In the above example, the first two pairs (2-4,6-8 and 2-3,4-5) don't overlap, while the remaining four pairs (5-7,7-9, 2-8,3-7, 6-6,4-6, and 2-6,4-8) do overlap:

5-7,7-9 overlaps in a single section, 7.
2-8,3-7 overlaps all of the sections 3 through 7.
6-6,4-6 overlaps in a single section, 6.
2-6,4-8 overlaps in sections 4, 5, and 6.
So, in this example, the number of overlapping assignment pairs is 4.

In how many assignment pairs do the ranges overlap?

Your puzzle answer was 919.

Both parts of this puzzle are complete! They provide two gold stars: **

At this point, you should return to your Advent calendar and try another puzzle.

If you still want to see it, you can get your puzzle input.

You can also [Share] this puzzle.
换句话说,在下列数组中,有多少对是重叠的,两题都很接近,自己看原文题目吧。

  1. 2-4,6-8
  2. 2-3,4-5
  3. 5-7,7-9
  4. 2-8,3-7
  5. 6-6,4-6
  6. 2-6,4-8
复制代码


回答|共 9 个

孤星11 发表于 2022-12-14 09:32:57| 字数 40 | 显示全部楼层

本帖最后由 孤星11 于 2022-12-14 09:42 编辑

大家也可以用下列数组测试:

input.zip (5.1 KB, 下载次数: 0)

蓝莓糖 发表于 2022-12-14 12:13:38| 字数 16 | 显示全部楼层

legs+大神评价一下这个题目?

孤星11 发表于 2022-12-14 16:30:07| 字数 41 来自手机 | 显示全部楼层

legs+ 发表于 2022-12-14 20:29:50| 字数 137 | 显示全部楼层

蓝莓糖 发表于 2022-12-14 12:13
legs+大神评价一下这个题目?

首先,英语我就没看懂,老大,借助Google翻译,也还是没看懂
我的雅思当年可是高分,但是专业术语太多,加之我不擅长这个领域
我从事的行业跟算法差的很远
。。。
大概,意思是有包含这些数字的把它们给PASS掉

蓝莓糖 发表于 2022-12-14 21:05:20| 字数 98 | 显示全部楼层

legs+ 发表于 2022-12-14 20:29
首先,英语我就没看懂,老大,借助Google翻译,也还是没看懂
我的雅思当年可是高分,但是专业术语太多, ...

大神过谦了,算法和编程难道不是一个东西吗?

legs+ 发表于 2022-12-14 22:11:49| 字数 151 | 显示全部楼层

蓝莓糖 发表于 2022-12-14 21:05
大神过谦了,算法和编程难道不是一个东西吗?

我就是码农,砌砖的。
编程跟数学关系不大
当然,如果你要懂算法,那得学好数学,像我这样的年纪,本来学计算机就走偏了
算法是很精深的东西,你像我现在在学的flink,有算子,就是现成的函数或者库,所以我搞大数据,也没涉及到算法

海王子1982 发表于 2022-12-16 23:49:37| 字数 105 来自手机 | 显示全部楼层

蓝莓糖 发表于 2022-12-14 21:05
大神过谦了,算法和编程难道不是一个东西吗?

好像是吧,是同一个意思。
我老公是什么算法架构师,忘了。就是个写代码的程序员。
具体干啥我也不知道,都是英文我也不懂,我也没问过。

蓝莓糖 发表于 2022-12-17 08:28:20| 字数 113 | 显示全部楼层

海王子1982 发表于 2022-12-16 23:49
好像是吧,是同一个意思。
我老公是什么算法架构师,忘了。就是个写代码的程序员。
具体干啥我也不知道, ...

感觉算法架构师这个称呼更加高大上一些,程序员大家都是马上联想到码农这个词儿

孤星11 发表于 2022-12-17 13:10:43| 字数 25 来自手机 | 显示全部楼层

编程也可以不接触算法的,我的软件也几乎没涉及算法。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

热门推荐