Skip to content

Instantly share code, notes, and snippets.

View kaashmonee's full-sized avatar

Skanda Kaashyap kaashmonee

View GitHub Profile
@kaashmonee
kaashmonee / gearing-up-for-destruction.py
Created July 11, 2017 06:19
Google foobar challenge -- gearing up for destruction recursive implementation
from fractions import Fraction
def answer(pegs):
def find_rn(num):
if num == 1:
return 0
else:
return pegs[num-1]-pegs[num-2]-find_rn(num-1)
ans = find_rn(len(pegs))
if len(pegs)%2 == 0: #if it's even
@kaashmonee
kaashmonee / binary-carry-count.py
Created October 16, 2017 04:10
Counts the number of times you have to carry when you add 1 to a binary number.
def countCarries(number):
number+=1
number = str(number)
number = list(number)
carries = 0
for x in range(len(number)-1, -1, -1):
if int(number[x])==2:
carries+=1
if number[x-1]:
#checks to see if n is prime in one line
def oneLineIsPrime(n): return False if (n % 2 == 0 and n > 2) or n < 2 or 0 in [n%factor for factor in range(3, round(n ** 0.5))] else True
@kaashmonee
kaashmonee / helloworld.rb
Created November 14, 2017 07:58
Hello world ruby
$i = 100
$n = 3
while $n < $i do
puts("inside the loop i = #$n")
$n += 1
end
@kaashmonee
kaashmonee / 3body.py
Last active May 4, 2020 22:22
3 body problem simulation in Python
from visual import *
scene = display(title="Earth's Orbit", width=500, height=500, range=3.e11)
#
scene.autoscale = 0 # Turn off auto scaling of display.
#
# Define the Sun and the Earth objects.
#
sun = sphere(color=color.yellow)
@kaashmonee
kaashmonee / codecopy.py
Created December 17, 2017 20:24
Copies and shortens code from one file to another
import argparse
def cp(inp, out):
with open(out, "w") as output, open(inp, "r") as inp:
lines = []
for line in inp:
# ignores new lines
if line == "\n":
@kaashmonee
kaashmonee / leafofthetreepicoCTF.py
Created December 23, 2017 07:00
Solution to Leaf of the Tree challenge in PicoCTF. Traverses all directories in path and retrieves flag file.
# picoCTF leaf of the tree
import os
path = "/problems/5da315e9c7f1c9886ea371abee5ae8d0"
def getPath(path):
if not os.path.isdir(path):
return path
else:
for dir in listdir_fullpath(path):
@kaashmonee
kaashmonee / gcd.py
Created April 12, 2018 04:18
finding gcd with the euclidean algorithm
def gcd(a, b):
if (a == 1 or b == 1):
return 1
elif (a == 0): return b
elif (b == 0): return a
else:
# print(a, b)
return gcd(b, a % b)
@kaashmonee
kaashmonee / create_user.sh
Created September 19, 2018 01:00
Creates a user on a linux system using the first command line arg, sets a temporary password, and adds them to the root and Docker groups.
#!/bin/bash
# Ensure that script is being run as root.
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root!"
exit 1
fi
# Getting username from cmd line