This file contains 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
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 |
This file contains 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
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]: |
This file contains 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
#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 |
This file contains 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
$i = 100 | |
$n = 3 | |
while $n < $i do | |
puts("inside the loop i = #$n") | |
$n += 1 | |
end | |
This file contains 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
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) |
This file contains 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
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": |
This file contains 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
# 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): |
This file contains 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
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) | |
This file contains 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
#!/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 |