Skip to content

Instantly share code, notes, and snippets.

View swanandp's full-sized avatar
🖥️

Swanand Pagnis swanandp

🖥️
View GitHub Profile
@swanandp
swanandp / 1_recurstive_cte.sql
Last active November 29, 2023 17:23
A demonstration of recursive query in SQL
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
/*
@swanandp
swanandp / swastika.py
Created March 27, 2024 06:56
Python code to generate the Hindu symbol Swastika of any given size
# generate a स्वस्तिक (swastika) of arm size n
# for n = 3
# * * * * *
# * *
# * *
# * * * * * * *
# * *
# * *
# * * * * *
@swanandp
swanandp / aoc_2024_day7.rb
Created December 7, 2024 13:33
Simple recursive solution to Advent of Code 2024 Day 7
# 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
@swanandp
swanandp / aoc2024_day08.rb
Last active December 8, 2024 19:41
AOC 2024 Day 8 Part 1 & 2
# 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
@swanandp
swanandp / aoc_2024_day10.rb
Created December 10, 2024 14:22
AOC 2024 Day 10, easy count paths/count destinations
# frozen_string_literal: true
def neighbours(input, i, j)
# @formatter:off
@deltas ||= [
[-1, 0],
[0, -1], [0, 1],
[1, 0],
]
# @formatter:on