Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
94 lines (66 loc) · 2.4 KB

File metadata and controls

94 lines (66 loc) · 2.4 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package Maths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
n number theory, a vampire number (or true vampire number) is a composite natural number with an even number of digits,
that can be factored into two natural numbers each with half as many digits as the original number
and not both with trailing zeroes, where the two factors contain precisely
all the digits of the original number, in any order, counting multiplicity.
The first vampire number is 1260 = 21 × 60.
* *
* <p>
* * link: https://en.wikipedia.org/wiki/Vampire_number
* * </p>
* <p>
*
*/
public class VampireNumber {
public static void main(String[] args) {
test(10,1000);
}
static void test(int startValue, int stopValue) {
int countofRes = 1;
StringBuilder res = new StringBuilder();
for (int i = startValue; i <= stopValue; i++) {
for (int j = i; j <= stopValue; j++) {
// System.out.println(i+ " "+ j);
if (isVampireNumber(i, j,true)) {
countofRes++;
res.append("" + countofRes + ": = ( " + i + "," + j + " = " + i*j + ")" + "\n");
}
}
}
System.out.println(res);
}
static boolean isVampireNumber(int a, int b, boolean noPseudoVamireNumbers ) {
// this is for pseudoVampireNumbers pseudovampire number need not be of length n/2 digits for example
// 126 = 6 x 21
if (noPseudoVamireNumbers) {
if (a * 10 <= b || b * 10 <= a) {
return false;
}
}
String mulDigits = splitIntoDigits(a*b,0);
String faktorDigits = splitIntoDigits(a,b);
return mulDigits.equals(faktorDigits);
}
// methode to Split the numbers to Digits
static String splitIntoDigits(int num, int num2) {
StringBuilder res = new StringBuilder();
ArrayList<Integer> digits = new ArrayList<>();
while (num > 0) {
digits.add(num%10);
num /= 10;
}
while (num2 > 0) {
digits.add(num2%10);
num2/= 10;
}
Collections.sort(digits);
for (int i : digits) {
res.append(i);
}
return res.toString();
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.