Skip to content

Instantly share code, notes, and snippets.

View BenMaydan's full-sized avatar
🏫
College Student

BenMaydan

🏫
College Student
View GitHub Profile
@BenMaydan
BenMaydan / ListNode.java
Last active January 30, 2022 06:53
Reverse a linked list
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;
@BenMaydan
BenMaydan / LinkedList.cpp
Last active November 12, 2019 01:54
Linked list in C++
#include <iostream>
class IntNode {
public:
IntNode* next;
int val;
@BenMaydan
BenMaydan / OperationsGame.pde
Last active September 29, 2019 21:21
COMPLETED Operations game. You move around as a square and perform operations on the square next to you. Added a map that shows the squares you have not used yet (IN RED) and squares that you have used (IN GREEN)
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];
@BenMaydan
BenMaydan / FlappyBird.pde
Last active September 25, 2019 20:00
Flappy bird with processing 3 and Java
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;
@BenMaydan
BenMaydan / pointOnCircle.class
Created September 22, 2019 02:54
Java plug in "function" to determine the x and y coordinates of a point of a circle at a certain radian. The way this is written the angle 0 starts on the far right of the circle and goes clockwise.
class Circle() {
float[] pointOnCircle(int x, int y, float rad, float radians) {
return new float[] {x+(rad * cos(radians)), y+(rad * sin(radians))};
}
}
@BenMaydan
BenMaydan / increasing.py
Last active August 15, 2019 19:42
A function to check if a list (or generator/tuple/set/dict keys) is strictly increasing by some arbitrary number
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
@BenMaydan
BenMaydan / list_generator.py
Created August 6, 2019 06:25
A generator function for iterating over a list of values in python. Computes the values on the fly
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
@BenMaydan
BenMaydan / range_replica.py
Created August 6, 2019 06:16
Exact range replica. I wanted to learn about python generators so I made a range replica
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):
@BenMaydan
BenMaydan / generate_fibonacci.py
Created August 6, 2019 05:26
A new way of calculating fibonnaci numbers. This is a python generator function. Example is included
def fib(stop):
"""
A generator function for fibonnaci
:return:
"""
times = 0
prev_prev = 1
prev = 0
fib_num = 0
while times < stop:
@BenMaydan
BenMaydan / increment_string.py
Last active August 5, 2019 22:18
Increments a string. For example, aaab would return aaac, abcd would return abce, abzz would return aczz, and zzzz would return zzzz
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
"""