Skip to content

Commit 93433cc

Browse files
committed
new(blogpost): Kaprekar's Routine
1 parent e00161a commit 93433cc

File tree

4 files changed

+84
-4
lines changed

4 files changed

+84
-4
lines changed

public/posts/algos/find-minimum-in-rotated-sorted-array.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# Find Minimum in Rotated Sorted Array
2-
31
## Problem Description
42

53
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.
@@ -54,4 +52,4 @@ func main() {
5452
fmt.Println(findMin([]int{1, 2})) // Output: 1
5553
fmt.Println(findMin([]int{2, 1})) // Output: 1
5654
}
57-
```
55+
```

public/posts/kaprekars-routine.txt

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
Have you ever played with numbers and found a surprising pattern? One such fascinating pattern is hidden within **Kaprekar's Routine**, named after the Indian mathematician D.R. Kaprekar. It's a simple game that, for most four-digit numbers, always leads to the same result: **6174**.
2+
3+
Let's dive in and see how it works!
4+
5+
## The Rules of the Game
6+
7+
1. **Pick a four-digit number** with at least two different digits. (Numbers like 1111, 2222, etc., won't work).
8+
2. **Arrange the digits** to form the largest possible number.
9+
3. **Arrange the same digits** to form the smallest possible number.
10+
4. **Subtract** the smallest number from the largest number.
11+
5. **Repeat** steps 2-4 with the new number you get.
12+
13+
You'll be amazed at what happens!
14+
15+
## Example 1: Starting with 3524
16+
17+
Let's try with the number **3524**:
18+
19+
* **Step 1:** Our number is 3524. It has different digits.
20+
* **Step 2:** Largest number: 5432
21+
* **Step 3:** Smallest number: 2345
22+
* **Step 4:** Subtract: 5432 - 2345 = **3087**
23+
24+
Now, we repeat the process with **3087**:
25+
26+
* **Step 2:** Largest number: 8730
27+
* **Step 3:** Smallest number: 0378 (remember to include leading zeros to keep it a four-digit number)
28+
* **Step 4:** Subtract: 8730 - 0378 = **8352**
29+
30+
Repeat with **8352**:
31+
32+
* **Step 2:** Largest number: 8532
33+
* **Step 3:** Smallest number: 2358
34+
* **Step 4:** Subtract: 8532 - 2358 = **6174**
35+
36+
And there it is! We reached 6174.
37+
38+
## Example 2: Starting with 1987
39+
40+
Let's try another one with **1987**:
41+
42+
* **Step 1:** Our number is 1987.
43+
* **Step 2:** Largest number: 9871
44+
* **Step 3:** Smallest number: 1789
45+
* **Step 4:** Subtract: 9871 - 1789 = **8082**
46+
47+
Repeat with **8082**:
48+
49+
* **Step 2:** Largest number: 8820
50+
* **Step 3:** Smallest number: 0288
51+
* **Step 4:** Subtract: 8820 - 0288 = **8532**
52+
53+
Repeat with **8532**:
54+
55+
* **Step 2:** Largest number: 8532
56+
* **Step 3:** Smallest number: 2358
57+
* **Step 4:** Subtract: 8532 - 2358 = **6174**
58+
59+
Again, we arrived at 6174!
60+
61+
## The Magic of 6174
62+
63+
This number, 6174, is known as **Kaprekar's Constant**. For almost any four-digit number (with at least two different digits), if you keep applying Kaprekar's routine, you will eventually reach 6174. Once you reach 6174, the next step will always be:
64+
65+
* Largest: 7641
66+
* Smallest: 1467
67+
* Subtract: 7641 - 1467 = **6174**
68+
69+
It's a loop!
70+
71+
Kaprekar's routine is a wonderful example of how simple arithmetic operations can lead to unexpected and beautiful mathematical constants. Try it with your own four-digit numbers and see the magic unfold!

public/posts/posts.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
[
2+
{
3+
"slug": "kaprekars-routine",
4+
"title": "Kaprekar's Routine: A Curious Number Game",
5+
"date": "2025-11-18",
6+
"updated": "2025-11-18",
7+
"description": "Explore Kaprekar's Routine, a fascinating number game that always leads to the constant 6174 for most four-digit numbers.",
8+
"tags": ["mathematics", "number-theory", "kaprekar", "fun"],
9+
"category": "rant",
10+
"filename": "kaprekars-routine.txt",
11+
"authors": ["fezcode"]
12+
},
213
{
314
"slug": "chaos-theory-philosophical-rant",
415
"title": "The Inevitable Dance of Entropy: A Rant on Chaos",

src/components/PostItem.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const PostItem = ({
7979

8080
return (
8181
<Link
82-
to={isSeries ? `/blog/${slug}` : `/blog/${slug}`}
82+
to={`/blog/${slug}`}
8383
className={`block p-8 my-4 border border-gray-700/50 rounded-lg shadow-lg cursor-pointer transition-colors group relative overflow-hidden ${postBackgroundColorClass} ${postHoverBackgroundColorClass} ${shouldAnimate ? 'animated-grid-bg' : ''}`}
8484
>
8585
<article>

0 commit comments

Comments
 (0)