## Awesome Acheivements

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

fazzone
Posts: 186
Joined: Wed Dec 10, 2008 9:38 pm UTC
Location: A boat

### Re: Awesome Acheivements

I just wrote a Java program to download a random wallpaper from www.socwall.com. Then I used it, in conjunction with wget and gconftool-2, in a bash script to change my wallpaper to a random new one every X seconds.
*/

Arancaytar
Posts: 1642
Joined: Thu Mar 15, 2007 12:54 am UTC
Location: 52.44°N, 13.55°E
Contact:

### Re: Awesome Acheivements

This isn't really an achievement as such, but my Python code has tripled in readability and terseness ever since I figured out you could assign by tuple.

Want to swap two variables?

Code: Select all

a, b = b, a

Want to iteratively calculate Fibonacci, with only two variables?

Code: Select all

a, b = 0, 1for i in xrange(n):  a, b = b, a + b
"You cannot dual-wield the sharks. One is enough." -Our DM. Xanthir
My HERO!!!
Posts: 5410
Joined: Tue Feb 20, 2007 12:49 am UTC
Contact:

### Re: Awesome Acheivements

Assigning by tuple is awesome.
(setf a b b (+ a b))
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

Earlz
Gets Obvious Implications
Posts: 785
Joined: Sat Jun 09, 2007 8:38 am UTC
Location: USA
Contact:

### Re: Awesome Acheivements

Arancaytar wrote:This isn't really an achievement as such, but my Python code has tripled in readability and terseness ever since I figured out you could assign by tuple.

Want to swap two variables?

Code: Select all

a, b = b, a

Want to iteratively calculate Fibonacci, with only two variables?

Code: Select all

a, b = 0, 1for i in xrange(n):  a, b = b, a + b

I've never much liked Python, but thats freaking amazing
My new blag(WIP, so yes it's still ugly..)
DEFIANCE! This is microtext. Zooming in digitally makes it worse. Get a magnifying glass.. works only on LCD

stephentyrone
Posts: 778
Joined: Mon Aug 11, 2008 10:58 pm UTC
Location: Palo Alto, CA

### Re: Awesome Acheivements

Earlz wrote:I've never much liked Python, but thats freaking amazing

Even more awesome -- there's a single x86 instruction that does exactly this (swap and add): xadd.
GENERATION -16 + 31i: The first time you see this, copy it into your sig on any forum. Square it, and then add i to the generation.

achilleas.k
Posts: 75
Joined: Wed Nov 18, 2009 3:21 pm UTC

### Re: Awesome Acheivements

headprogrammingczar wrote:This isn't nearly as impressive as what you guys are posting, but I might as well: http://www.eternal-silence.net/forums/i ... 502.0.html

Oooooooooh I love that game. Well, haven't played that much recently, but I tried it a while ago and it rocks The most exciting phrase to hear in science -the one that heralds new discoveries- is not "Eureka!" but "That's funny...". - Isaac Asimov

TheChewanater
Posts: 1279
Joined: Sat Aug 08, 2009 5:24 am UTC
Location: lol why am I still wearing a Santa suit?

### Re: Awesome Acheivements

I just started learning x86 assembly. I was able to compile a Hello World program, and even pick apart a mid-compiled C++ Hello World program.

I figure that next year in "Psuedo-Code Class", which the computer teacher says I "may" be able to get into when I'm a high school Sophomore, I'm going to at some point be asked, "Well, then what language do you know?".  http://internetometer.com/give/4279
No one can agree how to count how many types of people there are. You could ask two people and get 10 different answers.

M-x shell
Posts: 20
Joined: Thu May 21, 2009 2:07 am UTC

### Re: Awesome Acheivements

Please tell me if this is way too much code to put in one post (~38k, worked fine in preview), but 3D Tetris (in Java) is the most impressive thing I've ever written.

tetris.java

Code: Select all

/* * tetris.java * * Created on March 27, 2008, 10:27 AM * * @author Nathaniel Bude */import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.awt.image.*;class State {    Clump newbe, nextNoob;    Block[][][] space;    int serial;    public State( tetris game ) {        newbe = game.newbe.clone();        nextNoob = game.nextNoob.clone();        space = new Block[game.space.length][game.space.length][game.space.length];        for( int x = 0; x < game.space.length; x++ )            for( int y = 0; y < game.space[x].length; y++ )                for( int z = 0; z < game.space[x][y].length; z++ )                    if( game.space[x][y][z] == null ) space[x][y][z] = null;                    else space[x][y][z] = game.space[x][y][z].clone();    }    public void instate( tetris game ) {        for( int x = 0; x < space.length; x++ )            for( int y = 0; y < space[x].length; y++ )                for( int z = 0; z < space[x][y].length; z++ )                    if( space[x][y][z] == null ) game.space[x][y][z] = null;                    else game.space[x][y][z] = space[x][y][z].clone();        game.newbe = newbe.clone();        game.nextNoob = nextNoob.clone();        game.newbe.put();    }    public void redo( tetris game ) {        game.newbe = newbe.clone();        game.newbe.put();        game.nextNoob = nextNoob.clone();    }}public class tetris extends JPanel implements Runnable, KeyListener {    State[] undoStack = new State ;    Block[][][] space = new Block ;    Clump newbe, nextNoob;    double latitude = -.5, longitude = 2;    boolean gameOver = false;    int score = 0, moveIndex = 0, totalMoves = 0;    int startSleepTime = 300, sleepTime = startSleepTime;    boolean paused = false, fast = false, autospeed = true;    int dx, dy;    AI al = new AI();    boolean alon = false;    ControlPanel control = new ControlPanel( this );    public tetris() {        restart();        new Thread( this ).start();        setFocusable( true );        addKeyListener( this );    }        public boolean drop() {        if( moveIndex+1 < totalMoves )            undoStack[ moveIndex+1 ].redo( this );        else {            newbe = nextNoob; // as promised            ( nextNoob = new Clump( space ) ).remove(); // still looking to the future            newbe.put(); // on the other hand...            totalMoves++;         }        undoStack[ moveIndex++ ] = new State( this ); // i want to remember this moment        return nextNoob.gameOver;    }    public void undo( int regress ) {        if( moveIndex < regress ) return;        moveIndex -= regress;        undoStack[ moveIndex ].instate( this );        repaint();    }        public void keyPressed( KeyEvent e ) {            synchronized( al ) {                switch( e.getKeyCode() ) {                    case KeyEvent.VK_LEFT : longitude += .1; break;                    case KeyEvent.VK_RIGHT : longitude -= .1; break;                    case KeyEvent.VK_UP : latitude += .1; break;                    case KeyEvent.VK_DOWN : latitude -= .1; break;                    case KeyEvent.VK_R : newbe.move( new int[] { 0, 1, 0 } ); break;                    case KeyEvent.VK_Q : newbe.move( new int[] { 0, -1, 0 } ); break;                    case KeyEvent.VK_3 : newbe.move( new int[] { -1, 0, 0 } ); break;                    case KeyEvent.VK_E : newbe.move( new int[] { 1, 0, 0 } ); break;                    case KeyEvent.VK_W : newbe.rotate( 0 ); break;                    case KeyEvent.VK_2 : newbe.rotate( 1 ); break;                    case KeyEvent.VK_4 : newbe.rotate( 2 ); break;                    case KeyEvent.VK_ESCAPE : restart(); break;                    case KeyEvent.VK_SPACE : fast = true; break;                    case KeyEvent.VK_U : undo(1); break;                    case KeyEvent.VK_P : paused = !paused; break;                    case KeyEvent.VK_H : al.solve( this ); break;                } }             repaint();    }    public void keyReleased( KeyEvent e ) {}    public void keyTyped( KeyEvent e ) {}        public synchronized void run() {        int f = 0;        while( true ) {            while( !gameOver && !paused ) {                if( autospeed ) sleepTime = ( startSleepTime * 100 ) / ( 100 + score );                else sleepTime = control.time_out();                if( fast ) sleepTime = 20;                if( !newbe.move( new int[] { 0, 0, -1 } ) ) {                    collapse();                    if( gameOver = drop() ) break;                    score++;                    f = 0;                    fast = false;                }                if( f++ == 3 )                    //al.solve( this );                    al.findSolution( this );                if( alon /*&& 2*(int)(f/2) == f*/ ) al.reduce( this );                //longitude += control.spin;                repaint();                try { Thread.sleep( sleepTime ); } catch( InterruptedException iex ) {}            }            repaint();            while( paused || gameOver )                try { Thread.sleep( 50 ); } catch( InterruptedException iex ) {}        }    }        public void paint( Graphics h ) {        Graphics2D g = (Graphics2D) h;        g.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );        g.setColor( Color.black );        g.fillRect( 200, 200, 180, 180 );        g.fillRect( 400, 100, 180, 420 );        g.fillRect( 600, 100, 180, 420 );        g.fillRect( 0, 0, getWidth(), getHeight() );        g.setColor( Color.gray );        int l = 600, b = 500;        double mag = 20.0;        int startX = 0, startY = 0, startZ = 0, dz = 1; dx = 1; dy = 1;        if( Math.sin( longitude ) < 0 ) { startX = space.length - 1; dx = -1; }        if( Math.cos( longitude ) > 0 ) { startY = space.length - 1; dy = -1; }        if( Math.sin( latitude ) > 0 ) { startZ = space.length - 1; dz = -1; }        new Box( -2, 0, -2, space.length-2, 0, space.length-2, new RGB( 100, 100, 100 ) ).draw( g, latitude, longitude, mag, l, b );        drawSpace( g, space, latitude, longitude, mag, l, b );        if( Math.sin( latitude ) > 0 )            new Box( -2, 0, -2, space.length-2, 0, space.length-2, new RGB( 100, 100, 100 ) ).draw( g, latitude, longitude, mag, l, b );        g.setColor( Color.white );         g.setFont( new Font( "Times New Roman", Font.PLAIN, 20 ) );         g.drawString( "Score: " + score, 200, 200 );         if( gameOver ) {            g.setFont( new Font( "Times New Roman", Font.BOLD, 60 ) );            g.drawString( "Game Over.", 100, 100 );         }         Dot d = new Dot(0,0,0);         d.vis( latitude, longitude, mag, l, b );         g.drawLine( 100, 500, 100 - (int)d.camx, 500 - (int)d.camz );         g.drawOval( 50, 450, 100, 100 );         control.display( g );    }        public void drawSpace( Graphics2D g, Block[][][] space2, double lat, double lon, double mag, int left, int bottom ) {        int startX = 0, startY = 0, startZ = 0, dz = 1; dx = 1; dy = 1;        if( Math.sin( lon ) < 0 ) { startX = space2.length - 1; dx = -1; }        if( Math.cos( lon ) > 0 ) { startY = space2.length - 1; dy = -1; }        if( Math.sin( lat ) > 0 ) { startZ = space2.length - 1; dz = -1; }        synchronized( al ) {        for( int x = startX; x < space2.length && x >= 0; x += dx )            for( int y = startY; y < space2.length && y >= 0; y += dy )                for( int z = startZ; z < space2.length && z >= 0; z += dz ) {                    if( space2[x][y][z] != null ) {                        new Box( x - (dx-1)/2 -2, z - (dz-1)/2, y - (dy-1)/2 -2, x + (dx+1)/2 -2, z + (dz+1)/2, y + (dy+1)/2 -2,                                space2[x][y][z].color ).draw(g,lat,lon, mag, left, bottom );                    }                }        }        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float)0.5 ));        RGB grey = new RGB( 255, 000, 000 ); // my little joke (actually, it's historical)        RGB cyan = new RGB( 000, 255, 255 );        if( dz > 0 ) {            for( int i = 0; i < 5; i++ ) {                new Box( -2+i, 15, -2, -2+i+0.05, 15, 2, grey ).draw( g, lat, lon, mag, left, bottom );                new Box( -2, 15, -2+i, 2, 15, -2+i+0.05, grey ).draw( g, lat, lon, mag, left, bottom );            }            for( int x = 0; x < 4; x++ )                for( int y = 0; y < 4; y++ )                    if( newbe.shadows( x, y ) )                        new Box( x-2, 15, y-2, x-2+1, 15, y-2+1, cyan ).draw( g, lat, lon, mag, left, bottom );        }        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float)1.0 ));    }        public void collapse() {        for( int z = 0; z < space.length; z++ ) {            int c = 0;            for( int x = 0; x < space.length; x++ )                for( int y = 0; y < space.length; y++ )                    if( space[x][y][z] != null )                        c++; else break;            if( c == space.length * space.length ) {                for( int x = 0; x < space.length; x++ )                    for( int y = 0; y < space.length; y++ )                        space[x][y][z] = null;                try { Thread.sleep( sleepTime/10 ); } catch( InterruptedException e ) {}                repaint();                for( int z2 = z; z2 + 1 < space.length; z2++ )                    for( int x = 0; x < space.length; x++ )                        for( int y = 0; y < space.length; y++ )                            space[x][y][z2] = space[x][y][z2+1];                try { Thread.sleep( sleepTime/10 ); } catch( InterruptedException e ) {}                repaint();                z--;            }        }    }        public void restart() {        for( int x = 0; x < space.length; x++ )            for( int y = 0; y < space.length; y++ )                for( int z = 0; z < space.length; z++ )                    space[x][y][z] = null;        nextNoob = new Clump( space );        nextNoob.remove();        gameOver = false;        score = 0;        drop();    }        public static void main(String[] args) {        JFrame frame = new JFrame( "Tetris" );        frame.getContentPane().add( new tetris() );        frame.setSize( 1200, 750 );        frame.setVisible( true );        frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );    }    }class Clump {    static int[] size = {4,4};    Block[] blocks = new Block[(int)Math.round( Math.random() * (size-size) ) + size ];    boolean gameOver = false;    public Clump() {}    public Clump( Block[][][] space ) {        int[] coords = { 0, 0, space.length - 1 };        RGB color = new RGB( 255 - (int)(Math.random()*200), 255 - (int)(Math.random()*200), 255 - (int)(Math.random()*200) );        for( int i = 0; i < blocks.length; i++ ) {            blocks[i] = new Block( coords, space, color );            //blocks[i].color = color;            blocks[i].put();            if( i == blocks.length - 1 ) break;            int[] change = { 0, 0, 0 };            int c = 0;            if( i > 1 && Math.random() < .25 ) { // backtrack sometimes                Block save = blocks[i];                coords = ( blocks[i] = blocks[i-1] ).coord;                blocks[i-1] = save;            }            while( !blocks[i].canMove( change ) ) {                for( int d = 0; d < coords.length; d++ )                    change[d] = 0;                change[(int)( Math.random() * 3 )] = (int)( Math.random() * 2 ) * 2 - 1;                if( c > 1000 ) { gameOver = true; Block[] ocks = new Block[i-1];                for( int b = 0; b < ocks.length; b++ ) ocks[b] = blocks[b]; blocks = ocks; return; }                if( c++ > 100 ) if( boxed_in() ) { gameOver = true; change = new int[] {0,0,0}; break; }            }            coords = new int[] { coords + change, coords + change, coords + change };        }    }    public boolean boxed_in() {        for( int b = 0; b < blocks.length && blocks[b] != null; b++ )            if( !blocks[b].boxed_in() ) return false;        return true;    }    /*public boolean canMove( int[] delta ) {        for( int b=0; b<blocks.length; b++ )            if( !blocks[b].canMove(delta) )                return false;        return true;        }*/    public boolean shadows( int x, int y ) {        for( int i = 0; i < blocks.length; i++ )            if( blocks[i].coord == x && blocks[i].coord == y )                return true;        return false;    }    public boolean move( int[] delta ) {        for( int i = 0; i < blocks.length; i++ )            blocks[i].remove();        for( int i = 0; i < blocks.length; i++ )            if( !blocks[i].canMove( delta ) ) {                for( int n = 0; n < blocks.length; n++ )                    blocks[n].put();                return false;            }        for( int i = 0; i < blocks.length; i++ ) {            blocks[i].move( delta );            blocks[i].put();        }        return true;    }    public boolean dumb_rotate( int axis ) {        for( int i = 0; i < blocks.length; i++ )            blocks[i].remove();        int d1, d2;        if( axis == 0 ) { d1 = 1; d2 = 2; }        else if( axis == 1 ) { d1 = 0; d2 = 2; }        else if( axis == 2 ) { d1 = 0; d2 = 1; }        else return true; // it didn't rotate, but then, the caller didn't really want it to. did he?                int [][] deltas = new int [blocks.length];        for( int i = 0; i < blocks.length; i++ ) {             deltas[i] = new int[] { 0, 0, 0 };            int rad1 = blocks[i].coord[d1] - blocks.coord[d1];            int rad2 = blocks[i].coord[d2] - blocks.coord[d2];            deltas[i][d1] = - rad1 - rad2;            deltas[i][d2] = - rad2 + rad1;        }                for( int i = 0; i < blocks.length; i++ )            if( !blocks[i].canMove( deltas[i] ) ) {                for( int n = 0; n < blocks.length; n++ )                    blocks[n].put();                return false;            }        for( int i = 0; i < blocks.length; i++ ) {            blocks[i].move( deltas[i] );            blocks[i].put();        }        return true;    }    public void unmove( int[] delta ) {        //move( new int[] { -delta, -delta, -delta } ); // this took me forever to find        move( new int[] { -delta, -delta, -delta } );    }    public boolean rotate( int axis ) {        if( dumb_rotate( axis ) ) return true; // even my dumb cousin can do it. What am i doing here?        int[] try_ways = { 1, 0, 0 };        /*while( true ) {            while( move( try_ways ) )                if( dumb_rotate( axis ) ) return true;            if( try_ways > 0 ) try_ways = -1; // if you're going right, try going left            else if( try_ways < 0 ) { try_ways = 0; try_ways = 1; } // if going left, try forward            else if( try_ways > 0 ) try_ways = -1; // if forward, try backward            else if( try_ways < 0 ) break; // if backward, you've tried everything. End this madness.        }*/        // ^that should work, but because it doesn't... OVERKILL:        for( int dx = -3; dx <= 3; dx++ )            for( int dy = -3; dy <= 3; dy++ )                if( move( new int[] {dx,dy,0} ) ) {                    if( dumb_rotate( axis ) ) return true;                    unmove( new int[] {dx,dy,0} ); // turns out, this was the problem                } //turning off overkill // turning back on (underkill sometimes doesn't work)        // System.out.println( "impossible" ); // the impossible no longer happens!        return false;    }    public void put() {        for( int i = 0; i < blocks.length; i++ )            blocks[i].put();    }    public void remove() {        for( int i = 0; i < blocks.length; i++ )            blocks[i].remove();    }    public Clump clone() {        Clump clone = new Clump();        clone.blocks = new Block[ blocks.length ];        for( int b = 0; b < blocks.length; b++ )            clone.blocks[b] = new Block(new int[]{blocks[b].coord,blocks[b].coord,blocks[b].coord},blocks[b].space,blocks[b].color);        return clone;    }}class Block {    Block[][][] space;    int[] coord;    int[] bounds;    RGB color;    public Block( int[] coords, Block[][][] room, RGB col ) {        coord = coords;        space = room;        bounds = new int[] { space.length, space.length, space.length };        color = col;    }    public boolean boxed_in() {        for( int axis = 0; axis < 3; axis++ ) {            int[] adjacent = new int[] { coord, coord, coord };            adjacent[axis] -= 1;            try{ if( space[ adjacent ][ adjacent ][ adjacent ] == null ) return false; } catch( ArrayIndexOutOfBoundsException e ){}            adjacent[axis] += 2;            try{ if( space[ adjacent ][ adjacent ][ adjacent ] == null ) return false; } catch( ArrayIndexOutOfBoundsException e ){}        }        return true;    }    public boolean canMove( int[] delta ) {        for( int d = 0; d < 3; d++ )            if( coord[d] + delta[d] < 0 || coord[d] + delta[d] >= bounds[d] )                return false;        if( findSpace( coord, delta ) != null )            return false;        return true;    }    public void move( int[] delta ) {        for( int d = 0; d < 3; d++ )            coord[d] += delta[d];    }    public Block find( int[] a ) {        return space[ a ][ a ][ a ];    }    public Block findSpace( int[] a, int[] b ) {        return space[ a+b ][ a+b ][ a+b ];    }    public void remove() {        space[coord][coord][coord] = null;    }    public void put() {        space[ coord ][ coord ][ coord ] = this;    }    public int[] bounds() {        return new int[] { space.length, space.length, space.length };    }    public Block clone() {        return new Block(new int[]{coord,coord,coord},space,color);    }}class RGB {    int red, green, blue;    public RGB( int r, int g, int b ) {        red = r; green = g; blue = b;    }}class Box {    Dot [] corners;    RGB color;    public Box( double x1, double y1, double z1, double x2, double y2, double z2, RGB col ) {        corners = new Dot[] { new Dot(x1,y1,z1), new Dot(x1,y1,z2), new Dot(x1,y2,z1), new Dot(x1,y2,z2),                new Dot(x2,y1,z1), new Dot(x2,y1,z2), new Dot(x2,y2,z1), new Dot(x2,y2,z2) };        color = col;    }        public void draw( Graphics2D g, double X, double Y, double zoom, int left, int bottom ) {        g.setColor( new Color( color.red, color.green, color.blue ) );        Point[] vCorners = new Point ;        for( int i = 0; i < 8; i++ )            vCorners[i] = corners[i].vis( X, Y, zoom, left, bottom );//        for( int i = 0; i < 8; i++ )//            for( int n = 0; n < 8; n++ ) {//                Point p1 = vCorners[i];//                Point p2 = vCorners[n];//                g.drawLine( p1.x, p1.y, p2.x, p2.y );//            }        int[] x = new int , y = new int ;        int[] schedule = { 7, 3, 1, 5 };        g.setColor( new Color( color.red / 3, color.green / 3, color.blue / 3 ) );        for( int i = 0; i < 4; i++ ) {            x[i] = vCorners[schedule[i]].x;            y[i] = vCorners[schedule[i]].y;        }        g.fillPolygon( x, y, 4 );                schedule = new int[] { 4, 5, 7, 6 };        g.setColor( new Color( color.red / 2, color.green / 2, color.blue / 2 ) );        for( int i = 0; i < 4; i++ ) {            x[i] = vCorners[schedule[i]].x;            y[i] = vCorners[schedule[i]].y;        }        g.fillPolygon( x, y, 4 );                schedule = new int[] { 3, 2, 6, 7 };        g.setColor( new Color( color.red * 2/3, color.green * 2/3, color.blue * 2/3 ) );        for( int i = 0; i < 4; i++ ) {            x[i] = vCorners[schedule[i]].x;            y[i] = vCorners[schedule[i]].y;        }        g.fillPolygon( x, y, 4 );            }    }class Line {    double x1, y1, z1, x2, y2, z2;    double latitude, longitude;    public Line( double X1, double Y1, double Z1, double X2, double Y2, double Z2 ) {        x1 = X1;        y1 = Y1;        z1 = Z1;        x2 = X2;        y2 = Y2;         z2 = Z2;    }    public void draw( Graphics2D g, double X, double Y, double zoom ) {                latitude = X; longitude = Y;                double vx1 = x1 * Math.cos( longitude ) + z1 * Math.sin( longitude );        double vz1 = x1 * Math.sin( longitude ) - z1 * Math.cos( longitude );        double vy1 = y1 * Math.cos( latitude ) + vz1 * Math.sin( latitude );                double vx2 = x2 * Math.cos( longitude ) + z2 * Math.sin( longitude );        double vz2 = x2 * Math.sin( longitude ) - z2 * Math.cos( longitude );        double vy2 = y2 * Math.cos( latitude ) + vz2 * Math.sin( latitude );                g.drawLine(  (int)( vx1 * zoom ) + 600, 400 - (int)( vy1 * zoom ), (int) ( vx2 * zoom ) + 600, 400 - (int)( vy2 * zoom ) );    }    }class Dot {    double x, y, z;    double camx, camy, camz;    double pi = Math.PI;    Dot( double X, double Y, double Z ) {        x = X; y = Y; z = Z;            }    public Point vis( double latitude, double longitude, double zoom, int left, int bottom ) {        zoom *= 1.5;        double X = x * Math.cos( longitude ) + z * Math.sin( longitude );        double Z = x * Math.sin( longitude ) - z * Math.cos( longitude );        double Y = y * Math.cos( latitude ) + Z * Math.sin( latitude );        //zoom *= 1 + Math.pow( x*x + y*y + z*z, .5 ) / 50;        double rad = 50.0;        camx = rad * Math.cos( -latitude ) * Math.cos( -longitude );        camy = rad * Math.sin( -latitude );        camz = rad * Math.cos( -latitude ) * Math.sin( -longitude );        double dx = camx - x, dy = camy - y, dz = camz - z;        double distance = Math.pow( dx*dx + dy*dy + dz*dz, .5 );        Cam cam = new Cam();        cam.here = new double[] { camx, camy, camz };        cam.angle = new double[] { latitude, longitude, 0 };        double[] point = cam.flatten( new double[] {x,y,z} );        //X = point + 400; Y = point+300;        //distance = Math.pow( x*x + y*y + z*z, .5 ) + 50;        //zoom *= rad / distance;        //System.out.println( distance );        return new Point( (int)( zoom*X + left ), (int)( bottom - zoom*Y ) );//        double lon = Math.atan( dx / dz, dx ) - longitude;//        double lat = Math.atan( dy / dz, dx ) - latitude;//        zoom *= 20;//        return new Point( (int)( zoom*lon + 900 ), (int)( 400 - zoom*lat ) );    }    public Point camera( double latitude, double longitude, double dist, double zoom ) {        return null;    }}class Cam {    double[] here = {0,0,0};    double[] angle = {0,0,0};    public double[] relatize( double[] absolute ) {        double[] relative = new double , agl = new double;        double distance = 0;        for( int d= 0; d < 3; d++ )            relative[d] = absolute[d] - here[d];        relative = rotate( relative, angle );        return relative;    }    public double[] rotate( double[] point, double[] theta ) {        double distance = 0;        double[] agl = new double;                distance = Math.hypot( point, Math.hypot( point, point ) );        agl = Math.atan2( point, point ) - theta;        point = distance * Math.sin( agl );        agl = Math.atan2( point, point ) - theta;        point = distance * Math.sin( agl );        point = Math.abs( distance * Math.cos( agl ) * Math.cos( agl ) );        if( Math.cos( agl ) < 0  || Math.cos( agl ) < 0 ) point = -point;                /*agl = Math.atan2( point, point ) - theta;        distance = Math.hypot( point, point );        point = distance * Math.cos( agl );        point = distance * Math.sin( agl );*/                return point;    }    public double[] perspect( double[] p ) {        return new double[] { p/Math.abs( p ), p/Math.abs( p ), 0 };    }    public double[] flatten( double[] point ) {        point = relatize( point );        //if( point <= 0 ) return null;        return perspect( point );    }}class AI {    Action[] solution = new Action ;    int progress = 0;    public synchronized void reduce( tetris puzzle ) {        if( solution[progress] != null ) solution[progress++].enact( puzzle.newbe );         puzzle.newbe.put();    }    public synchronized void solve( tetris puzzle ) {        findSolution( puzzle );        for( int i = 0; solution[i] != null; i++ )            solution[i].enact( puzzle.newbe );    }    public synchronized void findSolution( tetris puzzle ) {        solution = new Action;        progress = 0;        Clump saveNewbe = puzzle.newbe.clone();        Action[] trial = new Action ;// solution = new Action ;        int best = -1000000, c = 0;        Clump newbe1 = puzzle.newbe.clone();        for( int r1 = -1; r1 < 3; r1++ ) {            ( trial = new Action( r1, 0, 'r' ) ).enact( puzzle.newbe );            Clump newbe2 = puzzle.newbe.clone();            for( int r2 = -1; r2 < 3; r2++ ) {                                ( trial = new Action( r2, 0, 'r' ) ).enact( puzzle.newbe );                Clump newbe3 = puzzle.newbe.clone();                for( int r3 = -1; r3 < 3; r3++ ) {                    ( trial = new Action( r3, 0, 'r' ) ).enact( puzzle.newbe );                     Clump newbe4 = puzzle.newbe.clone();                    for( int dx = -3; dx <= 3; dx++ ) {                            if( !( trial = new Action( 0, dx, 'm' ) ).enact( puzzle.newbe ) ) continue;                        Clump newbe5 = puzzle.newbe.clone();                        for( int dy = -3; dy <= 3; dy++ ) {                                                        if( !( trial = new Action( 1, dy, 'm' ) ).enact( puzzle.newbe ) ) continue;                            c++;                            int utility = examine( puzzle );                            if( utility > best ) {                                for( int i = 0; i < 10; i++ ) solution[i] = trial[i];                                best = utility;                            }                        revert( puzzle, newbe5 ); }                    revert( puzzle, newbe4 ); }                revert( puzzle, newbe3 ); }            revert( puzzle, newbe2 ); }        revert( puzzle, newbe1 ); }    }    public static void revert( tetris puzzle, Clump newbe ) {        puzzle.newbe.remove();        puzzle.newbe = newbe.clone();        puzzle.newbe.put();    }    public static void evolve( tetris puzzle ) {        Clump saveNewbe = puzzle.newbe.clone();        Action[][] trials = new Action;        int best = -1000000000;        int t = 1;        int track, step;        for( int r = 0; r < 3; r++ ) {            step = 0;            for( int bi = 0; bi < 2; bi++ ) {                trials[t++][step++] = new Action( r, 0 );                if( bi == 1 ) {                    trials[t] = trials[t-1];                    trials[t][step++] = new Action( r, 0 );                }                for( int a = 0; a <= 1; a++ )                    for( int s = -1; s <= 1; s += 2 )                        for( int d = 1; d < 4; d++ ) {                            trials[t][step-1] = trials[t-1][step-1];                            trials[t++][step] = new Action( a, s*d );                        }            }        }        Action[] solution = trials;        for( int i = 0; i < t; i++ ) {            for( int n = 0; n < 2 && trials[i][n] != null; n++ )                trials[i][n].enact( puzzle.newbe );            int utility = examine( puzzle );            if( utility >= best ) {                best = utility;                solution = trials[i];            }            puzzle.newbe.remove();            puzzle.newbe = saveNewbe.clone();            puzzle.newbe.put();        }        for( int n = 0; n < solution.length && solution[n] != null; n++ )             solution[n].enact( puzzle.newbe );    }    public static void decide( tetris puzzle ) {        Action guess, bestGuess = null;        int asis, best, utility;        best = asis = examine( puzzle );        for( int i = 0; i < 5; i++ ) {            Clump saveNewbe = puzzle.newbe.clone();            ( guess = randomAct() ).enact( puzzle.newbe );            utility = examine( puzzle );            if( utility >= best ) {                best = utility;                bestGuess = guess;            }            puzzle.newbe.remove();            puzzle.newbe = saveNewbe;        }        if( bestGuess != null )            bestGuess.enact( puzzle.newbe );    }    public static Action randomAct() {        return new Action( (int)( Math.random()*3 ), (int)( 3*Math.random() ) - 1 );    }    public synchronized static int examine( tetris puzzle ) {        Clump saveNewbe = puzzle.newbe.clone();        saveNewbe.remove();        int utility = 0;        while( puzzle.newbe.move( new int[] { 0, 0, -1 } ) ) ;//utility++;        for( int i = 0; i < puzzle.newbe.blocks.length; i++ )            for( int z = puzzle.newbe.blocks[i].coord - 1; z >= 0; z-- )                if( puzzle.space[puzzle.newbe.blocks[i].coord][puzzle.newbe.blocks[i].coord][z] == null )                    utility -= 4; else break;        for( int n = 0; n < puzzle.newbe.blocks.length; n++ ) utility -= puzzle.newbe.blocks[n].coord;        //utility -= countGaps( puzzle.space );        //utility += fullness( puzzle.space );        utility -= count_tunnels( puzzle.space ) * 10;        puzzle.newbe.remove();        puzzle.newbe = saveNewbe;        saveNewbe.put();        return utility;    }    public static int count_tunnels( Block[][][] space ) { // seems to help, but it is expensive! update: not        int[] p = {0,0,1};        int fullCount = 16, tc = 0;        while( p++ < space.length && fullCount > 0 ) {            fullCount = 0;            for( p = 0; p < space.length; p++ )                for( p = 0; p < space.length; p++ )                    if( is_tunnel( space, p ) )                        tc++;                    else if( space[p][p][p] != null ) fullCount++;        }        return tc;    }    public static int fullness( Block[][][] space ) {        int full = 0, empty = 0, nearest = 0;        for( int z = 0; z < space.length; z++ ) {            empty = 0;            for( int x =0; x < space.length; x++ ) {                for( int y = 0; y < space.length; y++ )                    if( space[x][y][z] == null ) empty++;            }            if( empty == 0 ) full++;            else if( empty < nearest || z == 0 ) nearest = empty;            if( empty == space.length * space.length ) break;        }        return full * 5 - nearest;    }    public static boolean is_tunnel( Block[][][] space, int[] p ) {        if( space[p][p][p] == null && ( p+1 >= space.length || space[p+1][p][p] != null ) )        if ( ( p-1 < 0 || space[p-1][p][p] != null ) && ( p-1 < 0 || space[p][p-1][p] != null ) )        if ( ( p+1 >= space.length || space[p][p+1][p] != null ) )  {            for( int z = p; z > p-3; z-- )                if( space[p][p][z] != null )                    return false;            return true;        } return false;    }    public static int countGaps( Block[][][] space ) {        int gaps = 0;        for( int z = 0; z < space.length; z++ ) {            int subgaps = 0;            for( int y = 0; y < space.length; y++ )                for( int x = 0; x < space.length; x++ )                    if( space[x][y][z] == null )                        subgaps++;            if( subgaps < space.length * space.length )                gaps += subgaps;            else break;        }        return gaps;    }}class Action {    char type; // r/m (rotate/move)    int axis, amount;    public Action( int dimension, int magnitude, char kind ) {        axis = dimension;        amount = magnitude;        type = kind;    }    public Action( int dimension, int magnitude ) {        axis = dimension;        amount = magnitude;        if( amount == 0 || axis == 2 ) type = 'r';        else type = 'm';    }    public boolean enact( Clump clump ) {        if( type == 'r' ) {            return clump.rotate( axis );        } else {            int[] delta = {0,0,0};            delta[axis] = amount;            return clump.move( delta );        }    }}class ControlPanel implements MouseListener, Runnable {    Rectangle bounds = new Rectangle( 800, 100, 300, 200 );    Rectangle AItoggle = new Rectangle( 200, 50, 50, 50 );    Rectangle speedScale = new Rectangle( 60, 160, 220, 20 );    Rectangle spinScale = new Rectangle( 140, 130, 140, 10 );    Rectangle limboWindow = new Rectangle( 20, 40, 100, 100 );    Rectangle autospeedCheck = new Rectangle( speedScale.x - 20, speedScale.y + 3, speedScale.height-6, speedScale.height-6 );    Rectangle clumpsizeB = new Rectangle( 140, 40, 20, 80 );    double spin = 0;    BufferedImage image = new BufferedImage( 300, 200, BufferedImage.TYPE_INT_ARGB );    Graphics2D drawer = (Graphics2D)image.getGraphics();    tetris game;    int speed_measure = 110;    public ControlPanel( tetris host ) {        game = host;        game.setFocusable( true );        game.addMouseListener( this );        new Thread( this ).start();    }    public void run() {        while( true ) {            try { Thread.sleep( 40 ); } catch( InterruptedException ie ) {}            game.longitude += spin;            game.repaint(); }    }        public void mousePressed( MouseEvent e ) {        if( bounds.contains( e.getPoint() ) ) {            int x = e.getX() - bounds.x, y = e.getY() - bounds.y;            if( AItoggle.contains( x, y ) )                game.alon = !game.alon;            if( speedScale.contains( x, y ) )                speed_measure = x - speedScale.x;            if( spinScale.contains( x, y ) )                spin = -(double)( ( x - spinScale.x - spinScale.width/2 )/4 ) / 250;            if( autospeedCheck.contains( x, y ) )                game.autospeed = !game.autospeed;            if( clumpsizeB.contains( x, y ) ) {                int h = ( clumpsizeB.y - y + clumpsizeB.height ) / 10;                if( h < 1 || h > 7 );                else if( h < Clump.size ) Clump.size = h;                else if( h > Clump.size ) Clump.size = h;                //else if( Math.abs( Clump.size - h ) < Math.abs( Clump.size - h ) )                else if( x < clumpsizeB.x + clumpsizeB.width/2 ) Clump.size = h; // 09/02/26                else Clump.size = h;            }            repaint();            game.repaint( this.bounds );        }    }    public int time_out() {        return (int) ( 500.0 * Math.pow( (double)speed_measure/110.0, 2 ) );    }    public Block[][][] limbo() {        Block[][][] space = new Block [game.space.length][game.space.length];        if( game.nextNoob == null ) return space;        Clump next = game.nextNoob.clone();        for( int i = 0; i < next.blocks.length; i++ ) next.blocks[i].space = space;        int h = 0;        for( int i = 0; i < next.blocks.length; i++ ) h += next.blocks[i].coord;        for( int i = 0; i < next.blocks.length; i++ ) next.blocks[i].coord -= h/next.blocks.length - next.blocks.length/2;        next.put();        return space;    }    public void mouseReleased( MouseEvent e ) {}    public void mouseEntered( MouseEvent e ) {}    public void mouseExited( MouseEvent e ) {}    public void mouseClicked( MouseEvent e ) {}    public void repaint() {        drawer.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON  );        drawer.setColor( Color.darkGray );        drawer.fill3DRect( 0, 0, bounds.width, bounds.height, true );        drawer.fill3DRect( AItoggle.x, AItoggle.y, AItoggle.width, AItoggle.height, false );        drawer.fill3DRect( speedScale.x, speedScale.y, speedScale.width, speedScale.height, false );        drawer.fill3DRect( spinScale.x, spinScale.y, spinScale.width, spinScale.height, false );        drawer.fill3DRect( limboWindow.x, limboWindow.y, limboWindow.width, limboWindow.height, false );        drawer.fill3DRect( clumpsizeB.x, clumpsizeB.y, clumpsizeB.width, clumpsizeB.height, false );        game.drawSpace( drawer, limbo(), -.5, 2, 10.0, limboWindow.x + 50, limboWindow.y + 90 );        drawer.setColor( Color.red );        if( game.alon )            drawer.fillOval( AItoggle.x + 4, AItoggle.y + 4, AItoggle.width - 8, AItoggle.height - 8 );        drawer.fillOval( spinScale.x + (int)( -spin*1000 + spinScale.width/2 ) -4, spinScale.y+1, 8, spinScale.height-3 );        drawer.drawLine( spinScale.x + spinScale.width/2, spinScale.y-2, spinScale.x + spinScale.width/2, spinScale.y + spinScale.height );        if( game.autospeed ) drawer.setColor( Color.lightGray );        drawer.fillRect( speedScale.x+1, speedScale.y+1, speed_measure, speedScale.height-2 );        drawer.setColor( Color.black );        if( game.autospeed ) drawer.fill( autospeedCheck );        else drawer.draw( autospeedCheck );        drawer.drawString( "Auto", autospeedCheck.x - 30, autospeedCheck.y+10 );        for( int i = 1; i <= 7; i++ ) { if( i == Clump.size ) drawer.setColor( Color.blue );            drawer.fillRect( clumpsizeB.x+4, clumpsizeB.y + clumpsizeB.height - i*10 - 5, clumpsizeB.width-8, 3 );            if( i == Clump.size ) drawer.setColor( Color.black );        }    }    public void display( Graphics2D g ) {        repaint();        g.drawImage( image, bounds.x, bounds.y, null );    }}

The result of gradual additions and tinkering over more than a year, the source code may induce a seizure, but the end result, when compiled, is actually pretty neat. Basically, I wrote everything from scratch except for some basic 2D graphics from the Java library. And I wrote an "AI" to play the game automatically. It's the exact same rules as tetris, extended into 3 dimensions. Controls are at the upper left part of the keyboard and arrow keys, if anyone's interested in trying it out.

Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

### Re: Awesome Acheivements

It's possible to upload attachments, just sayin'.

Also, it might be a good idea to split multiple classes into multiple code blocks, so people don't have to perform surgery on the text to get it running.
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.

Cosmologicon
Posts: 1806
Joined: Sat Nov 25, 2006 9:47 am UTC
Location: Cambridge MA USA
Contact:

### Re: Awesome Acheivements

Hey that reminds me, I was pretty pleased with the pure python/pygame/OpenGL game I was able to write in 3 days when I first learned OpenGL. For some reason I'm proud of the fact that it's a single 28k code file, with no extra data files. The coding could have been a bit better, but for something that was just an exercise to learn a new library, it turned out not half bad.

nyeguy
Posts: 580
Joined: Sat Aug 04, 2007 5:59 pm UTC

### Re: Awesome Acheivements

M-x shell wrote:Please tell me if this is way too much code to put in one post (~38k, worked fine in preview), but 3D Tetris (in Java) is the most impressive thing I've ever written.

snip...

The result of gradual additions and tinkering over more than a year, the source code may induce a seizure, but the end result, when compiled, is actually pretty neat. Basically, I wrote everything from scratch except for some basic 2D graphics from the Java library. And I wrote an "AI" to play the game automatically. It's the exact same rules as tetris, extended into 3 dimensions. Controls are at the upper left part of the keyboard and arrow keys, if anyone's interested in trying it out.

I went ahead, broke up the source code, and compiled it. I have the source code and the class files; run tetris.class to play the game.
Attachments
3dtetris.zip

Xeio
Friends, Faidites, Countrymen
Posts: 5101
Joined: Wed Jul 25, 2007 11:12 am UTC
Location: C:\Users\Xeio\
Contact:

### Re: Awesome Acheivements

M-x shell wrote:*snip*
I recommend spoiler tags so it's collapsible too if you're posting that much text. But yea, attachments are good.

spupy
Posts: 153
Joined: Sun Apr 13, 2008 10:48 pm UTC

### Re: Awesome Acheivements

Me and two other guys made a sensor network protocol thing. There were around 30 Sun SPOTs on the building floor. Communicating through radio, they connect in a P2P network. Using simple SQL queries issued using a mother node, one can aggregate measurements such as temperature and power of light, or make all the nodes do blinkenlights. The aggregated info can be stored in a DB or in XML. It had caching, object serialization and compression, and some ability to repair the network if nodes are unreachable. It also had an cute rainbow beam blinking pattern. All in OOP heavy Java.

We won 3 six-packs of beer for it. (it was a contest thing)
There are two types of people in this world - those who can count to 10 by using their fingers, and those who can count to 1023 by using their fingers.

tekk
Posts: 35
Joined: Wed Aug 12, 2009 5:48 am UTC

### Re: Awesome Acheivements

I was fixing my sources.list, manually poring through everything. Then I had a revelation....I KNEW PERL!!! REGEXES FTW.

I felt so smart the rest of that day Arancaytar
Posts: 1642
Joined: Thu Mar 15, 2007 12:54 am UTC
Location: 52.44°N, 13.55°E
Contact:

### Re: Awesome Acheivements

Spoiler: On the other hand...

"Sometimes a hacker has a problem, and he thinks to himself 'I know, I'll solve it with a regular expression!'. Now he has two problems." -- Jamie Zawinski
"You cannot dual-wield the sharks. One is enough." -Our DM. Earlz
Gets Obvious Implications
Posts: 785
Joined: Sat Jun 09, 2007 8:38 am UTC
Location: USA
Contact:

### Re: Awesome Acheivements

If your regular expression is over 100 characters long, you may want to consider killing yourself early without having to go through the pain
My new blag(WIP, so yes it's still ugly..)
DEFIANCE! This is microtext. Zooming in digitally makes it worse. Get a magnifying glass.. works only on LCD

fazzone
Posts: 186
Joined: Wed Dec 10, 2008 9:38 pm UTC
Location: A boat

### Re: Awesome Acheivements

Consider?
*/

tekk
Posts: 35
Joined: Wed Aug 12, 2009 5:48 am UTC

### Re: Awesome Acheivements

actually the regular expression was really managable. s/hardy/deltah/ is what I used I think

You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

### Re: Awesome Acheivements

Earlz wrote:If your regular expression is over 100 characters long, you may want to consider killing yourself early without having to go through the pain

It depends on the expression.

An expression matching against the 20 longest words in the dictionary isn't that painful to maintain, yet it's going to be well over 100 characters long.
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

foundation
Posts: 9
Joined: Mon Dec 17, 2007 11:59 am UTC

### Re: Awesome Acheivements

My greatest achivement was when I was doing some CUDA programming.
We were doing some numeric calculations using trigonometric polynomials as a base for a
function approximation. It had a bunch of if-s and switches for choosing the factors.
I made a simple algorithm to calculate them in one step for every case , and achived about a 50% speedup due to not stalling a pipeline. My professor wasnt convinced that it works so i made a formal proof for it and that is the one single program I am sure it works ! Also , writing a linux kernel module was quite cool , back when I didnt have a virtual machine to test things on , and had to try it on a live system, it just felt grat when it worked Arancaytar
Posts: 1642
Joined: Thu Mar 15, 2007 12:54 am UTC
Location: 52.44°N, 13.55°E
Contact:

### Re: Awesome Acheivements

For very complex patterns, I've actually tended to make a character by character loop with state variables and comparisons. Besides allowing a few tricks regex can't do, at least that can be documented with inline comments...
"You cannot dual-wield the sharks. One is enough." -Our DM. phlip
Restorer of Worlds
Posts: 7572
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

### Re: Awesome Acheivements

Perl has a /x flag that lets you put extra whitespace and comments inside a regex (if you then want something to match a single space, you have to escape it)... I dunno whether other regex libraries have a similar thing... but most of those work on ordinary strings, rather than builtin syntax things, so you can always break up the string and put comments" + /* like this */ ".

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

Dason
Posts: 1311
Joined: Wed Dec 02, 2009 7:06 am UTC
Location: ~/

### Re: Awesome Acheivements

In my second programming class we had a project where we had to make a game where cats were chasing mice around a maze. This took some work in itself but I added a feature that randomly (about 1/50 of the time) a raptor would randomly appear in the maze at the start and everything would die (of course) within the next round.

My professor told me it was awesome. But I already knew that.
double epsilon = -.0000001;

tekk
Posts: 35
Joined: Wed Aug 12, 2009 5:48 am UTC

### Re: Awesome Acheivements

Alright, so I'm writing a replacement for cat in perl, not STRAIGHT cat which is too easy, but with some nice improvements. I'm using getopt to check for flags and then converting it to a number to check, or atleast I was. The issue was that if there was no flag it would say 1/8, one flag is 2/8 etc. causing problems if I add more flags. Then I realized I was making cat and could just check for my flags with the whole cat portion of it the program is now easier to read, more extensible and smaller

IanO
Posts: 2
Joined: Wed Sep 24, 2008 9:25 pm UTC

### Re: Awesome Acheivements

Magic Molly wrote:Anyways, on this test, I found most of the problem to be relatively simple stuff, that we had already done variants of in class. However, the bonus problem was very intriguing to do. For it, i was supposed to create the following pic, without just drawing it straight out.

Spoiler: How might you guys have done it?

These kind of problems can often be done elegantly using recursion. For example, you can draw that picture in Logo using turtle graphics:

Code: Select all

to circles :radius :depth  pendown  arc 360 :radius  penup  if :depth = 0 [stop]  forward :radius/2   circles :radius/2 :depth-1  back :radius   circles :radius/2 :depth-1  forward :radius/2endleft 90penupcircles 200 3

The EGE
not very good at pickup limes
Posts: 1081
Joined: Sat Dec 27, 2008 12:11 am UTC
Contact:

### Re: Awesome Acheivements

Lanzaa wrote:The only programming achievement I can remember being proud of is a Fibonacci number calculator.

My first version calculated (with full precision) the 1,000,000th Fib number very slowly, ~30 minutes.
My second version calculated 1,000,000th Fib in ~40 seconds, but 10,000,000 took ~70 minutes.

With my final version the 1,000,000th Fib took <.5 sec, 100,000,000th <1 minute and I was able to calculate the 1,000,000,000th Fib in ~20 minutes.

The 1,000,000,000th Fib took ~500MB of ram and weighs in at 200MB on my disk.

Its first and last digits:
7952317874554683467829385196197148189255542185234
..
8296198982902073319952559425703172326981560546875

Did you calculate it recursively, or with the (phi^n)/(sqrt(5)) method?
sillybear25 wrote:But it's NPH, so it's creepy in the best possible way.

qbg
Posts: 586
Joined: Tue Dec 18, 2007 3:37 pm UTC

### Re: Awesome Acheivements

The EGE wrote:
Lanzaa wrote:The only programming achievement I can remember being proud of is a Fibonacci number calculator.

My first version calculated (with full precision) the 1,000,000th Fib number very slowly, ~30 minutes.
My second version calculated 1,000,000th Fib in ~40 seconds, but 10,000,000 took ~70 minutes.

With my final version the 1,000,000th Fib took <.5 sec, 100,000,000th <1 minute and I was able to calculate the 1,000,000,000th Fib in ~20 minutes.

The 1,000,000,000th Fib took ~500MB of ram and weighs in at 200MB on my disk.

Its first and last digits:
7952317874554683467829385196197148189255542185234
..
8296198982902073319952559425703172326981560546875

Did you calculate it recursively, or with the (phi^n)/(sqrt(5)) method?

Compute it using exponentiation by squaring on the closed-form matrix solution.

Earlz
Gets Obvious Implications
Posts: 785
Joined: Sat Jun 09, 2007 8:38 am UTC
Location: USA
Contact:

### Re: Awesome Acheivements

IanO wrote:
Magic Molly wrote:Anyways, on this test, I found most of the problem to be relatively simple stuff, that we had already done variants of in class. However, the bonus problem was very intriguing to do. For it, i was supposed to create the following pic, without just drawing it straight out.

Spoiler: How might you guys have done it?

These kind of problems can often be done elegantly using recursion. For example, you can draw that picture in Logo using turtle graphics:

Code: Select all

to circles :radius :depth  pendown  arc 360 :radius  penup  if :depth = 0 [stop]  forward :radius/2   circles :radius/2 :depth-1  back :radius   circles :radius/2 :depth-1  forward :radius/2endleft 90penupcircles 200 3

Recursion.... in logo... dude, that is an awesome achievement... Now I'm going to kick you though.
My new blag(WIP, so yes it's still ugly..)
DEFIANCE! This is microtext. Zooming in digitally makes it worse. Get a magnifying glass.. works only on LCD

phlip
Restorer of Worlds
Posts: 7572
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

### Re: Awesome Acheivements

Hmm? What's wrong with using recursion in Logo? It's modelled on lisp, after all, just with fewer parentheses. And sure, it's got a bunch of features that make it easier to program procedurally (eg while and repeat), it's still perfectly fine to program functionally in it.

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

Lenary
Posts: 151
Joined: Fri Apr 18, 2008 9:00 am UTC
Location: Edinburgh, SCOTLAND

### Re: Awesome Acheivements

Earlz wrote:
Arancaytar wrote:This isn't really an achievement as such, but my Python code has tripled in readability and terseness ever since I figured out you could assign by tuple.

Want to swap two variables?

Code: Select all

a, b = b, a

Want to iteratively calculate Fibonacci, with only two variables?

Code: Select all

a, b = 0, 1for i in xrange(n):  a, b = b, a + b

I've never much liked Python, but thats freaking amazing

in ruby, you can pass a lambda when creating a hash, which it uses to calculate its default value (i believe you can get the same functionality by using a defaultdict or something in python, but i am yet to investigate.

Behold, fibonacci, with caching (and the variables are scoped only to the lambda):

Code: Select all

fib = Hash.new {|h,k| h[k] = h[k-2] + h[k-1] }fib, fib = 0, 1

Also, assigning by arrays works in ruby too, as do tricks with splat (i think this works in python too) they're really useful for an unknown amount of args to a method or other fun things like that. ** from python would also be quite useful in ruby, instead of popping the last argument off only if it's a hash

Code: Select all

a, *b = 1, 2, 3, 4a # => 1b # => [2,3,4]
My Tumblog

[imath]you = me (awesome + clothes)[/imath]
solve for awesome if you're a hot girl
Spoiler:
[imath]awesome = \frac{you}{me} - clothes[/imath]

fzort
Posts: 8
Joined: Thu Jan 24, 2008 8:30 pm UTC

### Re: Awesome Acheivements

I won the IOCCC once.

lulzfish
Posts: 1214
Joined: Tue Dec 16, 2008 8:17 am UTC

### Re: Awesome Acheivements

fzort wrote:I won the IOCCC once.

fzort
Posts: 8
Joined: Thu Jan 24, 2008 8:30 pm UTC

### Re: Awesome Acheivements

lulzfish wrote:Sweet. What was your entry?

I got Best of Show at the 18th IOCCC (2005). Unfortunately, the organizers seem to have stopped caring about the contest around that time, so although I'm in the list of winning entries in this page, no one bothered to update the global list of winning entries in the past 4 years. The commented hint file for my entry is here (in Leo Broukhis' page - he's one of the judges). This is the code. It generates GIF animations of spinning, shaded torus knots, like this one: Cosmologicon
Posts: 1806
Joined: Sat Nov 25, 2006 9:47 am UTC
Location: Cambridge MA USA
Contact:

### Re: Awesome Acheivements

fzort wrote:I won the IOCCC once.

Oh hey me too. I didn't get Best in Show, though. I really liked yours when I found out about it; I remember it well. For a long time I didn't realize that the winners of the 18th were online. When I finally saw them it was like a hidden bonus treasure. Occams_Razor
Posts: 17
Joined: Wed Aug 26, 2009 8:50 pm UTC

### Re: Awesome Acheivements

My first and only awesome achievment, finally finished a project. Okay so it's just a small rock paper scissors game I wrote in Java, and it did only take about 3 hours of coding(most of which was spent trying to track down an error which resulted from a | where I needed an &&) but it is a project, and it works reasonably well, which you know, is nice.

fzort
Posts: 8
Joined: Thu Jan 24, 2008 8:30 pm UTC

### Re: Awesome Acheivements

Cosmologicon wrote:
fzort wrote:I won the IOCCC once.

Oh hey me too.

Nice! What's your entry? fzort
Posts: 8
Joined: Thu Jan 24, 2008 8:30 pm UTC

### Re: Awesome Acheivements

Occams_Razor wrote:My first and only awesome achievment, finally finished a project. Congratulations! Cosmologicon
Posts: 1806
Joined: Sat Nov 25, 2006 9:47 am UTC
Location: Cambridge MA USA
Contact:

### Re: Awesome Acheivements

fzort wrote:
Cosmologicon wrote:
fzort wrote:I won the IOCCC once.

Oh hey me too.

Nice! What's your entry? I got Best Abuse of Computation in the latest (19th) contest. It's not available on the IOCCC website, but I put a writeup on mine.

Durinthal
Posts: 799
Joined: Mon Dec 11, 2006 9:46 pm UTC
Location: 127.0.0.1

### Re: Awesome Acheivements

Not as great as some here, but I wrote a message board using just the core install of Python 2.4 (thanks to it having a massive standard library).

cmpwn
Posts: 30
Joined: Wed Dec 30, 2009 8:11 pm UTC

### Re: Awesome Acheivements

You know .docx Word files? Well, they are really just .zip files (try it yourself - just change the extention). I wrote two programs based off of this that are some of my proudest acheivements. After some experimentation I figured out how to hide a file inside of a Word document, while keeping the document readable by Word. The first program is a simple one that encrypts files based on a key, and hides them within a document, and will extract and decrypt them as well.
The second program is a much more complex one that sets up a "filesystem" in a file (similar to an iso) on a flash drive, and lets you modify it through the GUI. It is almost identical to Windows Explorer. You can add files, remove files, add or remove directories, copy/paste, ect. When you click "update" or close the program, it saves the filesystem and splits it into several files. It then uses legit Word documents that the user specifies to hide the encrypted pieces of the filesystem. What that does is lets you have a hidden, encrypted filesystem on your flash drive for storing all of your less than appropriate material and hide it all inside of legit, readable Word documents.

Those are my biggest moments of coding 1337|\|355
-Sir Cmpwn
On 1/23/2012 I returned from inactivity to make a single post.