Skip to content

Instantly share code, notes, and snippets.

@ellbur
ellbur / destruction.py
Created August 20, 2011 17:22
Testing the order of yield and destruction
class A:
def __del__(self):
print('Deleting')
def foo():
while True:
print 'Making'
a = A()
@ellbur
ellbur / Primes.java
Created October 12, 2011 04:25
Nth prime puzzle
public class Primes {
public static void main(String[] args) {
int n = 34;
int count = 0;
// for (int k=2; ; k++) {
int k = 2;
@ellbur
ellbur / Sevens.java
Created October 12, 2011 04:26
Sevens puzzle
public class Sevens {
public static void main(String[] args) {
int min = 1;
int max = 100;
int seven = 0;
for (int k=min; k<=max; k++) {
if ((k / 1) % 10 == 7) {
seven++;
@ellbur
ellbur / SmLr.java
Created October 12, 2011 04:28
Smallest Largest
public class SmLr {
public static void main(String[] args) {
int stop = IO.readInt();
int input = IO.readInt();
int highest = input;
int lowest = input;
while (input != stop) {
@ellbur
ellbur / Time.java
Created October 12, 2011 04:30
Timing puzzle
public class Time {
public static void main(String[] args) {
long now = System.currentTimeMillis();
int count = 0;
while (System.currentTimeMillis() - now <= 100) {
Math.sin(2);
count++;
@ellbur
ellbur / Collatz.java
Created October 12, 2011 04:31
Collatz puzzle
public class Collatz {
public static void main(String[] args) {
int n;
int count = 0;
int highest = 0;
int k = 1;
@ellbur
ellbur / Anagram.java
Created October 23, 2011 08:04
Anagram puzzle
public class Anagram {
public static void main(String[] args) {
String a = IO.readString();
String b = IO.readString();
boolean anagram = true;
int count = 0;
if (a.length()==b.length()) {
for ( int i = 0 ; i < a.length() ; i++) {
@ellbur
ellbur / Pal.java
Created October 23, 2011 08:05
Palindrome puzzle
public class Pal {
public static void main(String[] args) {
String word = "Racecar";
word = word.toLowerCase();
boolean ok = true;
for (int n=0; n<=word.length()-1; n++) {
if (word.charAt(n) == word.charAt(word.length() - n - 1)) {
@ellbur
ellbur / Pairs.java
Created October 31, 2011 06:18
Pairs
public class Pairs {
public static void main(String[] args) {
int[] cards = { 1, 2, 4, 1, 7 };
boolean pair = false;
for (int i=0; i<cards.length; i++) {
for (int j=i+1; j<cards.length; j++) {
if (cards[i] == cards[j]) {
@ellbur
ellbur / reversereverse.java
Created October 31, 2011 06:22
Reverse in place
public class reversereverse {
public static void main(String[] args){
int[] data = {1, 2, 3, 4, 5, 6, 7, 8, 9};
for (int i = 0; i<data.length/2; i++){
int a = data[i];
data[i] = data[data.length - i - 1];
data[data.length - i - 1] = a;
}
System.out.println(java.util.Arrays.toString(data));