Code for the Advent of Code event
aoc
advent-of-code
1#!/usr/bin/env ruby
2# frozen_string_literal: true
3
4require 'matrix'
5
6input = $stdin.readline.strip.to_i
7
8steps = (Math.sqrt(input).ceil / 2).floor
9offset = (input - (((2 * steps) - 1)**2)) % (2 * steps)
10steps += (offset - steps).abs
11
12puts "Part 1: #{steps}"
13
14# Part 2 from OEIS: https://oeis.org/A141481