Skip to content

Instantly share code, notes, and snippets.

@b4284
Created August 1, 2017 14:52
Show Gist options
  • Select an option

  • Save b4284/7a443bd1abea8cbeadb4414bfb2f5fa0 to your computer and use it in GitHub Desktop.

Select an option

Save b4284/7a443bd1abea8cbeadb4414bfb2f5fa0 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdint.h>
static inline void print_nums(const uint8_t *u8)
{
for (int i = 0; i < 5; ++i) {
printf(" %d", u8[i]);
}
putchar('\n');
}
void move_zeroes_last(uint8_t *u8) {
int iters = 0;
for (int i = 0; i < 5; ++i) {
if (u8[i] == 0) {
for (int q = i + 1; q < 5; ++q) {
iters += 1;
if (u8[q] != 0) {
int s = u8[q];
u8[q] = u8[i];
u8[i] = s;
break;
}
}
}
}
printf("Iterations: %d\n", iters);
}
int fib(int n) {
if (n <= 2) {
return 1;
}
return fib(n - 1) + fib(n - 2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment