puzzle

Why is JFrame layout not the one I set?

If I set a layout on a JFrame with setLayout and then retrieve it with getLayout then I get a different LayoutManager. What is going on here?? public class Lay { public static void main(String[] args) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { java.awt.Container contain...

Find all combinations of coins when given some dollar value

I found a piece of code that I was writing for interview prep few months ago. According to the comment I had, it was trying to solve this problem: Given some dollar value in cents (e.g. 200 = 2 dollars, 1000 = 10 dollars), find all the combinations of coins that make up the dollar value. There are only penny, nickel, dime, and quarter....

Algorithm to create hex flood puzzle

I'm creating a puzzle game that, while playable by hand for easy levels, is meant to be solved by computer programs for harder ones. The puzzle is a flood fill on a hexagonal board. You can try a prototype here. Here is how the puzzle works: by choosing a color from the top, you perform a flood fill starting from the upper-left tile. ...

1x10^49 in decimal - how binary bits is that and how would you convert it to binary?

I've encountered a website that uses a 50-digit decimal integer ID in a URL query string, which seems a little excessive. The smallest 50-digit decimal number is 1.0 x 10^49, otherwise known as: 1000000000 0000000000 0000000000 0000000000 0000000000 How many bits would the binary representation contain? How would you approach conver...

recursion: cut array of integers in two parts of equal sum - in a single pass

Using recursion, find an index that cuts an array in two parts so that both parts have equal sum. Cut means to cut like with a knife. All the cells with index <= to the result must be equal in their sum to the all the cells with index > to the result. No cells can be left off or be part of both sides. The arrays contains arbitrary inte...

Bridge crossing puzzle

Four men have to cross a bridge at night.Any party who crosses, either one or two men, must carry the flashlight with them. The flashlight must be walked back and forth; it cannot be thrown, etc. Each man walks at a different speed. One takes 1 minute to cross, another 2 minutes, another 5, and the last 10 minutes. If two men cross to...

Which should inherit which?

This is one of the boring academic OOP questions, but it is not a homework. I got the question from a newbie programmer about one of those stupid textbooks examples about OOP. Imagine that you are designing a Square class and a Cube class, which should inherit which? I see a relationship, but what it is, I can not really see! Could yo...

Which is the best way to solve this kind of game?

Hello, this evening I tried to solve a wood puzzle so I wondered which is the best way to find a solution to this kind of problem programmaticaly.. The aim is to combine a set of solids (like tetris pieces in three dimensions) together combining a shape in a feasable way that takes care of the fact that pieces can be attached or slided...

How do you answer questions in interviews for which you think, they are senseless?

I am mentioning a few questions which are usually the part of interviews, I dont understand what is the intent behind then. Of course one might argue, just to see how you think, or how you react, but isn't it better if you ask a more meaningful puzzle, at least for which you can be sure of answer, or justify unanimously. For example, see...

sites for having fun with php

are there any sites where we have to solve puzzles using php scripts? Similar to PythonChallenge? I am aware of most of the programming challenge sites, idea is to find a site which helps to discover the strength and speciality of PHP Scripting the way PythonChallenge does by it's wiki's for each level. ...

Are there any programming challenges out there for R users?

Are there any websites or blogs with programming challenges specifically for R users? ...

square puzzle solution

Question: given an integer number n, print the numbers from 1 up to n2 like this: n = 4 result is: 01 02 03 04 12 13 14 05 11 16 15 06 10 09 08 07 How do you solve it (apart from the solution provided in the link below)? http://www.programmersheaven.com/mb/CandCPP/81986/81986/problem-in-making-ap-c++-program/?S=B20000 I'm looking ...

What was the best Puzzle/Brainteaser you've ever been asked at an interview? And Why?

There have been many questions related to what one should ask interviewees, what you should ask a company you're interviewing at, etc. I searched and I don't think this one is a duplicate. Also, community wiki from the start. So here goes: What is the most interesting (challenging, fun, original, useful) brainteaser or puzzle question y...

Combinitorics Counting Puzzle: Roll 20, 8-sided dice, what is the probability of getting at least 5 dice of the same value

Assume a game in which one rolls 20, 8-sided die, for a total number of 8^20 possible outcomes. To calculate the probability of a particular event occurring, we divide the number of ways that event can occur by 8^20. One can calculate the number of ways to get exactly 5 dice of the value 3. (20 choose 5) gives us the number of orders o...

Reading letters from a custom iPhone keyboard

Hi, I'm trying to build an app that is a code breaking puzzle for the user. I've followed sample code on how to add a decimal to the numeric keypad and it works great. I would like to expand this so the whole keyboard is filled with custom images. Is it possible to have a piece of code that when the user presses on a symbol the iPhone...

An interesting math puzzle

Hi StackOverflow, Although it is not very programming related but I think SO could be of some assistance: A zeroless pandigital number of base 10 is a number with all the distinct digits 1,2,3,4,5,6,7,8,9. For example, the first zeroless pandigital number of base 10 is 123456789. Find a zeroless pandigital number of base 10 such that...

sliding puzzle help!

Hi! I'm a relative novice at C# and am thoroughly stuck! I need to make a sliding puzzle where numbered tiles are to be rearranged in order by using a blank space, i.e. 1 2 3 4 5 6 7 8 I have no idea where to start! Thanks for your time! ...

Regex: Match a string containing numbers and letters but not a string of just numbers.

Question I would like to be able to use a single regex (if possible) to require that a string fits [A-Za-z0-9_] but doesn't allow: Strings containing just numbers or/and symbols. Strings starting or ending with symbols Multiple symbols next to eachother Valid test_0123 t0e1s2t3 0123_test te0_s1t23 t_t Invalid t__t ____ 0123012...

Tinyurl-style unique code: potential algorithm to prevent collisions

I have a system that requires a unique 6-digit code to represent an object, and I'm trying to think of a good algorithm for generating them. Here are the pre-reqs: I'm using a base-20 system (no caps, numbers, vowels, or l to prevent confusion and naughty words) The base-20 allows 64 million combinations I'll be inserting potentially...

Fast way to pick randomly from a set, with each entry picked only once?

I'm working on a program to solve the n queens problem (the problem of putting n chess queens on an n x n chessboard such that none of them is able to capture any other using the standard chess queen's moves). I am using a heuristic algorithm, and it starts by placing one queen in each row and picking a column randomly out of the column...