Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all exercises should include headers #743

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions exercises/practice/all-your-base/all_your_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@

#define DIGITS_ARRAY_SIZE 64

size_t rebase(int8_t digits[DIGITS_ARRAY_SIZE], int16_t from_base,
int16_t to_base, size_t num_digits);

#endif
3 changes: 3 additions & 0 deletions exercises/practice/allergies/allergies.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ typedef struct {
bool allergens[ALLERGEN_COUNT];
} allergen_list_t;

bool is_allergic_to(allergen_t allergen, unsigned int score);
allergen_list_t get_allergens(unsigned int score);

#endif
26 changes: 26 additions & 0 deletions exercises/practice/circular-buffer/circular_buffer.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
#ifndef CIRCULAR_BUFFER_H
#define CIRCULAR_BUFFER_H

#include <stddef.h>
#include <stdint.h>

typedef int16_t buffer_value_t;
typedef struct circular_buffer_t circular_buffer_t;

// constructs a new buffer
circular_buffer_t *new_circular_buffer(size_t capacity);

// read next value from buffer
int16_t read(circular_buffer_t *buffer, buffer_value_t *value);

// write a value to the buffer
int16_t write(circular_buffer_t *buffer, buffer_value_t value);

// write a value to the buffer
// overwrites the oldest value if the buffer is already full
int16_t overwrite(circular_buffer_t *buffer, buffer_value_t value);

// clear the buffer
void clear_buffer(circular_buffer_t *buffer);

// destroy the entire buffer
// buffer will be a dangling pointer after calling this method on it
void delete_buffer(circular_buffer_t *buffer);

#endif
8 changes: 8 additions & 0 deletions exercises/practice/darts/darts.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
#ifndef DARTS_H
#define DARTS_H

#include <stdint.h>

typedef struct {
float x, y;
} coordinate_t;

uint8_t score(coordinate_t landing_position);

#endif
2 changes: 2 additions & 0 deletions exercises/practice/perfect-numbers/perfect_numbers.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ typedef enum {
ERROR = -1
} kind;

kind classify_number(int);

#endif
16 changes: 16 additions & 0 deletions exercises/practice/pythagorean-triplet/pythagorean_triplet.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
#ifndef PYTHAGOREAN_TRIPLET_H
#define PYTHAGOREAN_TRIPLET_H

#include <stdint.h>
#include <stdlib.h>

typedef struct {
uint16_t a, b, c;
} triplet_t;

typedef struct {
size_t count;
triplet_t triplets[];
} triplets_t;

triplets_t *triplets_with_sum(uint16_t sum);

void free_triplets(triplets_t *triplets);

#endif
22 changes: 22 additions & 0 deletions exercises/practice/rational-numbers/rational_numbers.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
#ifndef RATIONAL_NUMBERS_H
#define RATIONAL_NUMBERS_H

#include <stdint.h>

typedef struct {
int16_t numerator, denominator;
} rational_t;

rational_t add(rational_t r1, rational_t r2);

rational_t subtract(rational_t r1, rational_t r2);

rational_t multiply(rational_t r1, rational_t r2);

rational_t divide(rational_t r1, rational_t r2);

rational_t absolute(rational_t r);

rational_t exp_rational(rational_t r, uint16_t n);

float exp_real(uint16_t n, rational_t r);

rational_t reduce(rational_t r);

#endif
7 changes: 7 additions & 0 deletions exercises/practice/resistor-color-duo/resistor_color_duo.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#ifndef RESISTOR_COLOR_DUO_H
#define RESISTOR_COLOR_DUO_H

#include <stdint.h>

typedef enum {
} resistor_band_t;

uint16_t color_code(resistor_band_t colors[]);

#endif
15 changes: 15 additions & 0 deletions exercises/practice/resistor-color-trio/resistor_color_trio.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
#ifndef RESISTOR_COLOR_TRIO_H
#define RESISTOR_COLOR_TRIO_H

#include <stdint.h>

typedef enum {
} resistor_band_t;

typedef enum {
} resistor_unit_t;

typedef struct {
uint16_t value;
resistor_unit_t unit;
} resistor_value_t;

resistor_value_t color_code(resistor_band_t colors[]);

#endif
7 changes: 6 additions & 1 deletion exercises/practice/resistor-color/resistor_color.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#ifndef RESISTOR_COLOR_H
#define RESISTOR_COLOR_H

typedef enum {
#include <stdint.h>

typedef enum {
} resistor_band_t;

uint16_t color_code(resistor_band_t color);

const resistor_band_t *colors(void);

#endif
17 changes: 17 additions & 0 deletions exercises/practice/saddle-points/saddle_points.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
#ifndef SADDLE_POINTS_H
#define SADDLE_POINTS_H

#include <stddef.h>
#include <stdint.h>

typedef struct {
size_t row, column;
} saddle_point_t;

typedef struct {
size_t count;
saddle_point_t points[];
} saddle_points_t;

saddle_points_t *saddle_points(size_t rows, size_t columns,
uint8_t matrix[][columns]);

void free_saddle_points(saddle_points_t *saddle_points);

#endif
4 changes: 4 additions & 0 deletions exercises/practice/square-root/square_root.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#ifndef SQUARE_ROOT_H
#define SQUARE_ROOT_H

#include <stdint.h>

uint16_t square_root(uint16_t radicand);

#endif
6 changes: 6 additions & 0 deletions exercises/practice/triangle/triangle.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
#ifndef TRIANGLE_H
#define TRIANGLE_H

#include <stdbool.h>

typedef struct {
double a;
double b;
double c;
} triangle_t;

bool is_equilateral(triangle_t sides);
bool is_isosceles(triangle_t sides);
bool is_scalene(triangle_t sides);

#endif