Skip to content

Simple command-line factorisation utility written in Rust

Notifications You must be signed in to change notification settings

Navigierender/factorforcer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

🛠️ FactorForcer

FactorForcer is a command-line utility written in Rust that solves a specific factorization problem: finding the unique combination of a fixed number of prime factors that multiply up to a target number (if such a combination exists).

This tool is particularly useful for problems where a target value $G$ must be expressed as the product of exactly $S$ prime numbers:

$$ G = p_1 \times p_2 \times \cdots \times p_S $$

Where $p_i$ is a prime number. Due to the Fundamental Theorem of Arithmetic, there is at most one unique set of prime factors for any given $G$ and $S$. The program also outputs the sum of these prime factors $(\sum p_i)$. for the unique solution found.


🚀 How to Use

The program requires two command-line arguments:

Format:

factorforcer <size> <goal>
Argument Description Constraints
<size> The exact number of prime factors required in the solution. Must be between 1 and 32.
<goal> The target number to be factorized. Must be large enough to be factorized into the given size.

Example:

To find all ways that the number 30 can be expressed as a product of 3 prime numbers:

factorforcer 3 30

⚙️ Program Core

  • Sieve of Eratosthenes:
    Generates all prime numbers up to goal using a optimized bitvec array.
    -> (To speed this step up since it takes so long using a default 8 bit bool Vector)

  • Recursive Search:
    Stack-based Depth-First Search algorithm to find the unique factorization that matches the required size. The search only considers factors in non-decreasing order.


⚠️ Problems

The initialization of the bitvec array for the Sieve of Eratosthenes can be time-consuming when handling very large numbers.

Also its spagetthi code af 🤌 🍝

Updates

Alt Text


📦 Dependencies

This program relies on the external Rust crate bitvec for efficient boolean array management.
-> (used in the Sieve implementation)

To compile, ensure your Cargo.toml includes:

[dependencies]
bitvec = "1.0"

⭐ Project Context

This utility was developed because i got a bit to invested in prime factoralisation and represents my very first project written in Rust.

While the code successfully solves the problem, it may not reflect the most idiomatic or highly optimized Rust practices, as it was primarily built as an initial learning experience.

About

Simple command-line factorisation utility written in Rust

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages