This file contains hidden or 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
fahrenheit = "°F" | |
celcius = "°C" | |
kelvin = "K" | |
def c_to_f(celcius: float) -> float: | |
"""Celcius to fahrenheit.""" | |
return celcius * 9.0 / 5.0 + 32.0 | |
def f_to_c(fahrenheit: float) -> float: |
This file contains hidden or 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 random | |
import time | |
random.seed(int(time.time())) | |
class FarmingPatch: | |
def __init__(self, area_sqr_meter: float): | |
self.area_sqr_meter = area_sqr_meter | |
self.weeds_per_sqr_meter = random.randint(0, 3) | |
self.total_weeds = self.weeds_per_sqr_meter * self.area_sqr_meter |
This file contains hidden or 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 math | |
class Vec3: | |
def __init__(self, x: float, y: float, z: float): | |
self.x = x | |
self.y = y | |
self.z = z | |
def zero(self): |
This file contains hidden or 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
//Used for maximum efficiency, especially over a network. | |
#pragma once | |
#include <string> | |
#include <bitset> | |
namespace bit_packer { | |
void set_bit(uint8_t& bits, const bool value, const uint8_t index) { | |
bits |= (value << index); |
This file contains hidden or 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
//This code may contain bugs. | |
#include <malloc.h> | |
#include <ctype.h> | |
const size_t sizeof_char = sizeof(char); | |
const char empty_char = '\0'; | |
struct string { | |
//How many elements: |
This file contains hidden or 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
enum Bool { | |
False = 0, | |
True = 1 | |
}; | |
const char* true = "true"; | |
const char* false = "false"; | |
char* get_bool_str(enum Bool my_bool) { | |
return (my_bool == True) ? true : false; |
This file contains hidden or 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
struct binary_node { | |
int value; | |
struct node* left; | |
struct node* right; | |
}; | |
struct binary_node_char { | |
char value; | |
struct node* left; | |
struct node* right; |
This file contains hidden or 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
//true and false. | |
#include <stdbool.h> | |
//isalnum(). | |
#include <ctype.h> | |
int is_file_extension(const char* string) { | |
if (string[0] != '.') { | |
return false; | |
} |
This file contains hidden or 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
// this computes 1 / sqrt(number) using iterations of precision | |
//Attributed to Doom (the video game). | |
float Q_rsqrt( float number, int iterations ) | |
{ | |
long i; | |
float x2, y; | |
const float threehalfs = 1.5F; | |
x2 = number * 0.5F; | |
y = number; |
This file contains hidden or 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 math | |
def dirac_delta(x: float, variance: float=0.001) -> float: | |
return (1.0 / (abs(variance) * math.sqrt(math.pi))) * math.exp(-(x / b)**2) |
NewerOlder