Skip to content

Instantly share code, notes, and snippets.

@Sreyas-Sreelal
Sreyas-Sreelal / WilsonScore.pwn
Created February 17, 2024 13:04
Lower bound of Wilson score confidence interval for a Bernoulli parameter
// https://www.evanmiller.org/how-not-to-sort-by-average-rating.html
Float:Rating_Score(tOne, tTwo, tThree, tFour, tFive, Float:brenouli_param = 0.9604)
{
new total = tOne + tTwo + tThree + tFour + tFive,
Float:positive = tTwo * 0.25 + tThree * 0.5 + tFour * 0.75 + tFive,
Float:negative = total - positive;
return Float:(((positive + 1.9208) / (positive + negative) - 1.96 * floatsqroot(((positive * negative) / (positive + negative)) + brenouli_param) / (positive + negative)) / (1 + 3.8416 / (positive + negative)));
}
main()
@Sreyas-Sreelal
Sreyas-Sreelal / removeColorCode.pwn
Last active August 19, 2023 07:03
removeColorCode
#define RUN_TESTS
#include <YSI_Core\y_testing>
removeColorCode(const str[],output[])
{
new bad, out_track = -1, back_track;
for (new i, length = strlen(str); i < length; ++i)
{
if (str[i] == '{' && i < length - 1 - 7 && str[i + 7] == '}')
@Sreyas-Sreelal
Sreyas-Sreelal / IsSequence.pwn
Created February 14, 2017 14:42
Pawn function to check if a string is sequence of another string
bool:IsSequence( main_string[ ] , sub_string[ ] , first_size = sizeof( main_string ) , second_size = sizeof( sub_string ) )
{
if( !second_size ) return true;
if( !first_size ) return false;
if( main_string[ first_size - 1 ] == sub_string[ second_size - 1 ] )
return IsSequence( main_string , sub_string , first_size - 1 , second_size - 1 );
return IsSequence( main_string , sub_string , first_size - 1 , second_size );
@Sreyas-Sreelal
Sreyas-Sreelal / Shuffle Array 2.pwn
Last active June 26, 2018 02:37
Second version of Shuffle Array
ShuffleArray( array[ ] , start = 0 , end = sizeof( array ) )//by Sreyas
{
new rand_index , i , difference,temp;
i = start,
difference = end - start + 1;
while(i < end)
rand_index = random( difference ) + start , temp = array[ i ],array[ i ] = array[ rand_index ],array[ rand_index ] = temp,++i;
}
@Sreyas-Sreelal
Sreyas-Sreelal / Shuffle Array.pwn
Last active July 11, 2021 05:51
A pawn function to shuffle arrays
ShuffleArray( array[ ] , start = 0 , end = sizeof( array ) )//by Sreyas
for( new rand_index = random( end - start + 1 ) + start, i = start; i < end; ++i , rand_index = random( end - start + 1 ) + start )
array[ i ] = array[ rand_index ] + array[ i ] - ( array[ rand_index ] = array[ i ] );
@Sreyas-Sreelal
Sreyas-Sreelal / SubDel2.pwn
Created January 19, 2017 17:19
A pawn function to delete a sub string from a string using string functions
SubDel(string[],sub_string[],bool:case_sen=false)//by Sreyas
{
if(strfind(string,sub_string, case_sen) == -1) return;
new i=strfind(string,sub_string),
j=strlen(sub_string);
while((i=strfind(string,sub_string,case_sen) )!= -1)
strdel(string, i, j+i);
@Sreyas-Sreelal
Sreyas-Sreelal / BitwiseFunctions.pwn
Created January 19, 2017 15:24
Demonstration of some practical uses of bit wise operators.
//Swapping two variables without the use of 3rd one using XOR
swap(&a,&b)
{
a ^= b;
b ^= a;
a ^= b;
}
//Checking two numbers have same signs using XOR
bool:IsSameSign(a,b)
@Sreyas-Sreelal
Sreyas-Sreelal / isValidDate.pwn
Created January 19, 2017 15:20
pawn function to check a date is valid or not with any possible format.
bool:isValidDate(str[])//by Sreyas
{
new count,i,j;
new daysinmonth[12]={31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
new parts[3][5],Index_Beg;
new bool:legit;
while(str[i]!='\0')
{
if(str[i] < 48 || str[i] > 57)
@Sreyas-Sreelal
Sreyas-Sreelal / SubDel.pwn
Created January 19, 2017 15:17
pawn function to delete a string from another
SubDel(string[],sub_string[])//by Sreyas
{
new i,
j,
beg = -1,
bool:flag;
while( string[ i ] != '\0' )
{
j = 0;
flag = true;
@Sreyas-Sreelal
Sreyas-Sreelal / Pawn alphabet sorter.pwn
Last active November 13, 2016 16:19
Sorts the strings in alphabetic order
#define strcpy(%0,%1) strcat((%0[0] = '\0', %0), %1)
/*Alphabet sorter by Sreyas*/
alpha(str[MAX_NAMES][MAX_PLAYER_NAME]) //MAX_NAME - total number of strings in that matrix
{
new i, j,t[24];
for(i=1; i<MAX_NAMES; i++)