Skip to content

Instantly share code, notes, and snippets.

View rwhittaker's full-sized avatar

Ryan rwhittaker

View GitHub Profile
@rwhittaker
rwhittaker / DNAPairing.js
Created April 22, 2021 16:12
DNA Pairing
function pairElement(str) {
var unpaired = str.split('');
var newArr = [];
function createPair(element){
switch(element) {
case 'T':
return(['T','A'])
break;
case 'A':
<style>
body {
min-height: 150vh;
}
#navbar {
position: fixed;
top: 0;
left: 0;
width: 100%;
@rwhittaker
rwhittaker / palindromes.js
Created April 19, 2018 15:15
Check for Palindromes - FreeCodeCamp
function palindrome(str) {
// Strip non-alphanumeric and convert to lowercase
var string = str.replace(/[^0-9a-z]/gi, '').toLowerCase().split("");
// Iterate over half the number of chars in the string
for(var i= 0; i < (string.length)/2; i++){
// Check i'th character from beginning and i'th character from end, accounting for 0.
if(string[i] !== string[string.length-i-1]){
@rwhittaker
rwhittaker / binarysearch.py
Created January 18, 2018 14:37
Exercise 20 - Binary Search Function - www.practicepython.org
# Exercise 20 - Element Search from www.pythonpractice.org
# Implement a binary search function.
ordered_list = [1, 2, 5, 7, 9, 11, 15, 19, 20, 21, 40, 50]
def binarysearch(ordered_list,low,high,x):
if high >= low:
mid = int(low + (high - low) / 2)
if ordered_list[mid] == x:
print("Found!")
# Make a one-player Rock-Paper-Scissors game.
# TODO: Abstract out Win, Lose, Draw conditions
import random
print("Lets play rock paper or scissors. It will be thrilling.\n")
options = ["R","P","S"]
# Choose random from options for computer's guess
a = random.randint(0,2)
# Given a list saved in a variable, write one line of Python that takes the list
# and makes a new list that has only the even elements of this list in it.
a = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
# Place x'th value from a if that value has no remainder when / 2 (mod 2 = 0)
b = [x for x in a if x % 2 == 0]
# Ask the user for a string and print whether it is a palindrome or not
# Get string
# If the letters starting from the beginning of string are the same as from the end
# Print string, say it's a palindrome
# If the string is not a palindrome
# Print string, say it's not a palindrome
string = input("Enter a word: ")
if string[:] == string [::-1]:
# 1. Feed in two lists of different sizes - OK
# 2. Return a list populated by common elements of the two lists - OK
# 3a. Randomly generate two lists to test this
# 3b. Write this is one line of Python
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
c = []
for i in a:
if i in b:
# 1. Take a number DONE
# 2. Print out a list of all the divisors of that number
# For i in range that is less than _num_
# If number % i is 0
# append to x
# Print the list
num = int(input("Enter num: "))
x = []
@rwhittaker
rwhittaker / gist:d94951fd65a8a62a50dab998658e3d2e
Created January 16, 2018 17:42
Exercise 3 - List Less Than Ten
# Take a list, say for example this one:
# a = [1, 1, 2, 3, 5, 6, 13, 21, 34, 55, 89]
# and write a program that prints out all the elements of the list that are less than 5
# Extras:
# 1. Instead of printing the elements one by one make a new list that has all the elements less than 5
# from this list in it and print out this new list.
# 2. Write this one line of Python.
# 3. Ask the user for a number and return a list that contains only elements from the original list a
# that are smaller than that number given by the user.