Something went wrong. Try again.
Code for the Advent of Code event
aoc advent-of-code
Something went wrong. Try again.
401 B · 13 lines
Ruby
at rust
1234567891011121314# frozen_string_literal: true
# Function courtesy of http://stackoverflow.com/a/3852809def invert(arr, values) counts = values.each_with_object(Hash.new(0)) { |v, h| h[v] += 1 } arr.reject { |e| counts[e] -= 1 unless counts[e].zero? }end
def count_triangles(list) list.reduce(0) do |a, e| a + (e.permutation(2).all? { |perm| perm.inject(&:+) > invert(e, perm).first } ? 1 : 0) endend