One Paragraph of project description goes here
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
def bubble_sort(l: list): | |
arr = l[::] | |
is_sorted = True | |
end = len(arr) | |
while is_sorted: | |
is_sorted = False | |
for i in range(1, end): | |
if arr[i] < arr[i-1]: | |
arr[i], arr[i-1] = arr[i-1], arr[i] | |
is_sorted = True |
node *find_loop(node *head) | |
{ | |
node *p1; | |
node *p2; | |
if (head == NULL) | |
return (NULL); | |
p1 = head; | |
p2 = head; | |
while (p2->next != NULL && p2->next->next != NULL) |
#!/bin/bash | |
# Generate a Markdown change log of pull requests from commits between two tags | |
# Author: Russell Heimlich | |
# URL: https://gist.github.com/kingkool68/09a201a35c83e43af08fcbacee5c315a | |
# HOW TO USE | |
# Copy this script to a directory under Git version control | |
# Make the script executable i.e. chmod +x changelog.sh | |
# Run it! ./changelog.sh | |
# Check CHANGELOG.md to see your results |
def merge_sort(arr): | |
"""Sorts a list using recursion and helper merge function.""" | |
if len(arr) < 2: | |
return arr | |
mid = int(math.floor(len(arr) / 2)) | |
left = arr[0:mid] | |
right = arr[mid:len(arr)] | |
return merge(merge_sort(left), merge_sort(right)) |
def merge(list1, list2): | |
"""Merges two sorted lists.""" | |
left = 0 | |
right = 0 | |
res = [] | |
while left < len(list1) and right < len(list2): | |
if list1[left] <= list2[right]: | |
res.append(list1[left]) | |
left += 1 | |
else: |
const eratosthenes = n => { | |
const output = [] | |
const upperLimit = Math.sqrt(n) | |
// new array with n values of true i.e. [true, true, true...] | |
const array = Array(n).fill(true) | |
// loop from 2 to square root of n | |
for (let i = 2; i <= upperLimit; i++) { | |
// if i has been marked false, skip | |
if (array[i]) { |
const example = [1,2,5,7,9,11,13,17,19] | |
const example2 = [-2,5,8,14,1,5,-9,-10,2] | |
// imperative programming | |
avg = function(arr) { | |
let sum = 0 | |
// iterate through array | |
for (let i = 0; i < arr.length; i++) { | |
// add each number to var sum | |
sum += (arr[i]) |
const isEven = x=> { | |
switch (x) { | |
// base cases | |
case 0: return true; | |
case 1: return false | |
// subtracts 2 off of x until it hits 0 or 1 | |
default: return isEven(x - 2) | |
} | |
} |
const addWithRecursion = x => { | |
// base case | |
return x <= 0 | |
// ends function when x hits 0 | |
? 0 | |
// checks if x divides evenly by 2 | |
: x % 2 === 0 | |
// retains x and adds it to the function call of x - 1 | |
? x + addWithRecursion(x - 1) | |
// ignores x and moves on to the function call of x - 1 |