This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package euler; | |
import java.util.Arrays; | |
public class SameDigits { | |
public static String sort(String s) { | |
char[] array = s.toCharArray(); | |
Arrays.sort(array); | |
return new String(array); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Test { | |
public static void main(String[] args) { | |
System.out.println(concat(12, 34)); | |
} | |
public static int concat(int a, int b) { | |
if (b == 0) return a*10; | |
return a*pow(10,len(b)) + b; | |
} | |
public static int pow (int a, int b) { | |
if (b == 0) return 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Champernowne { | |
private static String num = null; | |
public static void main(String[] args) { | |
StringBuilder sb = new StringBuilder(); | |
for (int i = 0; i < 1_000_000; i++) { | |
sb.append(String.valueOf(i)); | |
if (i == 0) sb.append('.'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package euler; | |
public class ChainMember { | |
private int n; | |
// we use a -1 as n to indicate that this is a 89 to differ them from 0 or 1 | |
private static final ChainMember EIGHTYNINE = new ChainMember(-1); | |
public ChainMember(int n) { | |
this.n = n; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package dailyprogrammer; | |
import java.util.Arrays; | |
/** | |
* https://www.reddit.com/r/dailyprogrammer/comments/67q3s6/20170426_challenge_312_intermediate_next_largest/ | |
* @author David | |
* | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Comparator; | |
import java.util.PriorityQueue; | |
public class Comp { | |
public static void main(String[] args) { | |
PriorityQueue<Integer> q = new PriorityQueue<>(new Comparator<Integer>() { | |
@Override | |
public int compare(Integer o1, Integer o2) { | |
return sig(o1 - o2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class IsEven { | |
public static boolean isEven_bit(int i) { | |
return (i & 1) == 0; | |
} | |
public static boolean isEven_mod(int i) { | |
return i % 2 == 0; | |
} | |
public static void main(String[] args) { | |
isEven_bit(2); | |
isEven_mod(2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Fraction { | |
public static final Fraction ONE = new Fraction(1); | |
public static final Fraction TWO = new Fraction(2); | |
public static final Fraction TEN = new Fraction(10); | |
private long num; | |
private long denom; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File; | |
import java.io.FileWriter; | |
import java.io.IOException; | |
import java.text.SimpleDateFormat; | |
import java.util.Date; | |
import javax.swing.JOptionPane; | |
public final class Logger { | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @author David | |
* | |
* When I took an introductory course in mathematics, the lecturer introduced the natural numbers | |
* using a set of axioms called the peano axioms. | |
* I wondered if it would be possible to create a Java class that represents the integers without | |
* using any primitive type such as int, double, byte, boolean, etc. | |
* The class should be able to perform the operations + and *. | |
* I also created the relation ==, <, >, <=, >= to define an order. | |
* |