Skip to content

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

IdProblemDomainResultImplementation
1Multiples of 3 or 5SequencesSum1 + 2 + 3 + 4 + ...
2Even Fibonacci NumbersSequencesSumFibonacci sequence
3Largest Prime FactorNumber theoryMaximumTrial division
4Largest Palindrome ProductNumber theoryMaximumPalindromic number
5Smallest MultipleNumber theoryLeast common multipleEuclidean algorithm
6Sum Square DifferenceSequencesDifferenceSquare pyramidal number
710001st PrimeNumber theoryTermSieve of Eratosthenes
8Largest Product in a SeriesDynamic programmingMaximumSliding-window technique
9Special Pythagorean TripletGeometryProductEuclid's formula
10Summation of PrimesNumber theorySum
11Largest Product in a GridDynamic programmingMaximum
12Highly Divisible Triangular NumberSequencesTermInteger factorization
13Large SumArithmeticQuotientFloating-point arithmetic
14Longest Collatz SequenceSequencesTermCollatz conjecture
15Lattice PathsCombinatoricsBinomial coefficientBinomial coefficient
16Power Digit SumArbitrary-precision arithmeticSumArbitrary-precision arithmetic
17Number Letter CountsCombinatoricsCount
18, 67Maximum Path SumDynamic programmingMaximumBottom-up approach
19Counting SundaysCombinatoricsCount
20Factorial Digit SumArbitrary-precision arithmeticSum
21Amicable NumbersNumber theorySumAmicable numbers
22Names ScoresSortingSumSorting algorithm
23Non-Abundant SumsNumber theorySumAbundant numbers
24Lexicographic PermutationsCombinatoricsPermutationPermutation
251000-digit Fibonacci NumberSequencesTerm numberFibonacci sequence
26Reciprocal CyclesNumber theoryMaximumFull reptend prime
27Quadratic PrimesNumber theoryProduct
28Number Spiral DiagonalsSequencesSumArithmetic sequence
29Distinct PowersNumber theoryCount
30Digit Fifth PowersNumber theorySum
31Coin SumsCombinatoricsPartitionPartition function
32Pandigital ProductsNumber theorySumPandigital number
33Digit Cancelling FractionsNumber theoryGreatest common divisor
34Digit FactorialsCombinatoricsSumFactorial
35Circular PrimesNumber theoryCountCircular prime
36Double-base PalindromesNumber theorySumRadix
37Truncatable PrimesNumber theorySumTruncatable prime
38Pandigital MultiplesNumber theoryMaximum
39Integer Right TrianglesGeometryMaximum
40Champernowne's ConstantNumber theoryProductChampernowne constant
41Pandigital PrimeNumber theoryMaximum
42Coded Triangle NumbersSequencesCount
43Sub-string DivisibilityNumber theorySum
44Pentagonal NumbersSequencesMinimumPentagonal number
45Triangular, Pentagonal, and HexagonalSequencesTermHexagonal number
46Goldbach's Other ConjectureNumber theoryMinimum
47Distinct Primes FactorsNumber theoryTerm
48Self PowersArbitrary-precision arithmeticModulus
49Prime PermutationsSequencesTerms
50Consecutive Prime SumNumber theoryMaximum
51Prime Digit ReplacementsNumber theoryMinimum
52Permuted MultiplesCombinatoricsMinimum
53Combinatoric SelectionsCombinatoricsCount
54Poker HandsSimulationCountPoker
55Lychrel NumbersNumber theoryCountLychrel number
56Powerful Digit SumArbitrary-precision arithmeticMaximum
57Square Root ConvergentsArbitrary-precision arithmeticCountContinued fraction expansion
58Spiral PrimesSequencesTerm number
59XOR DecryptionCryptographySumFrequency analysis
60Prime Pair SetsNumber theoryMinimumMiller–Rabin primality test, Modular exponentiation, Exponentiation by squaring
61Cyclical Figurate NumbersNumber theorySumPolygonal number
62Cubic PermutationsNumber theoryMinimumMultimap, Daniel J. Bernstein (djb2) hash algorithm
63Powerful Digit CountsNumber theoryCount
64Odd Period Square RootsAlgebraCount
65Convergents of eArbitrary-precision arithmeticCount
66Diophantine EquationArbitrary-precision arithmeticMaximumPell's equation
68Magic 5-gon RingMagic shapesMaximumMagic square
69Totient MaximumNumber theoryPrimorialEuler's totient function
70Totient PermutationNumber theoryMinimum
71Ordered FractionsSequencesTermFarey sequence
72Counting FractionsNumber theoryCountTotient summatory function
73Counting Fractions in a RangeSequencesCount
74Digit Factorial ChainsCombinatoricsCount
75Singular Integer Right TrianglesGeometryCount
76Counting SummationsCombinatoricsPartition
77Prime SummationsCombinatoricsTerm
78Coin PartitionsCombinatoricsTermPentagonal number theorem
79Passcode DerivationGraph theoryMinimumAdjacency matrix
80Square Root Digital ExpansionArbitrary-precision floating point arithmeticSum
81Path Sum: Two WaysGraph theoryMinimum path
82Path Sum: Three WaysGraph theoryMinimum path
83Path Sum: Four WaysGraph theoryMinimum path
84Monopoly OddsSimulationMaximaBlackman and Vigna's xoshiro256** algorithm
85Counting RectanglesGeometryArea
86Cuboid RouteGeometryMinimum
87Prime Power TriplesNumber theoryCountHash set
89Roman NumeralsNumeral systemsDifferenceRoman numerals
91Right Triangles with Integer CoordinatesGeometryCount
92Square Digit ChainsNumber theoryCount

LeetCode

IdProblemDomainResultImplementation
7Reverse IntegerMathematicsIntegermath_reverse
8String to IntegerStringsIntegeratoll
9Palindrome NumberMathematicsBooleanmath_is_palindrome
12Integer to RomanStringMathematicsroman_to_string_builder
13Roman to IntegerMathematicsIntegerroman_from_string_builder
23Merge k Sorted ListsLinked ListsLinked ListPriorityQueue
28Find the Index of the First Occurrence in a StringStringsIndexstrstr
29Divide Two IntegersMathematicsQuotient
31Next PermutationArrayPermutationPermutationIterator
46PermutationsArrayPermutationPermutationIterator
50Pow(x, n)MathematicsPowerpow
60Permutation SequenceMathematicsPermutationPermutationIterator
62Unique PathsCombinatoricsBinomial coefficientbinomial
69Sqrt(x)MathematicsSquare rootsqrt
75Sort ColorsSortingSortqsort
77CombinationsBacktrackingMatrixCombinationIterator
150Evaluate Reverse Polish NotationMathematicsIntegerrpn_evaluate
202Happy NumberMathematicsBooleanSquareDigitChain
204Count PrimesMathematicsCountSieve, binary_search_rank
258Add DigitsMathematicsDigital root
263Ugly NumberMathematicsBoolean
273Integer to English WordsMathematicsStringwords_to_string
367Valid Perfect SquareMathematicsBooleanmath_is_polygonal
6502 Keys KeyboardMathematicsSumSieve, factor_sum
744Find Smallest Letter Greater Than TargetBinary searchCharacterbinary_search_min
2119A Number After a Double ReversalMathematicsBooleanmath_reverse
2400Number of Ways to Reach a Position After Exactly k StepsCombinatoricsBinomial coefficientmod_binomial_range
2427Number of Common FactorsMathematicsCountgcd
2507Smallest Value After Replacing With Sum of Prime FactorsMathematicsMinimumSieve, factor_sum
2520Count the Digits That Divide a NumberMathematicsCount
2521Distinct Prime Factors of a Product ArrayMathematicsCountFactorIterator, Sieve
2544Alternating Digit SumMathematicsSum
2550Monkey MoveCombinatoricsPowermod_pow

About

Competitive programming solutions in C language: Project Euler, LeetCode

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Contributors

Languages