{"data":{"mdx":{"id":"0cdd69b2-0e03-5f82-bff9-41f38dbf0905","code":{"body":"function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }\n\nfunction _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }\n\nfunction _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }\n\n/* @jsx mdx */\nvar _frontmatter = {\n  \"date\": \"2019-05-05\",\n  \"order\": 8,\n  \"title\": \"This is Anti-Climactic\",\n  \"tags\": [\"education\", \"javascript\", \"Advent of Code\"]\n};\n\nvar makeShortcode = function makeShortcode(name) {\n  return function MDXDefaultShortcode(props) {\n    console.warn(\"Component \" + name + \" was not imported, exported, or provided by MDXProvider as global scope\");\n    return mdx(\"div\", props);\n  };\n};\n\nvar layoutProps = {\n  _frontmatter: _frontmatter\n};\nvar MDXLayout = \"wrapper\";\nreturn function MDXContent(_ref) {\n  var components = _ref.components,\n      props = _objectWithoutProperties(_ref, [\"components\"]);\n\n  return mdx(MDXLayout, _extends({}, layoutProps, props, {\n    components: components,\n    mdxType: \"MDXLayout\"\n  }), mdx(\"h2\", null, \"The Problem\"), mdx(\"p\", null, \"For Part Two, we're asked to find every point that has a \", mdx(\"em\", {\n    parentName: \"p\"\n  }, \"total\"), \" distance to every \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"input\"), \" point of less than 10000. I didn't do anything fancy here, not even a use of \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \".reduce()\"), \" to turn my array of grid points into a number. Just good old \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"for\"), \" loops. My one optimization was in the innermost \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"for\"), \" loop, where I calculate the value of \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"current\"), \", the total distance of the current point to every point in \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"input\"), \". Since I only want the points that have \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"current\"), \" less than 10000, I include that as part of the condition in the loop. Once \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"current\"), \" hits 10000, I break out of the loop and go on to the next point.\"), mdx(\"pre\", null, mdx(\"code\", _extends({\n    parentName: \"pre\"\n  }, {\n    \"className\": \"language-javascript\"\n  }), \"let total = 0\\nfor (let x = 0; x <= xMax; x += 1) {\\n  for (let y = 0; y <= yMax; y += 1) {\\n    let current = 0\\n    for (let i = 0; i < input.length && current < 10000; i += 1) {\\n      current += Math.abs(input[i][0] - x) + Math.abs(input[i][1] - y)\\n    }\\n    if (current < 10000) total += 1\\n  }\\n}\\nconsole.log(total)\\n\")), mdx(\"p\", null, \"This makes me think I overcomplicated Part One, but I'm not going to do it again any time soon.\"));\n}\nMDXContent.isMDXComponent = true;"}}},"pageContext":{"isCreatedByStatefulCreatePages":false,"id":"0cdd69b2-0e03-5f82-bff9-41f38dbf0905","slug":"/2018-advent-of-code-day-six-part-two/","timeToRead":1,"wordCount":130,"frontMatter":{"date":"2019-05-05","title":"This is Anti-Climactic","tags":["education","javascript","Advent of Code"]},"prev":{"id":"9cc5cc71-dce2-5e6a-977d-334313740f40","parent":{"name":"2018-advent-of-code-day-six"},"excerpt":"These geometry problems are tough. The Problem This is best explained by the Advent of Code site itself, so I'm going to copy. For example…","fields":{"slug":"/2018-advent-of-code-day-six/"},"timeToRead":10,"wordCount":{"words":2562},"frontmatter":{"date":"2019-05-05","title":"Again with the Geometry","tags":["education","javascript","Advent of Code"]}},"next":{"id":"b7118581-8cfd-5918-8049-7800ffaeba3c","parent":{"name":"2018-advent-of-code-day-one"},"excerpt":"2018 Advent of Code, Day One Advent of Code  is a series of software puzzles released every year during Advent ^advent . There's a cute…","fields":{"slug":"/2018-advent-of-code-day-one/"},"timeToRead":4,"wordCount":{"words":1158},"frontmatter":{"date":"2019-05-04","title":"Solving Problems with Code","tags":["education","javascript","Advent of Code"]}}}}