Skip to content

Tag: optimization

How do I count numbers that contain one digit, but not another?

I recently came across an interview question which although had an immediately obvious solution, I struggled to find a more efficient one. The actual question involved counting numbers from a to b (up to 2^64) which satisfied having either the digit 6 or 8, but not both. They called it a ‘lucky number’. So for example: The obvious thought was

How can this Java tree be 1000 x faster?

I am programming an AI for a chess-like game, based on two types of pieces on a 8 x 8 grid. I want to build a kind of minmax tree, which represents each possible move in a game, played by white players in first, and by black players in second. I have this generate() method which is call recursively. I