Skip to content

Instantly share code, notes, and snippets.

@MLLeKander
MLLeKander / 1.py
Last active December 2, 2017 12:03
Advent of Code
s = open('inputs/1.in').read()
midp = 1
print sum(int(e[0]) for e in zip(s,s[midp:]+s[:midp]) if e[0] == e[1])
midp = len(s)/2
print sum(int(e[0]) for e in zip(s,s[midp:]+s[:midp]) if e[0] == e[1])
@MLLeKander
MLLeKander / TestIO.java
Last active October 31, 2016 17:00
IO Output Test
import java.io.*;
public class TestIO {
public static void testSystemOutPrintln() {
for (int i = 0; i < 10_000_000; i++) {
System.out.println(i);
}
}
public static void testSystemOutPrint() {
for (int i = 0; i < 10_000_000; i++) {
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
#define VI vector<int>
#define pb push_back
#define NMAX 100000
int l[NMAX], r[NMAX];
@MLLeKander
MLLeKander / Final MAX
Last active October 25, 2016 19:38
JVM
$ java -XX:+UnlockDiagnosticVMOptions '-XX:CompileCommand=print,*test3.main' test3
CompilerOracle: print *test3.main
OpenJDK 64-Bit Server VM warning: printing of assembly code is enabled; turning on DebugNonSafepoints to gain additional output
Compiled method (c1) 42 19 % 3 test3::main @ 8 (84 bytes)
total in heap [0x00007f9961110610,0x00007f9961111468] = 3672
relocation [0x00007f9961110738,0x00007f99611107e0] = 168
main code [0x00007f99611107e0,0x00007f9961110f20] = 1856
stub code [0x00007f9961110f20,0x00007f9961110fc8] = 168
oops [0x00007f9961110fc8,0x00007f9961110fd0] = 8
metadata [0x00007f9961110fd0,0x00007f9961110fe8] = 24
public class CountNoRepPerms {
public static long recur(int[] hist2, int prev, int uniqueChars) {
if (hist2[0] == uniqueChars) return 1;
int out = 0;
for (int i = 1; i < hist2.length; i++) {
int count = i == prev ? hist2[i]-1 : hist2[i];
if (count > 0) {
hist2[i]--;
hist2[i-1]++;
out += count*recur(hist2, i-1, uniqueChars);
@MLLeKander
MLLeKander / LinkedList.java
Last active December 12, 2015 23:58
Speedy LinkedList implementation.
import java.util.*;
public class LinkedList<T> implements List<T> {
public class Node {
T data;
Node prev, next;
public Node() {}
public Node(T data_) {data = data_;}
}
import java.util.*;
class Generics {
public enum A { A1, A2 }
public enum B { B1, B2 }
public static List<? extends Enum<?>> listFactory(String[] args) {
if (args.length == 0) {
return new ArrayList<>(Arrays.asList(A.A1, A.A2));
} else {
@MLLeKander
MLLeKander / Test.java
Created September 22, 2015 22:06
Yaaay java...
import java.lang.reflect.Array;
class Sup<T> {
T[] arr;
@SuppressWarnings("unchecked")
public Sup(int r) {
arr = (T[])new Object[r];
//arr = (T[])Array.newInstance(Object.class, r);
}
2015-06-20 16:32:30,638 - automaton2000 - DEBUG - irc.freenode.net > PING :sendak.freenode.net
2015-06-20 16:32:30,639 - automaton2000 - DEBUG - irc.freenode.net < PONG :sendak.freenode.net
2015-06-20 16:32:45,656 - automaton2000 - DEBUG - irc.freenode.net > :Automaton2000!~Automaton@192.241.181.122 QUIT :Ping timeout: 767 seconds
2015-06-20 16:32:45,656 - automaton2000 - DEBUG - Bot quitting
2015-06-20 16:32:45,656 - automaton2000 - DEBUG - irc.freenode.net < QUIT :Automaton destroyed
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/home/michael/.local/lib/python2.7/site-packages/automaton2000/bot.py", line 102, in run
abstract class Person implements Comparable<Person> {
protected String lastName, firstName;
public Person(String lastName, String firstName) {
this.lastName = lastName;
this.firstName = firstName;
}
public String fullName() { return firstName+" "+lastName; }