diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..3f542a3 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,59 @@ +[*] +cpp_indent_braces=false +cpp_indent_multi_line_relative_to=innermost_parenthesis +cpp_indent_within_parentheses=indent +cpp_indent_preserve_within_parentheses=false +cpp_indent_case_labels=true +cpp_indent_case_contents=true +cpp_indent_case_contents_when_block=false +cpp_indent_lambda_braces_when_parameter=true +cpp_indent_goto_labels=one_left +cpp_indent_preprocessor=leftmost_column +cpp_indent_access_specifiers=false +cpp_indent_namespace_contents=true +cpp_indent_preserve_comments=false +cpp_new_line_before_open_brace_namespace=ignore +cpp_new_line_before_open_brace_type=ignore +cpp_new_line_before_open_brace_function=ignore +cpp_new_line_before_open_brace_block=ignore +cpp_new_line_before_open_brace_lambda=ignore +cpp_new_line_scope_braces_on_separate_lines=false +cpp_new_line_close_brace_same_line_empty_type=false +cpp_new_line_close_brace_same_line_empty_function=true +cpp_new_line_before_catch=true +cpp_new_line_before_else=true +cpp_new_line_before_while_in_do_while=true +cpp_space_before_function_open_parenthesis=remove +cpp_space_within_parameter_list_parentheses=false +cpp_space_between_empty_parameter_list_parentheses=false +cpp_space_after_keywords_in_control_flow_statements=true +cpp_space_within_control_flow_statement_parentheses=false +cpp_space_before_lambda_open_parenthesis=false +cpp_space_within_cast_parentheses=false +cpp_space_after_cast_close_parenthesis=false +cpp_space_within_expression_parentheses=false +cpp_space_before_block_open_brace=true +cpp_space_between_empty_braces=false +cpp_space_before_initializer_list_open_brace=true +cpp_space_within_initializer_list_braces=true +cpp_space_preserve_in_initializer_list=true +cpp_space_before_open_square_bracket=false +cpp_space_within_square_brackets=false +cpp_space_before_empty_square_brackets=false +cpp_space_between_empty_square_brackets=false +cpp_space_group_square_brackets=true +cpp_space_within_lambda_brackets=false +cpp_space_between_empty_lambda_brackets=false +cpp_space_before_comma=false +cpp_space_after_comma=true +cpp_space_remove_around_member_operators=true +cpp_space_before_inheritance_colon=true +cpp_space_before_constructor_colon=true +cpp_space_remove_before_semicolon=true +cpp_space_after_semicolon=false +cpp_space_remove_around_unary_operator=true +cpp_space_around_binary_operator=insert +cpp_space_around_assignment_operator=insert +cpp_space_pointer_reference_alignment=left +cpp_space_around_ternary_operator=insert +cpp_wrap_preserve_blocks=one_liners \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..53c9109 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +a.out +*.exe +*.o +.vscode/ \ No newline at end of file diff --git a/LICENSE b/LICENSE.txt similarity index 100% rename from LICENSE rename to LICENSE.txt diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a50b902 --- /dev/null +++ b/Makefile @@ -0,0 +1,16 @@ +CC = gcc +CFLAGS = -O3 -pedantic -std=c99 -Wall -Wextra +LIBM = -lm +TWOS_COMPLEMENT = -fno-strict-overflow -fwrapv + +all: \ + id0001 + +euler: src/euler.h src/euler.c + $(CC) $(CFLAGS) -c src/euler.c -o $@.o + +id0001: src/id0001.c euler + $(CC) $(CFLAGS) $< -o $@.o euler.o + +clean: + rm -rf *.o diff --git a/cstyle.md b/cstyle.md new file mode 100644 index 0000000..2387515 --- /dev/null +++ b/cstyle.md @@ -0,0 +1,78 @@ +# C language style guide + +## Indentation + +- Use spaces instead of tabs. +- The indentation size is four spaces. +- Indent `case` labels. +- Do not put multiple statements on a single line. +- Do not put multiple assignments on a single line. +- Do not leave whitespace at the end of lines. + +## Wrapping + +- The line limit is 80 characters. +- Split long strings to meet the character limit. + +## Bracing + +- Every brace (`{`) or brace-semicolon pair (`};`) should have its own line, + except during empty initialization or during array initialization when all array + items are placed on a single line. +- Always use braces with control structures, even when optional. +- Separate functions and control structures by exactly one blank line. + +## Spacing + +Defer to the Linux Kernel Coding Style +[Section 3.1: Spacing](https://www.kernel.org/doc/html/v4.10/process/coding-style.html) +for spacing considerations. + +## Naming + +- Use `UPPER_SNAKE_CASE` for global constants, constant macros, and enumeration + members. +- Use `PascalCase` for struct names, enumeration names, and type definitions. +- Use `lower_snake_case` for global functions. +- Use `lowercase` for static functions. +- Use `camelCase` for local variables, struct fields, and function arguments. + +Always use descriptive names. Abbreviated names are forbidden except in the +following approved use cases. If a value is arbitrary, use the corresponding +abbreviation based on its type. If several values are abitrary, begin with the +corresponding type-based abbreviation and continue alphabetically. If doing so +is impractical, use numeric suffixes instead. + +| Letter | Appropriate use | +| :----: | :------------------------------------------------------------------------------------------- | +| `a` | arbitrary object, area | +| `b` | blue color component, boundary points in Pick\'s Theorem | +| `e` | arbitrary edge | +| `dx` | change in an arbitrary dimension | +| `g` | green color component, arbitrary graph | +| `hi` | larger pointer, point above, upper buffer | +| `i` | abitrary counter, matrix index in an arbitrary dimension, interior points in Pick\'s Theorem | +| `k` | term number, arbitrary constant | +| `l` | arbitrary line | +| `lo` | smaller pointer, point below, lower buffer | +| `m` | matrix size in an arbitrary dimension | +| `max` | inclusive maximum, exclusive interval upper bound | +| `mid` | middle pointer, middle buffer | +| `min` | inclusive minimum, inclusive interval lower bound | +| `n` | count, arbitrary integer | +| `p` | arbitrary pointer, arbitrary point | +| `q` | arbitrary rational number | +| `r` | red color component, arbitrary real number | +| `u` | arbitrary vertex | +| `x` | vector in an arbitrary dimension, position in an arbitrary dimension | + +## Type definitions + +- Always use type definitions for enumeration types. +- Always use type definitions to obscure pointers to structs. + +### Macros + +- Only use macros to define constants. +- When multiple related integer constants are defined, use an enumeration + instead. \ No newline at end of file diff --git a/src/euler.c b/src/euler.c new file mode 100644 index 0000000..a3f80c9 --- /dev/null +++ b/src/euler.c @@ -0,0 +1,13 @@ +// Licensed under the MIT License. + +// Multiples of 3 or 5 + +#include +#include "euler.h" + +void euler_submit(int id, clock_t start) +{ + printf("%04d %lf\n", + id, + (double)(clock() - start) / CLOCKS_PER_SEC); +} diff --git a/src/euler.h b/src/euler.h new file mode 100644 index 0000000..1e4db59 --- /dev/null +++ b/src/euler.h @@ -0,0 +1,3 @@ +#include + +void euler_submit(int id, clock_t start); diff --git a/src/id0001.c b/src/id0001.c new file mode 100644 index 0000000..65fc0a9 --- /dev/null +++ b/src/id0001.c @@ -0,0 +1,18 @@ +#include "euler.h" + +int math_gaussian_sum(int n) +{ + return n * (n + 1) / 2; +} + +int main(void) +{ + clock_t start = clock(); + int sum = (3 * math_gaussian_sum(999 / 3)) + + (5 * math_gaussian_sum(999 / 5)) - + (15 * math_gaussian_sum(999 / 15)); + + euler_submit(sum, start); + + return 0; +} diff --git a/tools/test.sh b/tools/test.sh new file mode 100644 index 0000000..fcfeda1 --- /dev/null +++ b/tools/test.sh @@ -0,0 +1,4 @@ +for i in {0001..0001}; +do + ./../id${i}.o +done