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
public class ListNode { | |
int val; | |
ListNode next; | |
ListNode() {} | |
ListNode(int val) { | |
this.val = val; | |
} | |
ListNode(int val, ListNode next) { | |
this.val = val; | |
this.next = next; |
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
#include <iostream> | |
class IntNode { | |
public: | |
IntNode* next; | |
int val; |
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 java.awt.Point; | |
// Array functions | |
Square[][] transpose(Square[][] arr) { | |
Square[][] nArr = new Square[arr[0].length][arr.length]; | |
int i, j; | |
for (i = 0; i < squares[0].length; i++) | |
for (j = 0; j < squares.length; j++) | |
nArr[i][j] = arr[j][i]; |
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
class World { | |
public ArrayList<float[]> clouds = new ArrayList<float[]>(); | |
public void drawClouds() { for (float[] c : this.clouds) { fill(255); ellipse(c[0], c[1], c[2], c[3]); noFill(); } } | |
public void createCloud(float w, float h) { this.clouds.add(new float[] {random(this.clouds.get(this.clouds.size()-1)[0] + w, width), random(height/5), w, h}); } | |
public void createClouds(int times, float w, float h) { for (int ii = 0; ii < times; ii += 1) { this.clouds.add(new float[] {random(width), random(height/5), w, h}); } } | |
} | |
class Bird { | |
private int x, y, dy; |
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
class Circle() { | |
float[] pointOnCircle(int x, int y, float rad, float radians) { | |
return new float[] {x+(rad * cos(radians)), y+(rad * sin(radians))}; | |
} | |
} |
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 increasing(values, amount): | |
""" | |
Checks if every value in a list of values increases by some arbitrary amount | |
:param values: The list of values | |
:param amount: The amount the values in the list should increase by | |
:return: True or False | |
""" | |
for current, future in zip(values, values[1:]): | |
if current != future - amount: | |
return False |
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 generator(array): | |
""" | |
Takes a list of values and generates the current value on the fly | |
:param array: A list of values | |
:return: The current value | |
""" | |
idx = 0 | |
while idx < len(array): | |
yield array[idx] | |
idx += 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
def new_range(start, stop, step=1): | |
""" | |
A copy of the normal python range generator | |
:param start: The number to start at | |
:param stop: The number to stop at (function stops at stop - step) | |
:param step: start + step until stop - step is reached | |
:return: Current number | |
""" | |
# If the resulting logic is an infinitely long generator (start can never reach stop - step) | |
if (start < stop and step < 0) or (start > stop and step > 0): |
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 fib(stop): | |
""" | |
A generator function for fibonnaci | |
:return: | |
""" | |
times = 0 | |
prev_prev = 1 | |
prev = 0 | |
fib_num = 0 | |
while times < stop: |
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 string import ascii_lowercase | |
def increment(string): | |
""" | |
Increments a string alphabetically | |
increment("aabc") would return "aabd" | |
:param text: Just some plain english text | |
:return: Incremented string | |
""" |
NewerOlder