Other "Armstrong Numbers" solutions.
#include "armstrong_numbers.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
int char_to_int(char c)
{
return c - '0';
}
int is_armstrong_number(int candidate)
{
char s[16] = {'\0'};
sprintf(s, "%d", candidate);
int len = strlen(s);
int sum = 0;
for (int i = 0; i < len; i++)
sum += pow(char_to_int(s[i]), len);
return candidate == sum;
}
Other "Darts" solutions.
#include "darts.h"
#include <math.h>
uint8_t score(coordinate_t coord)
{
float hyp = sqrt(pow(coord.x, 2) + pow(coord.y, 2));
int score = 0;
if (hyp <= 1.0F)
{
score = 10;
}
else if (hyp <= 5.0F)
{
score = 5;
}
else if (hyp <= 10.0F)
{
score = 1;
}
return score;
}
Other "Hello World" solutions.
#include "hello_world.h"
const char *hello(void)
{
return "Hello, World!";
}
Other "Linked List" solutions.
#include "linked_list.h"
typedef struct list_item
{
struct list_item *next;
struct list_item *previous;
ll_data_t data;
} list_item_t;
list_item_t **new_list()
{
list_item_t *list =
&(list_item_t){.next = 0, .previous = 0, .data = 0};
return list;
}
bool is_list_empty(struct list_item **list)
{
return !(list && *list);
}
Other "Resistor Color" solutions.
#include "resistor_color.h"
resistor_band_t *colors()
{
static resistor_band_t band[resistor_band_length];
for (resistor_band_t c = 0; c < resistor_band_length; c += 1)
band[(int)c] = c;
return band;
}
int color_code(resistor_band_t c)
{
return (int)c;
}
Other "Resistor Color Duo" solutions.
#include "resistor_color_duo.h"
#include <stdio.h>
#define MAX_DIGITS 2;
int color_code(resistor_band_t colors[])
{
return colors[0] * 10 + colors[1];
}
Other "Resistor Color Trio" solutions.
#include "resistor_color_trio.h"