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
stock float simpsons_func(float x) { | |
return 0.0; /// replace with math operations desired. | |
} | |
/** | |
* Composite Simpson's Rule: approximates the area of a function. | |
* 'a' represents the lower bounds | |
* 'b' represents the upper bounds | |
* 'num_intervals' is for how many iterations needed (this is for increasing accuracy) | |
*/ |
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
long double adaptive_simpsons(long double (*f)(long double), long double a, long double b, long double epsilon) { | |
long double c = (a + b) / 2.0L; | |
long double h = b - a; | |
long double fa = f(a); | |
long double fb = f(b); | |
long double fc = f(c); | |
long double integral = (h / 6.0L) * (fa + 4.0L * fc + fb); | |
long double d = (a + c) / 2.0L; | |
long double e = (c + b) / 2.0L; |
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
/// for int32. | |
/// a * (1/b) == (a * [(2^16 / b) + 1]) >> 16 | |
#include <stdio.h> | |
int make_recip(int const b) { | |
return ((1 << 16) / b) + 1; | |
} | |
int fast_div(int const a, int const recip) { |
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
#include <stdio.h> | |
#include <limits.h> | |
#include <time.h> | |
#include <math.h> | |
ssize_t ipow(ssize_t const x, size_t n) { | |
ssize_t r = 1; | |
while( n > 0 ) { | |
if( n & 1 ) { | |
r *= x; |
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
#include <inttypes.h> | |
#include <stdio.h> | |
static inline uint8_t bitwise_ceil8(uint8_t x) { | |
x |= x >> 1; | |
x |= x >> 2; | |
x |= x >> 4; | |
return x; | |
} |
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
def int_to_aii_numeral(num): | |
# greedy approach similar to https://leetcode.com/problems/integer-to-roman/description/ | |
# time O(1) | |
# space O(1) | |
# based on the numerals here: https://en.wiktionary.org/wiki/Module:number_list/data/aii | |
numerals = [ | |
(1000, 'ܐ݇'), | |
(900, 'ܨ̈'), (800, 'ܦ̈'), (700, 'ܥ̈'), (600, 'ܣ̈'), (500, 'ܢ̈'), (400, 'ܬ'), | |
(300, 'ܫ'), (200, 'ܪ'), (100, 'ܩ'), (90, 'ܨ'), (80, 'ܦ'), (70, 'ܥ'), (60, 'ܣ'), |
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
#if defined _utf8_included | |
#endinput | |
#endif | |
#define _utf8_included | |
#include <sourcemod> | |
stock int GetUTF8Len(int c) { | |
for( int i=7; i < 8; i-- ) { |
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{ TREE_DATA = 3 }; | |
enum{ TREE_SIZE = 2 << TREE_DATA }; | |
/// 0 is root node | |
/// odd numbers above 0 are left nodes. | |
/// even numbers above 0 are right nodes. | |
enum struct ArrayTree { | |
int data[TREE_SIZE]; | |
/// -1 0 1 | |
int IndexType(int i) { |
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
#if defined _int_log_included | |
#endinput | |
#endif | |
#define _int_log_included | |
#include <sourcemod> | |
stock int BitScanReverse(int n) { | |
int bit_index = 0; |
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
#include <sourcemod> | |
#pragma semicolon 1 | |
#pragma newdecls required | |
stock int any_hash(any a, int seed=0) { | |
int h = seed; | |
h = ( i & 0xFF) + (h << 6) + (h << 16) - h; | |
h = ((i >>> 8) & 0xFF) + (h << 6) + (h << 16) - h; | |
h = ((i >>> 16) & 0xFF) + (h << 6) + (h << 16) - h; |