This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE posts | |
( | |
id bigserial PRIMARY KEY, | |
content text NOT NULL, | |
reply_to_id bigint REFERENCES posts (id) | |
); | |
TRUNCATE posts RESTART IDENTITY; -- this deletes all rows and restarts the auto-increment ID | |
/* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# generate a स्वस्तिक (swastika) of arm size n | |
# for n = 3 | |
# * * * * * | |
# * * | |
# * * | |
# * * * * * * * | |
# * * | |
# * * | |
# * * * * * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
def shave_digits(l, r) | |
l_chars = l.to_s.chars | |
r_chars = r.to_s.chars | |
return false unless l_chars.length > r_chars.length | |
l_chars[0..(l_chars.length - r_chars.length - 1)].join.to_i | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
def print_input(input, antinodes) | |
input.each_with_index do |row, i| | |
row.each_with_index do |cell, j| | |
if !(cell =~ /[a-z0-9]/i) && antinodes[[i, j]] | |
print "#" | |
else | |
print cell | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
def neighbours(input, i, j) | |
# @formatter:off | |
@deltas ||= [ | |
[-1, 0], | |
[0, -1], [0, 1], | |
[1, 0], | |
] | |
# @formatter:on |
OlderNewer