Μόνη ελπίδα είναι να εμφανιστεί ο Jimmy Jump.
(previous)
Μόνη ελπίδα είναι να εμφανιστεί ο Jimmy Jump.
(previous)
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:
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.
Έχω γράψει παλιότερα πως μετά από μια σειρά από PDAs και SmartPhones, γύρισα σε ένα Moleskine notebook. Από τότε και για πρακτικούς λόγους το αντικατέστησα με ένα Filofax Personal. Για περιπτώσεις όμως που χρειάζομαι εκτεταμένες σημειώσεις, κείμενα που δε γράφω σε υπολογιστή (οτιδήποτε προκαλεί αυτό το “On Paper” feeling) χρησιμοποιώ πάλι Moleskine (όχι τα μικρά σημειωματάρια, αλλά τα μεγάλα squared τετράδια). Έτσι δεν είναι απορίας άξιο που έσκασα στα γέλια διαβάζοντας στο StuffWhitePeopleLike:
“Well, if a white person has a great idea, they write it by hand, if they have a good idea, it goes into the computer.”
I stumbled upon this site: www.plagiarism.org (about a year ago) while reading this thread on SOCNET, and I felt it deserves more than a simple tweet.
Update: Some comments about this post over at FriendFeed.
(lame excuse for microblogging on my blog)
Intersting parenthack by David Alan Grier:
“To probe the situation, I started to ask questions that would get Fi to answer “yes”. It’s a strategy that I learned from my mother, who was a primary school teacher. “You learn nothing from children”, she would say, “until they say ‘yes’ to three consecutive questions”.
I have blogged before that the reason that I like MIMEDefang is that it gives the Postmaster a Perl interpreter (a programming language that is) and a library of functions that can be used to filter and manipulate incoming and outgoing email.
Of the functions available I believe that md_check_against_smtp_server() deserves special mention since it can be used to quickly implement a poor man’s milter-ahead or milter-sender. Of course milter-ahead implements many features (caching among others), but with some effort most (if not all) of the functionality can be implemented withing mimedefang-filter.
Then again, milter-ahead does not cost much (€90) even for small organizations, so the not invented here syndrome can be supressed.
Last week I went mostly twitterless. I meant to do so ever since I had read Tom Limoncelli’s piece. There had been twitterless weekends but hey the stream that I am following is small enough to read on a Monday morning.
This time it was a little over a week: 8 days. And you know what? I did not miss it. Twitter bankruptcy is like INBOX bankruptcy without feeling any regret. For if I missed a good tweet or link to information I am sure it will pop up again sometime in the near future.
GReaderless for a week
Google Reader is showing 1000+ items waiting to be dealt with. Yet I do not feel ready to declare GReader bankruptcy even though most of the unread stuff comes from the Theory of Computing Blog Aggregator (and most stuff from it comes from the arXiv). It seems that I view my RSS feeds more like email.
Update 2012/12/05: I press “mark all as read” with no regret.
No FriendFeed for a week
I use my FriendFeed account mostly for interconnecting my twitter account, my blog and the items that I share through Google Reader. Nothing to worry about then.
Update 2012/12/05: FriendFeed?
Clickomania, ο απόλυτος χρονοφάγος. Για χρόνια έπαιζα μια εκδοχή του παιχνιδιού που έτρεχε σαν Java Applet κάπου στο Brown (εάν τη θυμάται κανείς, ας μου στείλει το (πεθαμένο) URL). Όμοια και η εκδοχή του που περιλαμβάνεται στο Axim X3 με έχει συντροφέψει σε πάμπολλες διαδρομές με το λεωφορείο. Ψάχνοντας μετά από καιρό το site του παιχνιδιού, είδα πως έχει και Ελληνική μετάφραση.
Μην το παίξετε. Έχετε προειδοποιηθεί.