Skip to content

Instantly share code, notes, and snippets.

View redrifle's full-sized avatar

Red redrifle

View GitHub Profile
@redrifle
redrifle / heron.c
Created April 21, 2026 22:27
Heron's method for finding square roots by successive averaging
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
double avg(double a, double b)
{
return (a + b) / 2;
}
int main(int argc, char **argv)
@redrifle
redrifle / stonks_convert.c
Created September 29, 2022 03:12
PicoCTF - Stonks
/* Convert little-endian hexadecimal string to big-endian ASCII */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char** argv)
{
if (argc < 2)
return EXIT_FAILURE;
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>
static const char *input = "\
08 02 22 97 38 15 00 41 00 75 04 05 07 78 52 12 50 77 91 08 \
49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00 \
81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65 \
52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91 \
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
/* gcc fizzbuzz.c -nostartfiles -O3 -std=c11 -march=native */
_Noreturn void _start()
{
for (register uint_fast8_t i = 1; i <= 100; ++i)
printf("%" PRIuFAST8 " %s", i, (i % 15 == 0 ? "FizzBuzz\n" : (i % 5 == 0 ? "Buzz\n" : (i % 3 == 0 ? "Fizz\n" : "\n"))));
@redrifle
redrifle / euclid.c
Created September 7, 2015 03:49
GCD finder using euclidean algorithm
#include <stdio.h>
#include <stdlib.h>
int do_algo(int a, int b, int r)
{
while(1)
{
printf("%d\t%d\t%d\t\n", a, b, r);
if (r == 0)
return b;