aboutsummaryrefslogtreecommitdiff
path: root/Java/Beginer training/src/VampireNumber explanation.txt
diff options
context:
space:
mode:
Diffstat (limited to 'Java/Beginer training/src/VampireNumber explanation.txt')
-rw-r--r--Java/Beginer training/src/VampireNumber explanation.txt39
1 files changed, 39 insertions, 0 deletions
diff --git a/Java/Beginer training/src/VampireNumber explanation.txt b/Java/Beginer training/src/VampireNumber explanation.txt
new file mode 100644
index 0000000..10ac553
--- /dev/null
+++ b/Java/Beginer training/src/VampireNumber explanation.txt
@@ -0,0 +1,39 @@
+VampireNumber Java task, code explanation with the number 1827:
+
+1827 (Number that we are checking)
+0123 (Indexes of digits, in code they are named: first, second, third & fourth)
+
+The first and second number that are multiplied are illustrated combined as one (the first half of the calculated numbers is the first multiple, and the second half - the second)
+For example, the number 1278 is actually 12 and 78 and they are multiplied to check for the result
+This is done like that to better illustrate how the numbers change
+
+Cycle: Swap 1 with 3 (indexes):
+1827 1728
+1782 1287
+1278 1872
+
+2178 2871
+2817 2718
+2781 2187 NOTE: 2187 is the answer, so the code would stop here, but this example is continued to the end
+
+7281 7182
+7128 7821
+7812 7218
+
+8712 8217
+8271 8172
+8127 8721
+
+1827 (Here the cycles end)
+
+Cycle: it rotates the last 3 digits, for example if we have 123,the 3 gets in the front and the others move back, i.e. 312
+
+ 1 2 3 => 3 1 2
+ ^-----'
+
+Swap 1 with 3: as the name suggests, it makes a second version of the number by swapping the 1st (index) and 2nd (index) digit
+
+ 0 1 2 3 => 0 3 2 1
+ ^---^
+
+ -the swap is there because with the cycle we miss out on half of the possible numbers \ No newline at end of file