File tree Expand file tree Collapse file tree 1 file changed +36
-1
lines changed Expand file tree Collapse file tree 1 file changed +36
-1
lines changed Original file line number Diff line number Diff line change 1
1
# 196-algorithm
2
2
Implementation of the 196-algorithm to find palindromes in a predetermined sequence of instructions.
3
3
4
- Inspired by: https://www.youtube.com/watch?v=bN8PE3eljdA&t=374s
4
+ Inspired by https://www.youtube.com/watch?v=bN8PE3eljdA&t=374s
5
+
5
6
Implemented here.
6
7
7
8
## Execution
@@ -11,3 +12,37 @@ cd 196-algorithm
11
12
g++ main.cpp -o main
12
13
./main
13
14
```
15
+ ## Approach
16
+ Given a number n we iteratively reassign n as the sum of previous n and the reverse of previous n until n is a palindrome.
17
+
18
+ Example Given:
19
+ ```
20
+ n = 19 // no palindrome, iteration = 0
21
+ n = 19 + 91 = 110 // no palindrome, iteration = 1
22
+ n = 110 + 11 = 121 // palindrome, iteration = 2
23
+ ```
24
+
25
+ ## Outcome
26
+
27
+ | Number| Iterations| Final palindrome|
28
+ | ------| :--------:| ---------------:|
29
+ | 1| 0| 1|
30
+ | 2| 0| 2|
31
+ | 3| 0| 3|
32
+ | 4| 0| 4|
33
+ | 5| 0| 5|
34
+ | 6| 0| 6|
35
+ | 7| 0| 7|
36
+ | 8| 0| 8|
37
+ | 9| 0| 9|
38
+ | 10| 1| 11|
39
+ | 11| 0| 11|
40
+ | 12| 1| 33|
41
+ | 13| 1| 44|
42
+ | 14| 1| 55|
43
+ | 15| 1| 66|
44
+ | 16| 1| 77|
45
+ | 17| 1| 88|
46
+ | 18| 1| 99|
47
+ | 19| 2| 121|
48
+ | 20| 1| 22|
You can’t perform that action at this time.
0 commit comments