Skip to content

Instantly share code, notes, and snippets.

@sarahzrf
Created December 13, 2021 18:13
Show Gist options
  • Save sarahzrf/2829c1a5252482f17a0070767362d602 to your computer and use it in GitHub Desktop.
Save sarahzrf/2829c1a5252482f17a0070767362d602 to your computer and use it in GitHub Desktop.
require 'set'
def fold(line, val)
if val < line
val
elsif val > line
line - (val - line)
else
raise "dot on line!"
end
end
dots = Set.new
while gets =~ /(\d+),(\d+)/
dots << [$1.to_i, $2.to_i]
end
gets =~ /fold along ([xy])=(\d+)/
line = $2.to_i
case $1
when 'x'
dots.map! {|x, y| [fold(line, x), y]}
when 'y'
dots.map! {|x, y| [x, fold(line, y)]}
end
print dots.count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment