Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -3,54 +3,54 @@ import java.util.List;
|
|||
|
||||
public final class LargestNumberDivisibleByItsDigits {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Base 10
|
||||
final int decimalDivisor = 9 * 8 * 7;
|
||||
int decimal = ( 9876432 / decimalDivisor ) * decimalDivisor;
|
||||
|
||||
while ( ! isLynchBellDecimal(decimal) ) {
|
||||
decimal -= decimalDivisor;
|
||||
}
|
||||
System.out.println("The largest decimal Lynch-Bell number is " + decimal);
|
||||
|
||||
// Base 16
|
||||
final long hexDivisor = 15L * 14 * 13 * 12 * 11;
|
||||
|
||||
long hexadecimal = ( 0xfedcba987654321L / hexDivisor ) * hexDivisor;
|
||||
while ( ! isLynchBellHex(hexadecimal) ) {
|
||||
hexadecimal -= hexDivisor;
|
||||
}
|
||||
System.out.println("The largest hexadecimal Lynch-Bell number is " + Long.toHexString(hexadecimal));
|
||||
}
|
||||
|
||||
private static boolean isLynchBellDecimal(int decimal) {
|
||||
String decimalString = Integer.toString(decimal);
|
||||
public static void main(String[] args) {
|
||||
// Base 10
|
||||
final int decimalDivisor = 9 * 8 * 7;
|
||||
int decimal = ( 9876432 / decimalDivisor ) * decimalDivisor;
|
||||
|
||||
while ( ! isLynchBellDecimal(decimal) ) {
|
||||
decimal -= decimalDivisor;
|
||||
}
|
||||
System.out.println("The largest decimal Lynch-Bell number is " + decimal);
|
||||
|
||||
// Base 16
|
||||
final long hexDivisor = 15L * 14 * 13 * 12 * 11;
|
||||
|
||||
long hexadecimal = ( 0xfedcba987654321L / hexDivisor ) * hexDivisor;
|
||||
while ( ! isLynchBellHex(hexadecimal) ) {
|
||||
hexadecimal -= hexDivisor;
|
||||
}
|
||||
System.out.println("The largest hexadecimal Lynch-Bell number is " + Long.toHexString(hexadecimal));
|
||||
}
|
||||
|
||||
private static boolean isLynchBellDecimal(int decimal) {
|
||||
String decimalString = Integer.toString(decimal);
|
||||
if ( decimalString.contains("0") || decimalString.contains("5") ) {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
List<Integer> distinctDigits =
|
||||
Arrays.stream(decimalString.split("")).map( s -> Integer.valueOf(s) ).distinct().toList();
|
||||
Arrays.stream(decimalString.split("")).map( s -> Integer.valueOf(s) ).distinct().toList();
|
||||
if ( distinctDigits.size() < decimalString.length() ) {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
return distinctDigits.stream().allMatch( i -> ( decimal % i ) == 0 );
|
||||
}
|
||||
|
||||
private static boolean isLynchBellHex(long hexadecimal) {
|
||||
String hexString = Long.toHexString(hexadecimal);
|
||||
if ( hexString.contains("0") ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
List<Integer> distinctDigits =
|
||||
Arrays.stream(hexString.split("")).map( s -> Integer.valueOf(s, 16) ).distinct().toList();
|
||||
if ( distinctDigits.size() < hexString.length() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return distinctDigits.stream().allMatch( i -> ( hexadecimal % i ) == 0 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static boolean isLynchBellHex(long hexadecimal) {
|
||||
String hexString = Long.toHexString(hexadecimal);
|
||||
if ( hexString.contains("0") ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
List<Integer> distinctDigits =
|
||||
Arrays.stream(hexString.split("")).map( s -> Integer.valueOf(s, 16) ).distinct().toList();
|
||||
if ( distinctDigits.size() < hexString.length() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return distinctDigits.stream().allMatch( i -> ( hexadecimal % i ) == 0 );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue