news 2026/4/23 18:54:14

谷歌 Gemini 正在加入 Advent of Code 挑战

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
谷歌 Gemini 正在加入 Advent of Code 挑战

原文:towardsdatascience.com/google-gemini-is-entering-the-advent-of-code-challenge-dfd88ffa12a6?source=collection_archive---------9-----------------------#2024-12-02

一个开源项目,用于探索 LLM 在编程挑战中的能力与局限

https://heiko-hotz.medium.com/?source=post_page---byline--dfd88ffa12a6--------------------------------https://towardsdatascience.com/?source=post_page---byline--dfd88ffa12a6-------------------------------- Heiko Hotz

·发表于 Towards Data Science ·阅读时长 8 分钟·2024 年 12 月 2 日

https://github.com/OpenDocCN/towardsdatascience-blog-zh-2024/raw/master/docs/img/7c62dc78a56ed7265c284edb641d6503.png

图片由作者提供(使用 Flux 1.1 Pro 创建)

这是什么?

如果 2024 年在生成性人工智能领域教给我们什么,那就是编程是大规模语言模型(LLMs)最具前景的应用之一。

在这篇博客中,我将描述如何使用目前领先于 LMArena 排行榜的最先进的 LLM——Gemini Experimental 1121,来应对 Advent of Code 挑战。

https://github.com/OpenDocCN/towardsdatascience-blog-zh-2024/raw/master/docs/img/037eb3b5d51254c5340d3640600163e8.png

图片由作者提供

我将概述我的方法,并分享我的 开源代码库,以便读者进一步探索并复现结果。

为什么我们应该关注?

LLMs + 编程是一个令人兴奋的领域,有很多原因,其中几个亮点如下:

所以,这无疑是一个有趣且令人兴奋的方向,我认为通过动手挑战来进一步探索它可能会很有趣。

Advent of Code 挑战

对于那些不熟悉 Advent of Code 挑战的人来说:这是一个每年举办的活动,从 12 月 1 日到 12 月 25 日,提供每天的编程难题,类似于圣诞倒计时日历。每天都会发布一个包含两部分的新难题,程序员可以在其中测试他们的编程和问题解决能力。这是一个让各个级别的开发者都可以练习编程的有趣方式。

每日挑战的两个部分围绕一个类似的问题展开,并使用相同的输入数据。其目的是编写一个 Python 程序来处理输入数据并生成解决方案(通常是一个数字)。一旦我们运行代码,模型计算出解决方案,我们可以将其粘贴到网站上,查看它是否正确。如果正确,第二部分将解锁,采用类似的程序。

竞赛持续 25 天,用户最多可以收集 50 星星(每天 2 星)。

一个很好的 LLM 挑战

如上所述,这是一个非常适合 LLM 的挑战。我们只需拿到问题陈述,插入选择的 LLM,让它生成代码,运行代码,再将生成的解决方案粘贴到网站上,查看 LLM 是否成功。

对于这个项目,我使用的是 Gemini Experimental 1121,它大大提高了编程和推理能力。它可以通过 Google 的AI Studio获得。我在整个挑战中使用相同的系统提示——它是一个零-shot 提示(没有链式思维),并且要求代码通过输入重定向接收输入,像这样:

python day01/part1.py<day01/input.txt

系统提示是:

Provide python code to solve a given puzzle.Assume thereisaninput.txtfilethat can be read viainputredirectioninthe command line.

然后我会发布实际的挑战,Gemini 将生成应当产生正确解决方案的代码。我将代码复制到 GH 仓库并运行,然后将生成的解决方案粘贴到 Advent of Code 网站上查看它是否正确。

仓库

每天的挑战都组织在自己的目录中:

dayXX/├──input.txt# Challenge input├── part1-problem.txt# Problem description for part 1├── part2-problem.txt# Problem description for part 2├── part1.py# Solution for part 1└── part2.py# Solution for part 2

part1 和 part2 的问题文本文件包含 Advent of Code 提出的挑战问题。我还在每个文本文件的末尾附上了正确的解决方案:

https://github.com/OpenDocCN/towardsdatascience-blog-zh-2024/raw/master/docs/img/541b539dd8e0b40f65902baac658a0d4.png

图片来自作者

Python 脚本包含由 Gemini 生成的代码。为了保持完全透明,我还链接到实际的对话记录,让大家可以查看并审核每一步:

https://github.com/OpenDocCN/towardsdatascience-blog-zh-2024/raw/master/docs/img/c723907aad4658ab10216a6eb423cbea.png

图片来自作者

要查看这些聊天中的一个示例,请访问我与 Gemini 关于第一天挑战的对话

我将把所有的结果记录在一个表格中,给读者一个关于模型表现的良好初步概览:

https://github.com/OpenDocCN/towardsdatascience-blog-zh-2024/raw/master/docs/img/72852ef645a49d51b9ae4148348992dc.png

图片来自作者

示例

为了更好地了解这将是什么样子,让我们来看一下第一天挑战的第一部分。以下是问题陈述:

The Chief Historianisalways presentforthe big Christmas sleigh launch,but nobody has seen himinmonths! Last anyone heard,he was visiting locations that are historically significant to the North Pole;a group of Senior Historians has asked you to accompany themasthey check the places they think he was most likely to visit.As each locationischecked,they will mark it on theirlistwitha star.They figure the Chief Historian must beinone of the first fifty places they'll look,soinorder to save Christmas,you need tohelpthem get fifty stars on theirlistbefore Santa takes off on December 25th.Collect stars by solving puzzles.Two puzzles will be made available on each dayinthe Advent calendar;the second puzzleisunlocked when you complete the first.Each puzzle grants one star.Good luck! You haven't even left yet and the group of Elvish Senior Historians has already hit a problem: their list of locations to check is currently empty. Eventually, someone decides that the best place to check first would be the Chief Historian's office.Upon pouring into the office,everyone confirms that the Chief Historianisindeed nowhere to be found.Instead,the Elves discover an assortment of notesandlists of historically significant locations! This seems to be the planning the Chief Historian was doing before he left.Perhaps these notes can be used to determine which locations to search? Throughout the Chief's office, the historically significant locations are listed not by name but by a unique number called the location ID. To make sure they don't miss anything,The Historians split into two groups,each searching the officeandtrying to create their own completelistof location IDs.There's just one problem: by holding the two lists up side by side (your puzzle input), it quickly becomes clear that the lists aren't very similar.Maybe you canhelpThe Historians reconcile their lists? For example:344325133933Maybe the lists are only off by a small amount! To find out,pair up the numbersandmeasure how far apart they are.Pair up the smallest numberinthe leftlistwiththe smallest numberinthe rightlist,then the second-smallest left numberwiththe second-smallest right number,andso on.Within each pair,figure out how far apart the two numbers are;you'll need to add upallof those distances.For example,ifyou pair up a3fromthe leftlistwitha7fromthe rightlist,the distance apartis4;ifyou pair up a9witha3,the distance apartis6.In the examplelistabove,the pairsanddistances would beasfollows:The smallest numberinthe leftlistis1,andthe smallest numberinthe rightlistis3\.The distance between themis2.The second-smallest numberinthe leftlistis2,andthe second-smallest numberinthe rightlistisanother3\.The distance between themis1.The third-smallest numberinboth listsis3,so the distance between themis0.Thenextnumbers to pair up are3and4,a distance of1.The fifth-smallest numbersineachlistare3and5,a distance of2.Finally,the largest numberinthe leftlistis4,whilethe largest numberinthe rightlistis9;these are a distance5apart.To find the total distance between the leftlistandthe rightlist,add up the distances betweenallof the pairs you found.In the example above,thisis2+1+0+1+2+5,a total distance of11! Your actual leftandright lists contain many location IDs.Whatisthe total distance between your lists?### Solution: 1666427

当将这个挑战交给 Gemini 时,它会生成以下代码:

importsysdefsolve():left_list=[]right_list=[]forlineinsys.stdin:left,right=map(int,line.strip().split())left_list.append(left)right_list.append(right)left_list.sort()right_list.sort()total_distance=0foriinrange(len(left_list)):total_distance+=abs(left_list[i]-right_list[i])print(total_distance)solve()

使用以下代码运行

python day01/part1.py<day01/input.txt

得到的结果是:

https://github.com/OpenDocCN/towardsdatascience-blog-zh-2024/raw/master/docs/img/ac065d6519cd72ddcb7ceb3031354abd.png

图片来自作者

如我们所见,Gemini 的代码生成了正确的结果。

奖励:获取解释

作为额外奖励,我们还可以请 Gemini 提供代码的解释,说明它是做什么的,以及为什么能解决这个挑战:

https://github.com/OpenDocCN/towardsdatascience-blog-zh-2024/raw/master/docs/img/d62b65f3db68b2f74aab2b7b37d41ed3.png

图片由作者提供

你可以在这里找到带有解释的聊天记录。

结论

通过这个项目,我想探索当前最先进的 LLM(大语言模型)在解决编程挑战方面的能力。我有一个假设,认为 Gemini(以及其他 LLM)已经足够优秀,可以解决大多数这些挑战。当然,这并不意味着它们已经准备好解决更复杂的真实软件挑战。

话虽如此,我只是出于好奇决定开始这个有趣的小项目。希望你喜欢它,并能为你提供一些关于我们与 LLM+编程未来发展方向的见解🤗

海科·霍茨

👋 在Medium和LinkedIn上关注我,关于生成式人工智能、机器学习和自然语言处理的内容。

👥 如果你在伦敦,可以加入我们的NLP London Meetups。

https://github.com/OpenDocCN/towardsdatascience-blog-zh-2024/raw/master/docs/img/ed0b16f80eb6e1e9f99290b10638f4d2.png

图片由作者提供

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/4/23 10:50:44

TypeScript中的interface详细介绍

interface TestTypeItem {name: string;value: string;checked?: boolean; // ? 表示可选属性 }interface 是 TypeScript 的一种类型定义方式&#xff0c;用来约束对象的结构。在这里&#xff0c;TestTypeItem 定义了 Test Type 对象 必须有 name 和 value 两个字符串属性&a…

作者头像 李华
网站建设 2026/4/23 13:35:28

如何通过API调用Wan2.2-T2V-A14B生成定制化长视频片段?

如何通过API调用Wan2.2-T2V-A14B生成定制化长视频片段&#xff1f; 在数字内容爆炸式增长的今天&#xff0c;短视频已成为品牌传播、用户互动和信息传递的核心载体。然而&#xff0c;传统视频制作流程依赖专业团队、高昂成本与漫长周期&#xff0c;难以满足个性化、高频次的内容…

作者头像 李华
网站建设 2026/4/23 12:11:33

第六十篇-ComfyUI+V100-32G+运行Wan2.2-图生视频

环境 系统&#xff1a;CentOS-7 CPU : E5-2680V4 14核28线程 内存&#xff1a;DDR4 2133 32G * 2 显卡&#xff1a;Tesla V100-32G【PG503】 (水冷) 驱动: 535 CUDA: 12.2 ComfyUI version: 0.4.0 ComfyUI frontend version: 1.34.8系统软件信息 系统信息 OS linux Python Vers…

作者头像 李华
网站建设 2026/4/23 13:35:42

交通信号仿真软件:Vistro_(13).Vistro与其他交通软件的集成

Vistro与其他交通软件的集成 在交通信号仿真软件的二次开发中&#xff0c;Vistro 通常需要与其他交通软件进行集成&#xff0c;以实现更复杂和全面的交通仿真场景。本节将详细介绍 Vistro 与一些常见交通软件的集成方法&#xff0c;包括数据交换、功能调用和联合仿真等方面。我…

作者头像 李华
网站建设 2026/4/23 14:06:29

38、Linux 服务器与 X 窗口系统全解析

Linux 服务器与 X 窗口系统全解析 1. 服务器基础与安全风险 在 Linux 系统中,服务器扮演着重要角色,但同时也伴随着安全风险。服务器可能存在漏洞、配置错误,以及本地安全方面的缺陷,如用户选择的弱密码,这些都可能使不法分子入侵计算机。例如,邮件服务器若配置不当,可…

作者头像 李华
网站建设 2026/4/22 13:40:10

Maccy剪贴板管理器:系统兼容性全面解析

Maccy剪贴板管理器&#xff1a;系统兼容性全面解析 【免费下载链接】Maccy Lightweight clipboard manager for macOS 项目地址: https://gitcode.com/gh_mirrors/ma/Maccy 您是否曾为在不同设备间切换时找不到刚复制的内容而烦恼&#xff1f;Maccy作为一款专为macOS打造…

作者头像 李华