10

Από το εξώφυλλο του Πρωταθλητή:

Πρωταθλητής, 2009-09-23
Πρωταθλητής, 2009-09-23

Έτσι όπως είναι προπονημένη η ομάδα, ο Zico άνετα φοράει στολή και παίζει. Να δούμε και καμιά “μπανάνα”.

– Μόνο για την ομάδα μας γυρίζει στο ποδόσφαιρο ο Πελέ!

Εμείς έχουμε μέλος τον Πελέ και προπονητή τον Λευκό Πελέ. Για να δούμε.

Με την ευκαιρία, αλίευμα από το twitter, χάρη στον @Jimbo77:

Score, 2006-09-23
Score, 2006-09-23

OneWebDay

For this year’s OneWebDay, I simply quote from “Doctor for Two Decades“:

“I’ve seen the Internet go from E-mail to Twitter. I’ve seen fax machines and CDs go from amazing technologies to has beens. And computers got much faster and smaller. I no longer have time for a restroom break when I LaTeX a paper.”

And like the author notes: I got to watch it all in real time

(previous) (next)

Conway’s Game of Life implemented in Processing

Yesterday’s ugliness in implemented in Processing:

class Cell {
  int x;
  int y;
  int size;
  int live;

  Cell(int tx, int ty, int ts, int tl) {
    x = tx;
    y = ty;
    size = ts;
    live = tl;
  }

  void display() {
    stroke(0);
    if (live == 0) {
      fill(209);
    } else {
      fill(255);
    }
    rect(x, y, size, size);
  }

  void display(int c) {
    stroke(0);
    fill(c);
    rect(x, y, size, size);
  }
}

Cell[][] grid;
int[][] next;
int maxI;
int maxJ;
int size = 10;
int start = 0;

void setup() {
  size(900, 500);
  background(255);

  maxI = floor(width / size) - 1;
  maxJ = floor(height / size ) -1;
  grid = new Cell[maxI][maxJ];
  next = new int[maxI][maxJ];

  noLife();
}

void noLife() {
  for (int i = 0; i < maxI; i++) {
    for (int j = 0; j < maxJ; j++) {
      grid[i][j] = new Cell(i * size, j * size, size, 0);
      next[i][j] = 0;
      grid[i][j].display();
    }
  }
}

void draw() {
  if (start == 1) {
    runLife();
    delay(200);
  }
}

void mouseClicked() {
  if (start == 1) {
      noLife();
      start = 0;
  }

  if ((mouseX < maxI * size) && (mouseY < maxJ * size)) {
    int i = floor(mouseX / size);
    int j = floor(mouseY / size);
    if (grid[i][j].live == 1) {
      grid[i][j].live = 0;
    } else {
      grid[i][j].live = 1;
    }
    grid[i][j].display();
  } else {
    start = 1;
  }
}

void runLife() {
  int i0;
  int i1;
  int j0;
  int j1;
  int alive;

  for (int i = 0; i < maxI; i++) {
    for (int j = 0; j < maxJ; j++) {
      i0 = i - 1;
      i1 = i + 1;
      j0 = j - 1;
      j1 = j + 1;

      if (i0 < 0) i0 = maxI - 1;
      if (j0 < 0) j0 = maxJ - 1;
      if (i1 == maxI) i1 = 0;
      if (j1 == maxJ) j1 = 0;

      alive = 0;

      if (grid[i][j0].live == 1) alive++;
      if (grid[i1][j0].live == 1) alive++;
      if (grid[i1][j].live == 1) alive++;
      if (grid[i1][j1].live == 1) alive++;
      if (grid[i][j1].live == 1) alive++;
      if (grid[i0][j1].live == 1) alive++;
      if (grid[i0][j].live == 1) alive++;
      if (grid[i0][j0].live == 1) alive++;

      if ((grid[i][j].live == 1) && ((alive == 2) || (alive == 3))) {
        next[i][j] = 1;
      } else {
        next[i][j] = 0;
      }

      if ((grid[i][j].live == 0) && (alive == 3)) {
        next[i][j] = 1;
      }
    }
  }

  for (int i = 0; i < maxI; i++) {
    for (int j = 0; j < maxJ; j++) {
      grid[i][j].live = next[i][j];
      grid[i][j].display();
      next[i][j] = 0;
    }
  }
}

Two things that I find cool about Processing:

  • You can export your application as a Java applet.
  • Processing.js

Conway’s Game of Life implemented in SmallBasic

At work we have a new junior system administrator. Given the fact that he is junior and lacks even programming experience, I gave him the following assignment:

– Implement Conway’s Game of Life. Pick the programming language of your choice, the user interface of your choice, read anything you believe is relevant, ask anyone (including me) for advice, make the assumptions that suit you (and document them). Just someday come back with a demo.

Life’s rules are simple:

  • Any live cell with fewer than two live neighbours dies, as if caused by underpopulation.
  • Any live cell with more than three live neighbours dies, as if by overcrowding.
  • Any live cell with two or three live neighbours lives on to the next generation.
  • Any dead cell with exactly three live neighbours becomes a live cell.

His language of choice is PHP (as I said he lacks programming experience and PHP is the only language he has ever written anything meaningful in). Given that a system administrator must be proficient at least in sh, awk, Perl and some Python (and VBScript or Windows PowerShell if working in a Windows environment) I expect a change of choice soon. He will see the light of C later.

Upon hearing about the assignment a colleague made an unfortunate humorous attempt to challenge me: If I am to put an assignment to the junior administrator, why don’t I implement it too? Due to the law of unintended consequences, this was an unfortunate remark that was done in front of the junior administrator (more on why this was a bad choice of timing later).

Continue reading “Conway’s Game of Life implemented in SmallBasic”

re: Όχι άλλο Μίχο!

Πέτρο Μίχο-

Υπήρξες αρχηγός μας και σε ευχαριστούμε για αυτό. Σεβάσου λοιπόν όσους που σε είδαμε να παίζεις και σε χειροκροτήσαμε και σταμάτα τις τηλεοπτικές εμφανίσεις. Δεν είναι ότι κάνεις κακό μόνο στον εαυτό σου: Κάνεις κακό στον Ολυμπιακό · κάνεις κακό και σε εμάς που σε χειροκροτήσαμε κάποτε.

Δεν είμαστε όλοι οι Ολυμπιακοί σαν κι εσένα. Μερικοί από εμάς διαβάζουμε και τους κανονισμούς πριν πούμε την άποψή μας.

Για το καλό της ομάδας μας, της ομάδας που ηγήθηκες, είναι καιρός να σταματήσεις.

Με σεβασμό (ακόμα, αλλά όχι για πολύ)

Γ.Α.

(In-Reply-To:)

atan2() implemented in bc

Dave Taylor thought that it would be a good idea to calculate in Perl the distance between two longitude / latitude points on the Earth. He also thought it would be awesome if the same could be implemented in bc.

I replied that one could easily transform in Perl the cost function from the TSP page. Dave Taylor pointed out that unfortunately atan2() is not available in bc and atan2() is used in the cost function.

“So what?” I thought. All one needs is the definition of atan2(). It turns out that one needs to define in bc the sign function and abs() too.

define sgn(x) {
        if (x == 0) {
                return(0);
        } else if (x < 0) {
                return(-1);
        } else if (x > 0) {
                return(1);
        }
}

define abs(x) {
        if (x < 0) {
                return(-1 * x);
        } else {
                return(x);
        }
}

define atan2(y, x) {
        auto pi, fi;

        pi = 4 * a(1);

        if (y == 0) {
                if (x > 0) {
                        return(0);
                } else if (x == 0) {
                        print "undefined\n";
                        halt;
                } else if (x < 0) {
                        return(pi);
                }
        }

        fi = a(abs(y/x));

        if (x > 0) {
                return(fi * sgn(y));
        } else if (x == 0) {
                return(pi * sgn(y) / 2);
        } else if (x < 0) {
                return((pi - fi) * sgn(y));
        }
}

Put the function definitions in a file (say atan2.bc) and call it from the command line as:

$ bc -l atan2.bc

The above code was written in less than ten minutes of time. I am sure that one can come up with better implementations (not calculating pi (== 4 * atan(1)) and then dividing it by 2 is an optimization directly observable). All in all it was a fun exercise, plus while searching I got to read about CORDIC.