{"size": 799, "ext": "js", "max_stars_repo_path": "2018/day-05/solution.js", "max_stars_repo_name": "amclin/advent-of-code", "max_stars_repo_stars_event_min_datetime": "2020-12-08T18:12:09.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-08T18:12:09.000Z", "max_issues_repo_path": "2018/day-05/solution.js", "max_issues_repo_name": "amclin/advent-of-code", "max_issues_repo_issues_event_min_datetime": "2018-12-20T05:57:31.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T13:02:57.000Z", "max_forks_repo_path": "2018/day-05/solution.js", "max_forks_repo_name": "amclin/advent-of-code", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 213, "max_forks_count": null, "avg_line_length": 25.7741935484, "max_line_length": 89, "alphanum_fraction": 0.6145181477}
const fs = require('fs')
const path = require('path')
const filePath = path.join(__dirname, 'input.txt')
const { reducePolymer, cleanProblemUnits } = require('./polymer')

fs.readFile(filePath, { encoding: 'utf8' }, (err, data) => {
  if (err) throw err

  data = data.trim()

  const answer = reducePolymer(data).length

  // Try removing each potential problem pair, and see which gets to the smallest polymer
  let answer2 = answer
  for (let i = 65; i < 91; i++) { // ASCII charset 65 = A, 91 = Z
    answer2 = Math.min(
      answer2,
      reducePolymer(
        cleanProblemUnits(
          String.fromCharCode(i)
          , data)
      ).length
    )
  }

  console.log('-- Part 1 --')
  console.log(`Answer: ${answer}`)
  console.log('-- Part 2 --')
  console.log(`Answer: ${answer2}`)
})
