Skip to content

combin is a Java utility that generates all possible binary combinations of a given size n. It allows you to customize the binary digits (0 and 1) with any other characters and offers flexible output options, including printing to the console, saving to a file, or storing the results in memory.

License

Notifications You must be signed in to change notification settings

BrownCoatJustice/combin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

combin: Binary Combiner

combin is a Java utility to generate all possible binary combinations of a given size n. It offers flexible output options: print results to the console, save them to a file, or store them in memory.

Features

  • Generate binary combinations: For any size n (up to (2^{16})).
  • Customizable characters: Replace 0 and 1 with any other characters.
  • Output options:
    • Print to the console.
    • Save to a file.
    • Store in an ArrayList.

Requirements

  • Java 8 or higher.

How to Use

Compile the Code

javac Combin.java

Run the Program

java Combin <size> [bin0] [bin1] [filename] [console]

Parameters

  1. <size>: (Required) The size of the binary combinations. Must be a positive integer ≤ 16.
  2. [bin0]: (Optional) Character to use instead of 0.
  3. [bin1]: (Optional) Character to use instead of 1.
  4. [filename]: (Optional) File to save the combinations. If provided, the program writes the combinations to this file.
  5. [console]: (Optional) If provided and set to console, results are printed to the console.

Examples

Default Binary Output

Generate all binary combinations of size 3 and print them to the console:

java Combin 3 1 0

Custom Characters

Generate combinations of size 3 using X and Y instead of 0 and 1:

java Combin 3 X Y console

Save to a File

Generate combinations of size 4 and save them to output.txt:

java Combin 4 0 1 output.txt

Save and Print

Generate combinations of size 4, save them to output.txt, and also print them:

java Combin 4 0 1 output.txt console

Error Handling

  • Invalid size: If <size> is not provided, not a number, or exceeds the limit, an error is displayed.
  • Invalid characters: Binary characters must be single characters.
  • File write issues: Errors during file operations are logged to the console.

Example Output

Command:

java Combin 2 1 0 console

Output:

Generating binary combinations for size: 2
Generated combinations:
00
01
10
11

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

combin is a Java utility that generates all possible binary combinations of a given size n. It allows you to customize the binary digits (0 and 1) with any other characters and offers flexible output options, including printing to the console, saving to a file, or storing the results in memory.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages