首页 > 其他分享 >Day 3: Spiral Memory

Day 3: Spiral Memory

时间:2022-10-10 23:33:36浏览次数:66  
标签:square carried Spiral only steps location Memory Data Day

https://adventofcode.com/2017/day/3

--- Day 3: Spiral Memory ---

You come across an experimental new kind of memory stored on an infinite two-dimensional grid.

Each square on the grid is allocated in a spiral pattern starting at a location marked 1 and then counting up while spiraling outward. For example, the first few squares are allocated like this:

17  16  15  14  13
18   5   4   3  12
19   6   1   2  11
20   7   8   9  10
21  22  23---> ...

While this is very space-efficient (no squares are skipped), requested data must be carried back to square 1 (the location of the only access port for this memory system) by programs that can only move up, down, left, or right. They always take the shortest path: the Manhattan Distance between the location of the data and square 1.

For example:

  • Data from square 1 is carried 0 steps, since it's at the access port.
  • Data from square 12 is carried 3 steps, such as: down, left, left.
  • Data from square 23 is carried only 2 steps: up twice.
  • Data from square 1024 must be carried 31 steps.

How many steps are required to carry the data from the square identified in your puzzle input all the way to the access port?

To play, please identify yourself via one of these services:

[GitHub] [Google] [Twitter] [Reddit] - [How Does Auth Work?]

标签:square,carried,Spiral,only,steps,location,Memory,Data,Day
From: https://www.cnblogs.com/z-cm/p/16777832.html

相关文章

  • 实验4:开源控制器实践——OpenDaylight
    实验4:开源控制器实践——OpenDaylight一、实验目的1.能够独立完成OpenDaylight控制器的安装配置;2.能够使用Postman工具调用OpenDaylightAPI接口下发流表。二、实验环......
  • 学习python-Day70
    今天学习内容一、自定义频率类fromrest_framework.throttlingimportBaseThrottleclassMyThrottle(BaseThrottle):VISIT_RECORD={}#存放用户访问记录{ip......
  • Day03-java学习记录
    类型转换由于Java是强类型语言,所以某些运算,需要用到类型转换!低》》》》》》》》》》》》》》》》》高byte,short,char->int->long->float->double强制转换高到低自......
  • day07 方法重写&super、this、static关键字&JVM的类加载顺序题目
    day07方法重写1)重写发生在子父类当中2)方法名、参数列表、返回值均相同3)重写的方法,方法体或者访问控制修饰符不同4)子类方法的访问权限不能缩小,比如父类是int,子类重写权......
  • day20 700,617,98, 645
    700.二叉搜索树中的搜索classSolution{publicTreeNodesearchBST(TreeNoderoot,intval){if(root.val==val||root==null)returnroot;//1:终止......
  • 代码随想录day20 | 654. 最大二叉树 617. 合并二叉树 700. 二叉搜索树中的搜索 98. 验
    654.最大二叉树题目|文章方法:模拟思路按照题目要求顺序使用递归函数traversal(nums,begin,end)对数组nums二叉树进行模拟。这道题的思路方法与105.从前序遍历和中序......
  • spring day02 xml开发总结以及注解开发总结
    第三方资源配置管理管理DataSource连接池对象【第一步】添加Druid连接池依赖<dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><......
  • 代码随想录day17
    110.平衡二叉树递归法:1classSolution{2public:3//递归三步走4//1、确定返回值和函数参数5intgetHeight(TreeNode*node){6//......
  • day09-2视图和用户权限
    视图和用户权限1.视图(view)看一个需求emp表的列信息很多,有些信息是个人重要信息(比如:sal、comm、mgr、hiredate),如果我们希望某个用户只能查询emp表的empno、enamel、job......
  • 前端Vue2-Day46
    Vue的特点:1.采用组件化模式,提高代码复用率,使代码易于维护。2.声明式编码,编码人员无需直接操作DOM,提高开发效率。3.使用虚拟DOM和diff算法,尽量复用DOM节点。Vue.config......