Skip to content

Competitive programming solutions in C language: Project Euler, LeetCode

License

Notifications You must be signed in to change notification settings

ishanpranav/codebook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Codebook

This is my C-language "book of code" for competitive programming problems. Thanks to the depth and breadth of competitive programming problems, this repository has become home to a diverse library including mathematical functions, data structures, and algorithms.

Why C?

C is a wonderful language because powerful abstractions come at an extremely low cost. I can take liberties with my implementations (such as runtime generics) while outperforming modern (bloated) alternatives, often by orders of magnitude. Plus C is readable, elegant, and beautiful (sometimes).

Constraints

  • Adhere to the project style guide.
  • Implement all final solutions following the C99 standard.
    • Assume that the English letter characters are ordered sequentially (i.e., no EBCDIC).
    • Assume that signed integer overflow is defined based on two's complement.

Dependencies

This repository depends on the GNU Multiple Precision Arithmetic Library (GMP), which is licensed under the GNU Lesser General Public License v3.0 (LGPL-3.0).

Project Euler

Id Problem Domain Result Implementation
1 Multiples of 3 or 5 Sequences Sum 1 + 2 + 3 + 4 + ...
2 Even Fibonacci Numbers Sequences Sum Fibonacci sequence
3 Largest Prime Factor Number theory Maximum Trial division
4 Largest Palindrome Product Number theory Maximum Palindromic number
5 Smallest Multiple Number theory Least common multiple Euclidean algorithm
6 Sum Square Difference Sequences Difference Square pyramidal number
7 10001st Prime Number theory Term Sieve of Eratosthenes
8 Largest Product in a Series Dynamic programming Maximum Sliding-window technique
9 Special Pythagorean Triplet Geometry Product Euclid's formula
10 Summation of Primes Number theory Sum
11 Largest Product in a Grid Dynamic programming Maximum
12 Highly Divisible Triangular Number Sequences Term Integer factorization
13 Large Sum Arithmetic Quotient Floating-point arithmetic
14 Longest Collatz Sequence Sequences Term Collatz conjecture
15 Lattice Paths Combinatorics Binomial coefficient Binomial coefficient
16 Power Digit Sum Arbitrary-precision arithmetic Sum Arbitrary-precision arithmetic
17 Number Letter Counts Combinatorics Count
18, 67 Maximum Path Sum Dynamic programming Maximum Bottom-up approach
19 Counting Sundays Combinatorics Count
20 Factorial Digit Sum Arbitrary-precision arithmetic Sum
21 Amicable Numbers Number theory Sum Amicable numbers
22 Names Scores Sorting Sum Sorting algorithm
23 Non-Abundant Sums Number theory Sum Abundant numbers
24 Lexicographic Permutations Combinatorics Permutation Permutation
25 1000-digit Fibonacci Number Sequences Term number Fibonacci sequence
26 Reciprocal Cycles Number theory Maximum Full reptend prime
27 Quadratic Primes Number theory Product
28 Number Spiral Diagonals Sequences Sum Arithmetic sequence
29 Distinct Powers Number theory Count
30 Digit Fifth Powers Number theory Sum
31 Coin Sums Combinatorics Partition Partition function
32 Pandigital Products Number theory Sum Pandigital number
33 Digit Cancelling Fractions Number theory Greatest common divisor
34 Digit Factorials Combinatorics Sum Factorial
35 Circular Primes Number theory Count Circular prime
36 Double-base Palindromes Number theory Sum Radix
37 Truncatable Primes Number theory Sum Truncatable prime
38 Pandigital Multiples Number theory Maximum
39 Integer Right Triangles Geometry Maximum
40 Champernowne's Constant Number theory Product Champernowne constant
41 Pandigital Prime Number theory Maximum
42 Coded Triangle Numbers Sequences Count
43 Sub-string Divisibility Number theory Sum
44 Pentagonal Numbers Sequences Minimum Pentagonal number
45 Triangular, Pentagonal, and Hexagonal Sequences Term Hexagonal number
46 Goldbach's Other Conjecture Number theory Minimum
47 Distinct Primes Factors Number theory Term
48 Self Powers Arbitrary-precision arithmetic Modulus
49 Prime Permutations Sequences Terms
50 Consecutive Prime Sum Number theory Maximum
51 Prime Digit Replacements Number theory Minimum
52 Permuted Multiples Combinatorics Minimum
53 Combinatoric Selections Combinatorics Count
54 Poker Hands Simulation Count Poker
55 Lychrel Numbers Number theory Count Lychrel number
56 Powerful Digit Sum Arbitrary-precision arithmetic Maximum
57 Square Root Convergents Arbitrary-precision arithmetic Count Continued fraction expansion
58 Spiral Primes Sequences Term number
59 XOR Decryption Cryptography Sum Frequency analysis
60 Prime Pair Sets Number theory Minimum Miller–Rabin primality test, Modular exponentiation, Exponentiation by squaring
61 Cyclical Figurate Numbers Number theory Sum Polygonal number
62 Cubic Permutations Number theory Minimum Multimap, Daniel J. Bernstein (djb2) hash algorithm
63 Powerful Digit Counts Number theory Count
64 Odd Period Square Roots Algebra Count
65 Convergents of e Arbitrary-precision arithmetic Count
66 Diophantine Equation Arbitrary-precision arithmetic Maximum Pell's equation
68 Magic 5-gon Ring Magic shapes Maximum Magic square
69 Totient Maximum Number theory Primorial Euler's totient function
70 Totient Permutation Number theory Minimum
71 Ordered Fractions Sequences Term Farey sequence
72 Counting Fractions Number theory Count Totient summatory function
73 Counting Fractions in a Range Sequences Count
74 Digit Factorial Chains Combinatorics Count
75 Singular Integer Right Triangles Geometry Count
76 Counting Summations Combinatorics Partition
77 Prime Summations Combinatorics Term
78 Coin Partitions Combinatorics Term Pentagonal number theorem
79 Passcode Derivation Graph theory Minimum Adjacency matrix
80 Square Root Digital Expansion Arbitrary-precision floating point arithmetic Sum
81 Path Sum: Two Ways Graph theory Minimum path
82 Path Sum: Three Ways Graph theory Minimum path
83 Path Sum: Four Ways Graph theory Minimum path
84 Monopoly Odds Simulation Maxima Blackman and Vigna's xoshiro256** algorithm
85 Counting Rectangles Geometry Area
86 Cuboid Route Geometry Minimum
87 Prime Power Triples Number theory Count Hash set
89 Roman Numerals Numeral systems Difference Roman numerals
91 Right Triangles with Integer Coordinates Geometry Count
92 Square Digit Chains Number theory Count

LeetCode

Id Problem Domain Result Implementation
7 Reverse Integer Mathematics Integer math_reverse
8 String to Integer Strings Integer atoll
9 Palindrome Number Mathematics Boolean math_is_palindrome
12 Integer to Roman String Mathematics roman_to_string_builder
13 Roman to Integer Mathematics Integer roman_from_string_builder
23 Merge k Sorted Lists Linked Lists Linked List PriorityQueue
28 Find the Index of the First Occurrence in a String Strings Index strstr
29 Divide Two Integers Mathematics Quotient
31 Next Permutation Array Permutation PermutationIterator
46 Permutations Array Permutation PermutationIterator
50 Pow(x, n) Mathematics Power pow
60 Permutation Sequence Mathematics Permutation PermutationIterator
62 Unique Paths Combinatorics Binomial coefficient binomial
69 Sqrt(x) Mathematics Square root sqrt
75 Sort Colors Sorting Sort qsort
77 Combinations Backtracking Matrix CombinationIterator
150 Evaluate Reverse Polish Notation Mathematics Integer rpn_evaluate
202 Happy Number Mathematics Boolean SquareDigitChain
204 Count Primes Mathematics Count Sieve, binary_search_rank
258 Add Digits Mathematics Digital root
263 Ugly Number Mathematics Boolean
273 Integer to English Words Mathematics String words_to_string
367 Valid Perfect Square Mathematics Boolean math_is_polygonal
650 2 Keys Keyboard Mathematics Sum Sieve, factor_sum
744 Find Smallest Letter Greater Than Target Binary search Character binary_search_min
2119 A Number After a Double Reversal Mathematics Boolean math_reverse
2400 Number of Ways to Reach a Position After Exactly k Steps Combinatorics Binomial coefficient mod_binomial_range
2427 Number of Common Factors Mathematics Count gcd
2507 Smallest Value After Replacing With Sum of Prime Factors Mathematics Minimum Sieve, factor_sum
2520 Count the Digits That Divide a Number Mathematics Count
2521 Distinct Prime Factors of a Product Array Mathematics Count FactorIterator, Sieve
2544 Alternating Digit Sum Mathematics Sum
2550 Monkey Move Combinatorics Power mod_pow

About

Competitive programming solutions in C language: Project Euler, LeetCode

Topics

Resources

License

Stars

Watchers

Forks

Languages