HNHacker News
TopNewBestAskShowJobs

qntm

625 karma · joined September 8, 2010

submissionscomments
qntm··on A mirror flips left and right, but not up and down
This is the entire answer. It amazes me that people can write so much about this question without managing to get to this statement.
qntm··on Even a URL tells a story
I wrote a thing about my exceptionally short urls a little while ago: http://qntm.org/urls
qntm··on Solving Tetris in C
Ooh. That's actually cleverer. It reduces the space of possible wells quite substantially. It does make detecting a horizontal line more difficult, though. I will think about this.
qntm··on Solving Tetris in C
Alpha-beta pruning sounds like a reasonable route forward. In this case, each "well" is a state in the game and placing a new piece in the well constitutes a move to a new state. Since the "heuristic value" of a move is absolute (player wins or AI wins), I already have stuff in place to exit early from an exhaustive evaluation of all possible landing points if a definitive answer is found. But I don't have anything in place to put those landing points into an optimal order for evaluation purposes. A Tetris-playing AI which can quantify the "goodness" of a move would be useful here, and that's entirely possible.

Intelligent caching is possible but I think it would be difficult for me to implement and I'm not certain that it would yield much benefit.

Actually, the procedure for identifying all the possible player moves is very fast already and I think making it prioritise "easier" moves would slow it down. In particular, ruling out or de-prioritising simple things like "tucking" a piece under another is very counterproductive.

qntm··on Solving Tetris in C
You're suggesting using 2 bits to store the height of the column, plus 3 bits to store the presence of holes, for a total of 5 bits per column. Exactly how you got from that to a figure of "2^23" I don't know. That's actually (2^5)^10 = 2^50 possible column combinations.

Why not just use 4 bits to represent the whole column? That's (2^4)^10 = 2^40, exactly where we started.

In fact, look at rows instead. With 10 columns and 4 rows there are, to be more precise, (2^10 - 1)^4 possible states.

And the majority of which have "floating" (disconnected) sections which, while reachable with the rules of Tetris, cannot be reached without making at least one line.

In case you didn't read the article, Tetris has been solved for width 10 height 4: the AI wins. The same is true for width 10 height 5. We need to go further.

qntm··on Solving Tetris in C
I'm afraid the game tree for W10xH5 is over 2 gigabytes and I'm pretty sure the number of possibilities increases faster than exponentially in H!
qntm··on Solving Tetris in C
You are correct. I updated it to this:

    who_wins(well W) {
      for each piece P {
        for each landing state of piece P in well W {
          well W2 = result
          if(that_makes_a_line(W2)) {
            next piece
          }
          if(who_wins(W2) == PLAYERWINS) {
            next piece
          }
        }

        // AI wins every landing state
        return AIWINS
      }

      // Player wins every piece
      return PLAYERWINS
    }

    print who_wins(empty_well)
qntm··on Why I will never pursue cheating again
Because the cheater gets out the other end of the degree course with a degree they didn't earn. And then they start competing for the same jobs as me.
qntm··on The Plot to Kill PHP MySQL Extension
MySQL queries constitute a signification proportion of SQL queries, and PHP's MySQL extension is responsible for a significant proportion of MySQL queries. It's not a problem of MySQL and it's not even a problem of how the PHP code that uses MySQL is written - the problem is that PHP's MySQL extension doesn't even offer a way to safely prepare a statement. "Fix the developers", in this context, would mean beating them about the head until they remember to mysql_real_escape_string() every parameter every time, and that's obviously not the right approach.

A better approach is to either (1) add a mysql_prepare() function to the PHP MySQL extension, or (2) deprecate the extension in favour of one which forces or at least encourages or at least supports the use of prepared statements.

qntm··on The Plot to Kill PHP MySQL Extension
Will this result in more people using the prepared statements provided in PDO etc.? Then this could reduce the global number of MySQL injection attacks by a noticeable percentage.
qntm··on Bored People Quit
For arbitrary messages:

    sub escape {
        my $arg = shift;
        $arg =~ s/([^a-zA-Z0-9_])/\\$1/g;
        return $arg;
    }
qntm··on Writing code that works on first go
I instinctively distrust code that works first time. I advocate error-driven development.
qntm··on Google Singleton Detector
What are the advantages of instantiating the Singleton object in multiple different locations rather than, for example, using the Singleton class itself as an object with various static attributes and methods?
qntm··on Oh Yes You Can Use Regexes to Parse HTML
I didn't know that a grammar featuring recursion can still be called a "regular" grammar if the language it describes is regular.

However, no regular grammar (not even a recursive regular grammar) can describe a recursive language.

qntm··on Oh Yes You Can Use Regexes to Parse HTML
Negative, a regular grammar which describes a regular language cannot be recursive. For recursion you need to be context-free at least.

Of course, most modern "regex" engines provide features which go beyond the strictly regular languages.

qntm··on What every programmer should know about time
This seems like it would cause more problems than it solves.

"It's 10:00 here in London. I need to call someone in New York, what time is it there?" "10:00, same as it is everywhere in the world." "So... is now a good time to call them?" "I have no idea."

qntm··on A cron pitfall that will probably snare you at least once in your career
Isn't ".bak" a fairly logical file extension for a cron job intended to, e.g., perform backups?
qntm··on What's a condition system and why do you want one?
I'm still not 100% sure what the answer to the second question is. I think a more compelling example is needed.
qntm··on Edsger Dijkstra's note on starting array indices at 0 (pdf, 1982)
The worst part is, if you are a mathematician and you expect the modulus operator to behave exactly as it does in mathematics then it can be maddeningly difficult to track down why your program isn't working correctly. You just don't expect simple mathematical operators to start malfunctioning.
qntm··on Erik Naggum on Emacs and muscle memory
Of course it isn't an argument against powerful text editors. It's an argument against obtuse text editors.
qntm··on Erik Naggum on Emacs and muscle memory
> A novice tool never makes anything but the most trivial task easy

I disagree with this statement in the strongest terms.

qntm··on Erik Naggum on Emacs and muscle memory
I'm saying that the meaning of the text - be it prose, poetry or code - is all that is important. Text editors are tools, like paintbrushes and screwdrivers. They only important or valuable to the extent that they enable us to create stuff of actual value.

You can go down the route of text editing as art, like that Vi Golf concept that was floating around. And a well-made tool is indeed valuable and beautiful to behold. Nevertheless, I maintain that a text editor is strictly as important as the text it is used to create.

qntm··on Erik Naggum on Emacs and muscle memory
This essay was evidently written in 1997. I don't know what the competitors to Emacs were in 1997 other than Vi, but these days there are extremely powerful text editors which are exceedingly easy for a novice to pick up and use right out of the gate and then go on to offer vast arrays of substantially more advanced tools for those prepared to explore and become experts.

Just because it used to be extremely painful to become a towering expert at text editing doesn't mean it should continue to be so. It's not like riding a bicycle-- text editing actually is easy. Or at least, it can be made easy, and there is no argument for keeping it difficult.

Remember, text editing in and of itself is of no value. Tools should get the hell out of the way of their users.

qntm··on The 10:10 code - global position in ten characters
Maybe wide acceptance isn't the use case!

It's okay to intend a tool for a specific purpose! It's okay to do one thing well.

qntm··on MtGox account database leaked
SQL injection problems are trivially preventable.
qntm··on Why we are unlikely to ever leave the solar system.
Socrates was wrong.

We are wrong now, as well.

But to say that we are as wrong as Socrates is ridiculous. We are much, much, much closer to the truth now than we have ever been.

qntm··on PHP Hacking aka trying to push PHP internals forwards
The good parts of PHP, just off the top of my head: Extremely forgiving syntax which makes it quick and easy to bash together something that just works, implicit type conversion, a vast array of built-in functions, readability, near-ubiquity, generally very strong documentation with a healthy focus on example code, and the way it interpolates with static HTML, which I'm sure there's a word for but I can't remember offhand.
qntm··on Blunt and necessary review of programming language books.
I learned Perl by reading Learning Perl, but even trying to use Programming Perl as a reference since then has been difficult for me. The book is conversational and humorous in its tone, which makes it extremely verbose and irritating to read when I'm actually trying to get information out of it. There's too much raw text and not enough examples, particularly when it comes to syntax. I also find that because the book attempts to be a complete reference, and because Perl at its core is insanely complicated, Programming Perl (like the Perl online documentation) spends far too much time dwelling on minor technical details and edge cases which no sane coder should ever be thinking about using.
qntm··on Blunt and necessary review of programming language books.
Programming Perl is definitely guilty of this.
qntm··on Oddities about JavaScript
That's because in Python the line break is the statement terminator.
← PreviousPage 5 of 9Next →