Skip to content

Instantly share code, notes, and snippets.

View shreyshahi's full-sized avatar

Shrey Kumar Shahi shreyshahi

View GitHub Profile
def number_difference(num):
# Convert number to string and pad with zeros if needed
num_str = str(num).zfill(4)
# Convert to list of digits and sort
digits = list(num_str)
# Create ascending and descending numbers
ascending = int(''.join(sorted(digits)))
descending = int(''.join(sorted(digits, reverse=True)))
@shreyshahi
shreyshahi / gist:2dd29a77271e20a0dc265b45d50e0610
Created January 21, 2025 17:39
What is a shape that has same number of sides as number of letters in its name?
Okay, so I need to figure out a shape where the number of sides is equal to the number of letters in its name. Let me start by thinking about some basic shapes and their names.
First, a triangle. Triangle has three sides, and the word "triangle" has eight letters. Hmm, that's way more letters than sides. Not a match.
Next, a square. A square has four sides, and the word "square" has six letters. Still not the same.
How about a pentagon? Five sides, and "pentagon" is eight letters. Nope. Hexagon? Six sides, seven letters. Getting closer, but still not equal.
Wait, maybe I should check simpler shapes. Let's go back. A "circle" is a shape, but it doesn't have sides. So that's out. What about a "line"? A line doesn't really have sides either. Maybe polygons only?
@shreyshahi
shreyshahi / make_cat_dreams_playground.py
Last active March 5, 2024 00:28
Simple code to make stable playground v2.5 dream about cats
# Code inspired from https://gist.github.com/karpathy/00103b0037c5aaea32fe1da1af553355
# slerp function is entirely lifted from the above gist.
import torch
from diffusers import DiffusionPipeline
import numpy as np
def slerp(t, v0, v1, DOT_THRESHOLD=0.9995):
""" helper function to spherically interpolate two arrays v1 v2 """
inputs_are_torch = False
@shreyshahi
shreyshahi / make_cat_dreams.py
Created March 3, 2024 18:04
Simple code to make stable diffusion dream about cats
# Code inspired from https://gist.github.com/karpathy/00103b0037c5aaea32fe1da1af553355
# slerp function is entirely lifted from the above gist.
import torch
from diffusers import DiffusionPipeline
import numpy as np
def interpolate(v1, v2, step, total_steps):
alpha = step / (total_steps - 1)