Loading [Contrib]/a11y/accessibility-menu.js
Back
Close

Advent of Code 2017 Solutions

Advent of Code 2017 Solutions

Day 2 - Corruption Checksum

Problem

As you walk through the door, a glowing humanoid shape yells in your direction. "You there! Your state appears to be idle. Come help us repair the corruption in this spreadsheet - if we take another millisecond, we'll have to display an hourglass cursor!"

The spreadsheet consists of rows of apparently-random numbers. To make sure the recovery process is on the right track, they need you to calculate the spreadsheet's checksum. For each row, determine the difference between the largest value and the smallest value; the checksum is the sum of all of these differences.

For example, given the following spreadsheet:

5 1 9 5
7 5 3
2 4 6 8
  • The first row's largest and smallest values are 9 and 1, and their difference is 8.
  • The second row's largest and smallest values are 7 and 3, and their difference is 4.
  • The third row's difference is 6.

In this example, the spreadsheet's checksum would be 8 + 4 + 6 = 18.

Solution

const input = `1136 1129 184 452 788 1215 355 1109 224 1358 1278 176 1302 186 128 1148
242 53 252 62 40 55 265 283 38 157 259 226 322 48 324 299
2330 448 268 2703 1695 2010 3930 3923 179 3607 217 3632 1252 231 286 3689
89 92 903 156 924 364 80 992 599 998 751 827 110 969 979 734
100 304 797 81 249 1050 90 127 675 1038 154 715 79 1116 723 990
1377 353 3635 99 118 1030 3186 3385 1921 2821 492 3082 2295 139 125 2819
3102 213 2462 116 701 2985 265 165 248 680 3147 1362 1026 1447 106 2769
5294 295 6266 3966 2549 701 2581 6418 5617 292 5835 209 2109 3211 241 5753
158 955 995 51 89 875 38 793 969 63 440 202 245 58 965 74
62 47 1268 553 45 60 650 1247 1140 776 1286 200 604 399 42 572
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io
codingame x discord
Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
JOIN US ON DISCORD
Online Participants