Skip to content

Commit

Permalink
Add id0001
Browse files Browse the repository at this point in the history
  • Loading branch information
ishanpranav committed Jan 7, 2024
1 parent 276fc1e commit 7cc9952
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 0 deletions.
59 changes: 59 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
a.out
*.exe
*.o
.vscode/
File renamed without changes.
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
78 changes: 78 additions & 0 deletions cstyle.md
Original file line number Diff line number Diff line change
@@ -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.
13 changes: 13 additions & 0 deletions src/euler.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Licensed under the MIT License.

// Multiples of 3 or 5

#include <stdio.h>
#include "euler.h"

void euler_submit(int id, clock_t start)
{
printf("%04d %lf\n",
id,
(double)(clock() - start) / CLOCKS_PER_SEC);
}
3 changes: 3 additions & 0 deletions src/euler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include <time.h>

void euler_submit(int id, clock_t start);
18 changes: 18 additions & 0 deletions src/id0001.c
Original file line number Diff line number Diff line change
@@ -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;
}
4 changes: 4 additions & 0 deletions tools/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
for i in {0001..0001};
do
./../id${i}.o
done

0 comments on commit 7cc9952

Please sign in to comment.