Software Development

Advent of Eternal Champions I

By
published

Snow was falling hard across the arctic hillside. The wind was biting. No trees offered shelter. Our hero was laying in the snow, barely conscious. His gear was strewn about him. His memories were a blur. He had known many names, but he knew not what they called him in this realm. This realm felt unfamiliar.

He struggled to his feet. The wind whipped snow into his eyes as he attempted to orient himself. He made out a faint glow in the distance and began to gather his gear.

Among his usual equipment were some items that seemed out of place. The first was a box made of a smooth, white, metallic material. It seemed to be designed to collect something, but he did not know what.

def reconstitute(&block)
  Object.singleton_class.define_method(:const_missing, &block)
end

There was another item he recognized, but did not know why he had it. It could be attached to a scroll or parchment. By winding the crank on its side, a user with no magical talent could cast the spell inscribed on the parchment. It was a dangerous device that could cause great harm were it to fall into the hands of the untrained.

def eval_the_input
  input = File.read("01.txt").strip
  eval(input, nil, "01.txt")
end

His gear stowed in the pack on his back, our hero made his way towards the glow. As he approached, he found the light emanating from a glowing sign next to a large stone door embedded directly in the mountainside. The sign was some kind of esoteric sigil, a triangle with a circle on its topmost point and an extra bar along its base. It emitted red and white light.

Beneath the sigil was a button pad and a note reading, “Due to new security protocols, the password is locked in the safe below. Please see the attached document for the new combination.”

He looked down to find the document in the snow at his feet. Somehow, from all the many spheres he had traveled, he felt the knowledge come to him; this was a deception. Something about the zeroes.

module Shared
  refine Array do
    def -@
      count(0)
    end
  end
end

using Shared

He quickly realized that he could attach the white box to the dial. He fitted it into place.

module Part1
  refine Array do
    def <<(other)
      step = other[1..].to_i
      unit = other.start_with?("R") ? 1 : -1

      super (self[-1] + unit * step) % 100
    end
  end
end

Next, he took a look at the parchment. It seemed possible to attach the parchment to the crank device and the crank device to the white box. Assembling the contraption, he began to turn the crank. The combination flowed from the paper, transformed into pulsating purple energy, flowed into the box, turning the dial. After a great many turns of the crank, it jammed. The purple light faded. A number flashed in his mind, the number of times the dial had landed on zero. He punched it into the keypad, but nothing happened. The door didn’t move.

module X
  using Part1
  n = [50]
  reconstitute { |name| n << name.to_s }
  eval_the_input
  puts "Part 1: #{-n}"
end

The hero frowned. He racked his multiverse addled brain. Something was missing. A thought struck him as if thrown from another time and place. The dial had touched zero a great many more times than he had counted.

He pulled open the box to reveal its inner workings. The mechanism was complex, and he could not understand it, nevermind make the necessary adjustments

He was deep in thought, when a strange figure approached from the storm. Our hero tensed, ready to fight, but quickly realized the newcomer was unarmed.

“Hello, friend,” the figure spoke. “You might not know me yet, but I know you. Have known and will know. It seems you need my aid.”

“Who are you?” the hero asked warily.

“I am Jardo-a-Tom-el. In a realm where you called yourself Corum, I was your ally.” Jardo-a-Tom-el extended their hand, revealing something wrapped in cloth. “I have brought you a solution from another sphere.”

The hero accepted the bundle, unwrapping it. Inside was a new box, this one more worn and complex.

“This will do what I need?” the hero asked.

“Aye.” Jardo-a-Tom-el smiled.

module Part2
  refine Array do
    def <<(other)
      step = other[1..].to_i
      unit = other.start_with?("R") ? 1 : -1

      until step == 0
        super (self[-1] + unit) % 100
        step -= 1
      end
    end
  end
end

The hero fitted the new contraption into place and began cranking. The mechanism was different, but the operation was the same. After a great many turns, the crank jammed. The hero saw the number of times the dial had landed on zero flash in his mind. He turned to the keypad and punched in the number. The door rumbled and began to open.

Module.new do
  using Part2
  n = [50]
  reconstitute { |name| n << name.to_s }
  eval_the_input
  puts "Part 2: #{-n}"
end

He turned to thank Jardo-a-Tom-el, but found only footsteps disappearing into the storm. Shrugging, he stepped through the door and into the unknown.