Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f3ac8e1

Browse filesBrowse files
committed
day03
1 parent 930d9a7 commit f3ac8e1
Copy full SHA for f3ac8e1

File tree

Expand file treeCollapse file tree

5 files changed

+261
-2
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+261
-2
lines changed

‎2021/day03/main.rb

Copy file name to clipboard
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/usr/bin/env ruby
22
arr = File.readlines('data.txt')
33

4-
row = Array.new((arr.first.length - 1) , 0)
4+
row = Array.new((arr.first.length - 1), 0)
55

66
arr.each do |line|
77
puts [row, line.strip.each_char.map(&:to_i)].inspect
88
row = [row, line.strip.each_char.map(&:to_i)].transpose.map(&:sum)
99
end
10-
puts row.map { |v| v > arr.count / 2.0 ? 1 : 0 }.join.to_i(2) * row.map { |v| v > arr.count / 2.0 ? 0 : 1 }.join.to_i(2)
10+
puts row.map { |v| v > arr.count / 2.0 ? 1 : 0 }.join.to_i(2) * row.map { |v| v > arr.count / 2.0 ? 0 : 1 }.join.to_i(2)

‎2023/day03/.ruby-version

Copy file name to clipboard
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.1.0

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.