Skip to content

Finding Kaprekar's constant (6174) and the number of iterations to reach it. https://en.wikipedia.org/wiki/6174

Notifications You must be signed in to change notification settings

ralu2004/Kaprekar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”’ Kaprekar's Constant Finder

An x86 Assembly program that demonstrates the iterative process of reaching Kaprekar's constant (6174) from any four-digit number.


πŸ“Œ Overview

This project showcases an x86 Assembly implementation that takes a four-digit number and applies Kaprekar's routine until it converges to the constant 6174. The program also tracks the number of iterations required to reach this constant.


πŸ” How It Works

Kaprekar's routine involves the following steps:

  1. Arrange the digits of the number in descending and ascending order to form two new numbers.
  2. Subtract the smaller number from the larger number.
  3. Repeat the process with the result until the number 6174 is obtained.

For example, starting with the number 3524:

  • 5432 (descending) - 2345 (ascending) = 3087
  • 8730 - 378 = 8352
  • 8532 - 2358 = 6174

πŸ›  Project Structure

Kaprekar/
β”œβ”€β”€ README.md # Project documentation
β”œβ”€β”€ DATA.TXT # Output file: the number of iterations for each 4-digit number
β”œβ”€β”€ maclib.asm # Assembly macros
β”œβ”€β”€ main.asm # Main program logic
└── proclib.asm # Procedure library

βš™οΈ Requirements

  • Assembler: NASM
  • Debugger/Emulator: DOSBox or EMU8086
  • Operating System: Windows/Linux/MacOS (with DOS emulator)

πŸš€ How to Run

Option 1: Using DOSBox (classic)

  1. Clone the repository:
    git clone https://github.com/ralu2004/Kaprekar.git
    cd Kaprekar
  2. Assemble the program:
    nasm -f bin main.asm -o kaprekar.com
  3. Run the program using a DOS emulator:
    dosbox kaprekar.com
  4. Input a four-digit number (e.g., 3524) when prompted.

Option 2: Using Visual Studio Code

  1. Open the project in VS Code.
  2. Assemble main.asm with NASM (either in the terminal or using an extension):
nasm -f bin main.asm -o kaprekar.com
  1. Run the resulting .com file: Directly in the terminal, or Using an x86 emulator/extension inside VS Code.

  2. Enter a four-digit number when prompted. The program will iterate until it reaches Kaprekar’s constant 6174.


πŸ“„ License

This project is licensed under the MIT License.


πŸ“¬ Contact

GitHub profile: https://github.com/ralu2004

About

Finding Kaprekar's constant (6174) and the number of iterations to reach it. https://en.wikipedia.org/wiki/6174

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published