Categories
Algorithms and Data Structures
  • Github CLI
  • SSH
  • HTTPS
Clone Repo

Zig Math Algorithms

A collection of mathematical algorithms implemented in Zig, designed for educational purposes and showcasing Zig’s performance.

🚀 Table of Contents

🔢 Available Algorithms

AlgorithmDescriptionCommandDifficulty
Basic Number Operations
Prime Number CheckerChecks if a number is primezig run src/algorithm/math/prime_checker.zigEasy
Armstrong Number CheckerVerifies Armstrong numberszig run src/algorithm/math/is_armstrong.zigEasy
Happy Number CheckerChecks if a number is happyzig run src/algorithm/math/happy_number.zigEasy
Palindrome Number CheckerChecks if a number is a palindromezig run src/algorithm/math/palindrome_number.zigEasy
Sum of DigitsCalculates digit sumzig run src/algorithm/math/sum_of_digits.zigEasy
Digital RootRecursive digit sum calculationzig run src/algorithm/math/digital_root.zigEasy
Reverse NumberReverses digits of a numberzig run src/algorithm/math/reverse_number.zigEasy
Power of Two CheckerChecks if number is 2ⁿzig run src/algorithm/math/power_of_two.zigEasy
Integer Square RootFinds floor(√n)zig run src/algorithm/math/integer_sqrt.zigEasy
Leap Year CheckerDetermines if year is leapzig run src/algorithm/math/leap_year_checker.zigEasy
Number Theory
Sieve of EratosthenesGenerates prime numbers efficientlyzig run src/algorithm/math/sieve_of_eratosthenes.zigMedium
Perfect Number CheckerChecks if a number is perfectzig run src/algorithm/math/perfect_number_checker.zigEasy
Abundant/Deficient CheckerChecks if number is abundant/deficientzig run src/algorithm/math/abundant_deficient_checker.zigEasy
Strong Number CheckerSum of digit factorials checkzig run src/algorithm/math/strong_number_checker.zigEasy
GCD and LCM CalculatorFinds GCD and LCMzig run src/algorithm/math/gcd_lcm_calculator.zigMedium
Prime FactorizationComputes prime factorszig run src/algorithm/math/prime_factorization.zigMedium
Prime CounterCounts primes up to nzig run src/algorithm/math/prime_counter.zigMedium
Euler’s Totient FunctionCounts coprime numberszig run src/algorithm/math/euler_totient.zigHard
Fermat’s Factorization 🆕Factors integers using difference of squareszig run src/algorithm/math/fermats_factorization.zigMedium
Modular Exponentiation 🆕Efficiently computes (base^exp) % modzig run src/algorithm/math/modular_exponentiation.zigMedium
Sequences and Series
Fibonacci CalculatorCalculates nth Fibonaccizig run src/algorithm/math/fibonacci.zigEasy
Lucas NumbersGenerates Lucas numberszig run src/algorithm/math/lucas_numbers.zigEasy
Factorial CalculatorCalculates n!zig run src/algorithm/math/factorial.zigEasy
Sequence GeneratorArithmetic/Geometric sequenceszig run src/algorithm/math/sequence_generator.zigEasy
Trailing Zeros in FactorialCounts trailing zeros in n!zig run src/algorithm/math/factorial_trailing_zeroes.zigMedium
Collatz ConjectureSteps to reach 1zig run src/algorithm/math/collatz_conjecture.zigMedium
Catalan CalculatorCalculates nth Catalanzig run src/algorithm/math/catalan.zigHard
Pascal’s Triangle 🆕Generates Pascal’s triangle up to n rowszig run src/algorithm/math/pascals_triangle.zigEasy
Advanced Mathematics
Binomial CoefficientPascal’s triangle coefficientszig run src/algorithm/math/binomial_coefficient.zigMedium
Cantor Set GeneratorGenerates Cantor setzig run src/algorithm/math/cantor_set.zig -- 0 1 3Hard
Extended EuclideanGCD and Bézout coefficientszig run src/algorithm/math/euclidean_algorithm_extended.zigHard
Linear InterpolationLinear interpolationzig run src/algorithm/math/linear_interpolation.zigHard
Chinese RemainderSolves linear congruenceszig run src/algorithm/math/chinese_remainder.zigHard
Karatsuba Multiplication 🆕Efficient multiplication algorithmzig run src/algorithm/math/karatsuba.zigHard
Fast Fourier Transform 🆕Computes the FFT of a sequencezig run src/algorithm/math/fft.zigHard

🚀 Prerequisites

  • Zig Compiler:
    • Latest version recommended. Install via:

      sh -c "$(curl -fsSL https://ziglang.org/download/index.json | jq -r '.master.url')"
      

🔧 Running the Algorithms

To run any algorithm, use the Zig run command followed by the specific algorithm file path and any required arguments. For example:

zig run src/algorithm/math/prime_checker.zig
# or
zig test src/algorithm/math/prime_checker.zig

More information is available in the respective file comment header.

📚 Purpose

This repository provides a collection of mathematical algorithms implemented in Zig, showcasing the language’s capabilities and performance. Each module is designed to be easily run and tested, making it a useful resource for learning and experimentation.

📝 License

MIT License

Copyright (c) 2025 Ramsyana

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

🤝 Contributing

Contributions are welcome! Here’s how to contribute:

  • Fork the repository
  • Create your feature branch (git checkout -b feature/AmazingFeature)
  • Commit your changes (git commit -m ‘Add some AmazingFeature’)
  • Push to the branch (git push origin feature/AmazingFeature)
  • Open a pull request

📧 Contact

Ramsyana - ramsyana[at]mac[dot]com

I’m a system engineering enthusiast. Feel free to fork, clone, open issues, or contribute to this project. Don’t hesitate to reach out with any questions, suggestions, or collaboration ideas!

About
A collection of mathematical algorithms implemented in Zig, designed to address specific mathematical problems with simple command-line interfaces.
Owner
ramsyana (User)
Last Commit
2025-02-25
Latest Release
Latest Release Date
Created
2024-12-13