Showing posts with label puzzles. Show all posts
Showing posts with label puzzles. Show all posts

Monday, August 27, 2012

52 Number Logic Puzzle

Here's a logic puzzle that my boss gave me to think about.  I thought about it on and off for a few days before arriving at a correct solution.  I feel I should have figured it out sooner, but I ended up going down a dead-end path and wasting time stuck in that rut.

Anyway, here's the problem.  I personally find it to be a really nice puzzle with a nice clean solution.

There is a bag with 52 balls numbered 1 through 52.  First, you choose 5 of them randomly, and second, you pick one of them out (non-randomly... you get a choice) and put it in your pocket.  Now, there are 4 balls remaining from your initial 5.  Your goal is to order the 4 balls however you want in order to convey what the pocketed ball is to someone that understands your strategy/algorithm/rules.

Note that by ordering the 4 balls, I am not saying that you're allowed to do weird things with how the balls are placed.  This problem involves no such trickery.  The strategy that you come up with should work just as well if you wrote down the values in the order of your choice and some random person on the street were asked to read them out in order.  The mere reading of these numbers in order should be enough information to determine the value of the hidden ball.

As you would guess, the question is simply this: What strategy/algorithm/rules can you use to accomplish this information transmission feat?

Enjoy.

Additional Clarification Notes (as some appear to be confused by the questions):

Understand that you only have 4 values to work with. The pocketed ball's value never comes into play as far as transmitting information.  All the information must be conveyed with 4 ordered values. Nothing more. To further clarify, the final list of 4 values can be read out loud by anyone (including those without knowledge of the algorithm), and anyone that listens to the sequence of 4 values and also understands the strategy/algorithm/rules should be able to ascertain the hidden ball's value.

Tuesday, April 12, 2011

Logic Problem

I'm a big nerd. Here's a problem for all you other nerds out there.

We have 25 balls of different weights. We would like to find out which are the 5 heaviest in order. In other words, we would like to know which ball is the heaviest, 2nd heaviest, 3rd heaviest, 4th heaviest, and 5th heaviest. The only tool we have available to conduct any measurements on these balls is what I'm calling a Relative Weighing device.

This device allows up to 5 balls to be loaded into it one at a time. Once all the balls are inserted, you press a button and the device prints out the ball order that corresponds to heaviest to lightest. As soon as the button is pushed, the device's memory is cleared and all you have is the printout.

For example: Say that you put in Balls 1 through 5 into the machine in that order. The Relative Weighing device might return 3, 4, 2, 1, 5 to indicate that Ball 3 is heavier than Ball 4 is heavier than Ball 2, and so on.

Now, for the question: What is the fewest weigh-ins using our special device to determine the 5 heaviest balls in order?

Friday, November 12, 2010

A Neat Little Problem

I found this problem to be both interesting and sort of cute. So, I'm sharing here. There are at least two solutions that I know of (ignoring isomorphisms). I didn't find it too difficult, but who knows what everyone else thinks of it.

You have 10 visually indistinguishable balls lined up in front of you. Let's mark then ball #1 through #10. Two adjacent balls have been deemed special. Your job is to determine which balls are the special ones.

You are given a single consultation with an oracle to help you out. The oracle accepts a specific type of query, which is of the form: How many of the balls in this list { ... } are special? You are allowed to submit two questions at once, and you will receive two answers at once.

For example, if the special balls are #1 and #2, a valid consultation with the oracle would be:

1) How many of the balls in {#1, #2, #3, #9} are special?
2) How many of the balls in {#1, #5, #6} are special?

The oracle's response in this case will be Question #1 = 2, Question #2 = 1.

Notice that you are not allowed to formulate Question #2 based on the response of Question #1. Both questions must be submitted simultaneously.

Enjoy!

Sunday, August 15, 2010

1-4-24 Simulation

So, I've written some simple simulation code for the 1-4-24 game. If you're not familiar with it, see this old post: 1-4-24 Dice Game.

Edit: I found a bug in my code, so I've updated the simulation results.
Edit #2: I found another bug in my code, and so I've updated the results again. And, added ran a couple other strategies just to see results.

I ran an initial simulation with a simple default strategy as follows:

1) Always keep 1 and 4 if you don't already have them.
2) Always keep 6 if you already have both a 1 and a 4.
3) If you didn't keep anything in the current roll (1/4/6 as per Rules #1 and #2) , then keep a single die (the highest valued one).

Score Frequency PDF CDF
Not Qualified 4324214 (4.32%) (100.00%)
4 0 (0.00%) (95.68%)
5 11 (0.00%) (95.68%)
6 143 (0.00%) (95.68%)
7 1094 (0.00%) (95.68%)
8 5670 (0.01%) (95.67%)
9 21906 (0.02%) (95.67%)
10 75295 (0.08%) (95.65%)
11 222711 (0.22%) (95.57%)
12 562945 (0.56%) (95.35%)
13 1239852 (1.24%) (94.79%)
14 2489387 (2.49%) (93.55%)
15 4420645 (4.42%) (91.06%)
16 6855657 (6.86%) (86.64%)
17 9436721 (9.44%) (79.78%)
18 11863564 (11.86%) (70.34%)
19 14150677 (14.15%) (58.48%)
20 13048294 (13.05%) (44.33%)
21 11259056 (11.26%) (31.28%)
22 8955723 (8.96%) (20.02%)
23 6549697 (6.55%) (11.07%)
24 4516738 (4.52%) (4.52%)


Here are results for a different strategy. Based on these results, it seems superior in most cases -- one case where it would not be superior is if you need only to score 15 to win (the following strategy hits 15+ 85% of the time while the previously described default strategy gets you there 91% of the time).

Evaluate the dice in the following sorted order: (1+4), 6, 5, 3, 2

1) Always keep 1 and 4 if you don't already have them.
2) Always keep 6 if you already have both a 1 and a 4.
3) If you have 2 or fewer dice left to consider, then keep a 5.
4) If you have only one die left to consider, then keep a 4. (Basically, expected value of a single roll is 3.5. You are 50% to do worse than a 4, and only 33% to do better. So, keeping the 4 is best.)
5) If you didn't keep anything in the current roll (as per above rules) , then keep a single die (the highest valued one).

Score Frequency PDF CDF
Not Qualified
12031334 (12.03%) (100.00%)
4 0 (0.00%) (87.97%)
5 14 (0.00%) (87.97%)
6 106 (0.00%) (87.97%)
7 746 (0.00%) (87.97%)
8 3596 (0.00%) (87.97%)
9 14262 (0.01%) (87.96%)
10 49197 (0.05%) (87.95%)
11 147225 (0.15%) (87.90%)
12 372987 (0.37%) (87.75%)
13 821681 (0.82%) (87.38%)
14 1633170 (1.63%) (86.56%)
15 2888930 (2.89%) (84.93%)
16 4484273 (4.48%) (82.04%)
17 6258644 (6.26%) (77.55%)
18 9710872 (9.71%) (71.29%)
19 11806824 (11.81%) (61.58%)
20 11650430 (11.65%) (49.78%)
21 11174701 (11.17%) (38.13%)
22 12093475 (12.09%) (26.95%)
23 10505528 (10.51%) (14.86%)
24 4352005 (4.35%) (4.35%)


Here's the 'go for broke' strategy, where you are going for 24 only. This means that you are going to keep all 6's (up to 4) and keep 1 and 4 as they present themselves. This strategy is forced if someone before you had gotten 24, and so you need specifically 24 to tie.

Score Frequency PDF CDF
Not Qualified 14806947 (14.81%) (100.00%)
4 1 (0.00%) (85.19%)
5 9 (0.00%) (85.19%)
6 117 (0.00%) (85.19%)
7 728 (0.00%) (85.19%)
8 3590 (0.00%) (85.19%)
9 14230 (0.01%) (85.19%)
10 49667 (0.05%) (85.17%)
11 146853 (0.15%) (85.12%)
12 374034 (0.37%) (84.98%)
13 821225 (0.82%) (84.60%)
14 1625200 (1.63%) (83.78%)
15 2859193 (2.86%) (82.16%)
16 4400751 (4.40%) (79.30%)
17 6108761 (6.11%) (74.90%)
18 9339354 (9.34%) (68.79%)
19 11297706 (11.30%) (59.45%)
20 11116484 (11.12%) (48.15%)
21 10652890 (10.65%) (37.04%)
22 11547947 (11.55%) (26.38%)
23 10035266 (10.04%) (14.83%)
24 4799047 (4.80%) (4.80%)

Tuesday, April 20, 2010

So Much For Brain Games

Nature published a study on brain training via computerized tests, such as those found in Brain Age or Brain Challenge, this week. Unfortunately, their conclusion was not what I would have hoped for; these games do not increase cognitive function. It's a shame, because I actually find those types of games entertaining.

The study shows that any skills obtained from training on one particular task does not transfer to other tasks even when the tasks are cognitively closely related! That's surprising to me.

Anyway, read the actual paper here: Putting brain training to the test.

Thursday, July 23, 2009

Robozzle

Here's a new logic/puzzle game that I just started playing. The rules are pretty simple... you write a program that controls a robot with the goal of picking up all the stars. One neat thing about this game is that there are optimization, recursion, and other coding techniques that are incorporated into many of the puzzles.

Here's a link to the game: Robozzle.

You'll want to play the tutorials and a few of the easy rated puzzles first. I haven't yet attempted any puzzle rated more than 3/5 in difficulty. Here's one that I still can't figure out and it's killing me. Maybe I'll get lucky and someone can figure this one out and give me some help.

I'm clearly missing some fundamental concept/technique. The furthest I can get the robot is past the red square and make the first left turn after it. I just can't figure out how I can get the robot to make the subsequent blue corner turns afterward.

Help Me -- Puzzle 1043: Fermat's Spiral 3

Enjoy the game!

Thursday, June 11, 2009

A Neat Problem

Recently, I went in for a series of technical interviews in search of a new position. As is typical in an interview for the types of jobs I seek, I was given a few reasoning/logic/brain teaser types of problems. One of them really stumped me, and it was only after being pushed in the right direction that I was able to see the correct approach and arrive at an answer.

Here it is for all of your entertainment.

A man arrives at the train station after work at 5pm daily. His wife always leaves the house earlier to pick him up and she arrives at 5pm sharp every day. After pick up, they head straight home. The commute time each way is always the same, so they get home at the same time each and every day. To be clear, both one-way trips (to and from) take the same amount of time.

One day the man catches the earlier train and arrives at the train station at 4pm. His wife does not know this, and so she is on her normal schedule. The man (at 4pm) decides to start walking home to save his wife some time. The wife sees him on the road on her way to the station. She picks him up and they turn around and head home. They arrive home 10 minutes earlier than their normal arrival time.

For how long did the man walk for?

Thursday, April 16, 2009

Countries of the World Challenge

If you have 15 minutes to spare, give this a try. Basically, you have to enter as many countries as possible in 15 minutes. Spelling counts, which cost me a few points, unfortunately.

Here's the link: How Many Countries Can You Name?

I got 116 out of 195. There were a few really obvious ones that I should have gotten, but I did manage to get a number of the more obscure ones. Not really a great score, but it's probably not all that shabby either. Below is a mini-image of my final map (click to zoom) so that there's no spoilers. Green = correct and Red = missed. Enjoy!

Tuesday, August 26, 2008

A Sequence Relationship

I thought I'd spend a minute to post this up, because some might find that trying to figure it out might be entertaining. So, I'm at work going through some code and I'm getting two sequences of 4 numbers. All I know is that these two sequences are related somehow, but there isn't much more information beyond that.

Unfortunately, I'm slow and I did not instantly see the relationship, and so I had to spend some time digging deeper into the code before all was revealed. Let's see if you can spot the relationship.

Sequence A: 11, 25, 165, 300
Sequence B: 64, 199, 339, 353

Hint: Think line numbers in text, or maybe think of a line of people. -- Too bad, I wasn't given this luxury. Could have saved myself 20 or so minutes of time.

Note: There's actually some practical meaning to the sequences.

Wednesday, February 13, 2008

More Chess...

Well, I've begun getting others back into playing chess again. My friend, Jim, and I used to play a lot, but then we stopped years ago around the time when we joined new companies, or something like that. Anyway, we decided to set aside some time each week to play a few games then go over them and run analysis software to learn a bit more. No idea if this is a good way to learn, but it's at least a fun way to go about it.

So, we played 3 games tonight (15 minute). I basically got lucky in a few key spots, and managed to win two of them. The one that I lost, I resigned after I was put in a hopeless spot after some miscalculation.

Well, there was one game that was actually really good. It was close for most of the way (even the analysis software said so!). That is, until I blundered and allowed Jim to give my King a nasty check. Here's the position after that "game-winning" check (I think it's still a game-winning move despite the ultimate outcome of the game).


In the actual game, I moved Kf8, which incidentally leads to a forced mate with White playing Rd7 (there is a straightforward mating sequence for both g6 and Re7). Lucky for me, Jim did not see this, and I went on to win despite missing a forced mate myself later in the game. It's awesome being mediocre.

But, that's not what I wanted to share about this position. It turns out that even if I had not walked into the forced mate position, the checking play is so good that I will actually lose my Queen following a really slick combination. So, Black must move Ke7 to avoid immediate loss. White starts the deadly attack with Re6+. Here's the position after that move.


King takes the Rook, and Queen takes the Rook back with check. The only move is Kd5. And, the lovely finish is Qg8+, which wins Black's Queen via an eventual skewer. Pretty sweet... too bad neither of us were good enough to actually play the game out to see this awesomeness unfold. Haha.

Anyway, it was a lot of fun, and I really hope the two of us can keep it up. Maybe we will get better over time. I guess we'll see.

Tuesday, February 12, 2008

More Chess

Here are two positions from a couple recent games. One is from a normal game, and the other is from a speed game (5 minute). The speed one isn't really all that interesting, but it is a game where I am under a lot of time pressure, and proceed to choke horribly. The other one I thought was sort of cute, but not really all that impressive.

Okay, here's me playing the role of a choke artist. I am White, and I moved Qd7 to threaten mate at g7. My opponent (1560-rated Blitz player on FICS) 'blunders' by moving Rb7. I had expected him to push his pawn to f5, and instead of spending a little extra time to think about this and making the correct play, I panicked and retreated with Qd3. So, instead of having a relatively easy win (even with little time left), I ended up losing on time in a roughly even position five moves later. Blech, I suck!


Again, I'm White. It's my move, and I've got a nice combination from here, which leads to a huge material advantage (in 3 moves, worst case). I guess I'll leave it at that, but once you see it, I think you'll understand why I thought it was a little cute. I know a few of you have been IM'ing me about chess lately, which is great. And, some of you have already started playing again. I need to get better though... maybe, I'll start studying the game, but I really don't want a huge time suck on my hands.

Monday, February 11, 2008

More Chess -- Missed Mate

Well, I got my friend Womper to start playing again. We used to play a lot many years ago. Although he's a bit rusty, our games have produced a few complicated positions. Womper's not the only one that's a bit rusty though, as seen by this position from last night where I miss a forced mate.

I'm Black here, and it's my move. Post-game analysis concludes that I overlooked a Mate in 4. I'm posting the position here for anyone that wants to have a look. I'll post up the mating sequence as a comment in a few days if no one else does.

Sunday, February 10, 2008

Some Chess

As many of you know I've been on a bit of a chess kick lately. I thought I'd share parts of two games I played recently. The first position isn't really all that interesting, except that it's an early game forced mate. My opponent missed the fact that I have a mate in 3, and so he did nothing to prevent it. The second position, however, is really a thing of beauty. Forgive me for tooting my own horn, but it's really rare for me to pull off such a combination.

I am White in both games. Oh, and just for those who are unfamiliar with chess notation... rows are denoted by numbers and columns are denoted by letters (order is from bottom to top and left to right, respectively, from White's view of the board).

Here is the mate in 3 position, only 13 moves into the game. Black has pushed his pawn to threaten the knight, but it guarantees White's victory. I won't say much more about it this one. Nothing too special, really. But, I thought it might be fun for those that don't really play too much to find the mating sequence.


This next one, I found a lot more interesting. And, maybe it is a lesson on why you shouldn't bring out your Queen too early. Some background... Black steals my pawn on b2, but he doesn't realize it is the start of a deadly combination. I follow with Rb1, which forces his Queen to a3 (the only safe spot for it). So, this is where we're at.


If you start looking a little bit deeper in this position, you will find that Black is in really bad shape. White has a strong move here. Knight to b5 is a huge winner. It is a sort of meta-fork. My Knight has forked Black's Queen as well as the threat of a King-Rook fork at c7.

Naturally, Black would want to save his Queen and prevent the c7 fork on his next move. On first blush, Black's obvious move would be Queen to c5 (note that a5 will not work, because the Bishop on d2 now covers it once the Knight has moved). The Queen is now safe, and the fork threat has been mitigated, as c7 is now covered. But, it turns out that it's all a big disaster for Black. The c7 fork can't be prevented without the loss of the Queen. Here's what the position looks like now.


If you want to think about this a bit, here's your chance. Otherwise, here we go on to see the rest of this combination unfold.

I move the Bishop to e3, which threatens his Queen. The Queen's only escape is to retreat to c8. But, it does her no good. Knight forks the King and Queen by taking the pawn on d6. And, that's the end of it.

In the actual game, however, my opponent sees that the Queen's retreat is futile, and opts to just take my Bishop with his Queen. He resigned a few moves later.

Anyway, I hope you all enjoyed this. I'll probably post up more positions in the future, so long as I'm still semi-obsessed with the game. I really did forget how much I liked the game, so I'm glad to have started playing again.

Monday, August 13, 2007

The Mind and Interpretation

I read this not long ago on another forum, but I thought it was interesting, so I'm going to share it here.

Take the following sentence: No head injury is too small to ignore.

Now, think about what the literal interpretation of that sentence implies... does it imply that we should treat all head injuries, or that we should be ignoring all head injuries?

Most people, including myself, think the above statement says that we should treat all head injuries. But, that is actually not what that statement is telling us to do at all. Re-read it carefully to see if you can see why. I think it is neat how our mind is quick to correct syntactical errors if we have some formulated opinion as to what is the most reasonable interpretation.

Had the sentence been: No head injury is X to Y.

We would interpret it as it is written, since we have no bias. Anyway, I find all of this interesting.

If you still aren't quite seeing the error in the first sentence, take a look at the following sentence.

The man is too tall to drive a Lotus. This says that the man can't drive a Lotus, because he's too tall. This sentence makes sense... a Lotus is a small car, so if you're too tall you probably would have difficulty driving it.

Now, let's replace the with no.

No man is too tall to drive a Lotus. This clearly means that all men are short enough to drive a Lotus, since there does not exist a man that is too tall to drive one.

Finally, let's go back to the original sentence.

No head injury is too small to ignore. This must mean that all head injuries are big enough to ignore, since no head injury is too small to be ignored. It is clear that this sentence is nonsensical; it implies that we prefer to ignore large head injuries over small ones. Additionally, it tells us that all head injuries are of a size that grants them admission into the 'large' category.

Apparently, this nonsensical sentence comes from Alice in Wonderland by Lewis Carroll. I assume that Carrol did this on purpose, after all, he is known for literary nonsense.

Thursday, May 17, 2007

Anti-social Drinker Puzzler

A friend of mine recently had an interview for a software position, and was given the following problem...

There is a bar with 25 equally spaced stools. The patrons are anti-social and will always choose the stool that maximizes the minimum distance to other patrons. And, no patron will choose to sit next to another. If there isn't any spot that is insulated from others, then no more patrons can be seated. As the owner, you get to seat the first patron, but after that initial placement, the new patrons will seat themselves according to the aforementioned rules. Where do you seat the first person to maximize the number of customers?

So, I thought about this a little bit, and decided that the more general related problem was maybe a bit more interesting. Here's a slightly different question that is a bit more general. Given a bar with N stools, is it possible to seat (N + 1)/2 patrons? I came up with a solution, but it's not really all that elegant, but I do believe it works.

I'm going to skip a ton of the details, but what I came up with is the following. Let's start with what I am going to call a safe interior median partition (SIMP). These are interior stool groupings where splitting down the middle creates two SIMPs. Safe, meaning odd numbered. This is because as soon as we see even numbers, we know we can't fill it up to full capacity.

Not all interior median partitions are safe. Say we had the following: O O O O O O O. We care about the interior, so let's put patrons on the edges. Now, we have: X O O O O O X. Now, we have an IMP of size 5 (there are 5 stools on the interior). This is not safe since it leads to even-numbered IMPs. If we put a patron in the center, we'd have X O O X O O X, and that's clearly not what we want. We can't achieve full capacity using a 'sit in the middle' strategy. So, we know that IMP-5 is not a SIMP.

Now, if we had O O O O O O O O O. We block the edges, giving us: X O O O O O O O X, and we see that this gives us an IMP of size 7. But, look at what happens when we put a person in the middle. We then have X O O O X O O O X. And, we now have two new IMPs, each of size 3. Notice that the IMP of size 3 allows us futher partitioning with a central-seating. Giving us X O X O X O X O X. So, we know that IMP-3 is a SIMP, and IMP-7 is a SIMP, as it produces two IMP-3's.

We have a SIMP, if we have an IMP-X where X is of the form (2^N - 1). So, we can generate our list of SIMPs: 1, 3, 7, 15, 31, 63, etc.

Now, how does this help us? Basically, here's the deal. If we have N barstools, then I contend that we can fill it to capacity, which means (N + 1)/2 patrons seated according to the rules, if and only if we are able to find two SIMPs that sum to (N-3). Once we find our two SIMPs, then simply take one of them and add 2 to find the initial seating. Since we are choosing a first seat to give us two SIMPs, we are guaranteed to fill to capacity, because each median seating produces new SIMPs.

Here are a few examples with illustrative seatings:

N = 25. (N-3) = 22. Our two SIMPs are 7 and 15, which sum to 22. So, we choose initial seat 9.

N = 19. (N-3) = 16. Our two SIMPs are 1 and 15. We choose initial seat 3.

N = 13. (N-3) = 10. Our two SIMPs are 3 and 7. We choose initial seat 5.

N = 15. (N-3) = 12. There aren't two SIMPs that sum to 12. So, there does not exist an initial seating that gives us full capacity. You can see this is the case below, as I've exhausted the possibilities (ignoring symmetric cases).

Click Image to Enlarge

And, that's really all there is to it. If you can find two SIMPs that sum to N-3, then you can certainly fill to capacity. Otherwise, you are bound to have some two-seat gaps in the final seating configuration.

Thursday, May 10, 2007

Sudoku

So, the other day Rowr was talking to me about writing a sudoku solver. Just in case you've been living in a cave for the last 2 years, here's a sudoku webpage. Since I suck at figuring out sudokus, I figured I might as well write a solver, and it might be fun to do so. Anyway, I'm done with a working version. There are a few things about it that I figure I'd mention now.

Download the SudokuSolver here.

1) The program attempts to use built-in logic first, but if it gets stuck then it attempts a trial-and-error method (Nishio method). If this happens, then either the puzzle is complex or is deficient (see #2 below). The program will warn you if this method is invoked. There are likely other logic rules that I didn't put in, so my program might have to invoke the Nishio method when a good puzzle solver would not require it.

2) If it is given a deficient puzzle, meaning there is more than one solution, then the program should find a solution. So, even if you were to give it a blank board, some valid solution should appear.

3) You can set up the board using either the Quick Entry (81 edit boxes) or simply clicking on the graphical board. Clicking is much slower, but if you are making small tweaks, it might be simpler.

Oh, and look at the readme file for other info. This thing isn't perfect, and is provided as-is.

And, for those who don't trust random programs, here's a screenshot so you can see what you're missing out on.

Wednesday, April 11, 2007

Where in the World is Carmen San Diego?

Thought I'd have some fun with Google's earth mapping program. So, I'm putting up seven satellite shots of famous structures and landmarks. Your job is to figure out what/where these are in the world. Have fun!

(click on images to zoom in)

Location #1


Location #2


Location #3


Location #4


Location #5


Location #6


Location #7

Tuesday, January 09, 2007

Word Growth Puzzle

Our friend, Mr. PetDander, gave me a word puzzle yesterday that you all might enjoy. Here it is...

What is the longest word in the English language which you can form starting with a base single-letter word (e.g. A, I, or O) and adding one letter at a time without rearrangement, where each additional letter creates a new legal word? Internal additions are allowed.

Here is an example of a valid 7 letter solution:

A --> AN --> ANT --> PANT --> PLANT --> PLANTS --> PLANETS

So, what is the longest valid solution?

I'll post the answer later on if no one gets it. I was unable to find any really long answers, so I cheated and ended up writing a program that grew words from A, I, O seeds. Turns out that there is a single word that bests all others. Interesting.

Monday, May 15, 2006

Simple, Yet Annoying Coding Problem

Here's a simple coding problem. What I'm looking for is a simple and efficient solution that does not require any loops. My current solution is pretty efficient, but I think there are probably better solutions, so I will pose the problem here.

IP Addresses are of the form: A.B.C.D where A, B, C, D range from 0 to 255. A computer stores an IP Address as a single value. So, an IP of 0.0.0.0 = 0, an IP of 0.0.1.0 = 256, and an IP of 0.0.2.5 = 517. An IP is simply a base-256 number.

So, say you were given an X and a Y (Y >= X). How many IPs are contained in the range INCLUSIVE that do not end with a 0 or a 255?

Here are some sample Inputs and Outputs (X,Y) --> Total.

(0, 256) --> 254
(250, 255) --> 5
(500, 1000) --> 497
(123, 99999) --> 99097

Anyone have a clever, efficient, coding solution? I'll post mine up in a few days.

*** Edit ***

I now have a solution without any conditionals. So it is a straight formula with the terms X and Y. The formula is pretty ugly, but at least it's a straight (and fast) computation.

Thursday, May 04, 2006

Kodak and the Guess Who? Game

Kodak announced yet another loss this morning. Boo on that. Looks like I'm a sucker and a believer, but I still continue to believe. Bill Miller's large stake also provides me with another vote of confidence, I'll be sticking around I guess.

Now, onto the game. I was playing on: Guess the Dictator or Sitcom Character

I've got a thing for those stupid tree search guessing games... anyway, here are two sitcom characters. See if you can figure them out.

Character #1 -- Took 19 questions.

1) Are you female? No.
2) Are you often seen dating different women? No.
3) Do you have trouble performing everyday tasks? No.
4) Do you put down rebellions? No.
5) Do you often dispense advice? Yes.
6) Do you work with animals? No.
7) Are you a middle age white guy? Yes.
8) Are you the owner of a company? No.
9) Are you tall? No.
10) Do you have 3 children? No.
11) Are you a television writer? No.
12) Are you heavy? Yes.
13) Are you a butler? No.
14) Do you work in a department store? No.
15) Do you deliver mail? No.
16) Does your son-in-law live with you? Yes.
17) Are you liked by all? No.
18) Do you like cigars? Yes.
19) Do you live in New York City? Yes.


Character #2 -- Took 53 questions.

1) Are you female? No.
2) Are you often seen dating different women? Yes.
3) Are you a salesman? No.
4) Do you live in New York? Yes.
5) Are you rich? No.
6) Are you funny? Yes.
7) Are you balding? No.
8) Do you live in the same building with a mailman? No.
9) Are you a lawyer? No.
10) Do you work at a museum? No.
11) Are you an actor? No.
12) Were you once married to a supermodel? No.
13) Are you the deputy mayor of New York? No.
14) Do you work for an advertising agency? No.
15) Do you work on TV? No.
16) Have you ever been on a sports team? No.
17) Were/Are you a professor? No.
18) Do you drive for a living? No.
19) Are you a comedian? No.
20) Did your parents abandon you? No.
21) Are you british? No.
22) Do you live with your cousin? No.
23) Are you a Doctor? No.
24) Do you work in a bar? No.
25) Do you have a mustache? No.
26) Are you a mailman? No.
27) Are you constantly making crude sexual remarks? No.
28) Are you a writer? No.
29) Do you work as a policeman? No.
30) Is your boss black? No.
31) Do you own any birds? No.
32) Are you an auto mechanic? No.
33) Do you work at night? No.
34) Are you a photographer? No.
35) Do you have any children? No.
36) Did you grow up in the 60s? No.
37) Do you have curly hair? Yes.
38) Do you dress as a woman? No.
39) Are you a handyman? No.
40) Do you work in a news stand? No.
41) Do you work as an RA? No.
42) Are you a fact checker? No.
43) Are you a dentist in Chicago? No.
44) Are you a restaurant owner? No.
45) Are you black? Yes.
46) Are you friends with Holly? No.
47) Is your best friend white? No.
48) Are you friends with Theo? No.
49) Are you involved with mathematics? No.
50) Does your best friend call you Bud? No.
51) Are you a student? Yes.
52) Are you in College? No.
53) Is your father a doctor? Yes.

What TV sitcom characters was I?
Quantcast