Skip to content

Instantly share code, notes, and snippets.

View LuxXx's full-sized avatar

David LuxXx

View GitHub Profile
@LuxXx
LuxXx / euler.java
Last active April 21, 2017 23:31
Project Euler - Problem 52
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);
}
@LuxXx
LuxXx / intconcat.java
Created April 18, 2017 12:37
Concatenation of ints using math only
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;
@LuxXx
LuxXx / euler.java
Created April 21, 2017 23:23
Project Euler - Problem 40
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('.');
@LuxXx
LuxXx / euler.java
Last active April 25, 2017 13:59
Project Euler - Problem 92
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;
@LuxXx
LuxXx / dailyprogrammer.java
Last active April 29, 2017 12:03
[2017-04-26] Challenge #312 [Intermediate] Next largest number
package dailyprogrammer;
import java.util.Arrays;
/**
* https://www.reddit.com/r/dailyprogrammer/comments/67q3s6/20170426_challenge_312_intermediate_next_largest/
* @author David
*
*/
@LuxXx
LuxXx / comparator.java
Last active April 29, 2017 13:34
Comparator
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);
@LuxXx
LuxXx / iseven.java
Last active June 20, 2018 19:59
isEven bit vs mod
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);
@LuxXx
LuxXx / Fraction.java
Last active May 27, 2017 23:23
Fraction
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;
@LuxXx
LuxXx / Logger.java
Last active May 10, 2017 19:10
A Logger maybe for re-use
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 {
@LuxXx
LuxXx / Integer.java
Last active May 6, 2017 23:15
What if there were no primitive data types in java?
/**
* @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.
*