Все вопросы: [puzzle]

95 вопросов

5
голосов
2ответов
849 просмотров

Help understanding Sieve of Eratosthenes implementation

This is boring, I know, but I need a little help understanding an implementation of the Sieve of Eratosthenes. It's the solution to this Programming Praxis problem. (define (primes n) (let* ((max-index (quotient (- n 3) 2)) (v (make-vector (+ 1 max-index) #t))) (let loop ((i 0) (p...

0
голосов
3ответов
841 просмотров

duplicacy problems while creating a sudoku puzzle

I am trying to create my own normal 9x9 sudoku puzzle. I divided the problem into two parts - creating a fully filled sudoku, and removing unnecessary numbers from the grid Right now, I am stuck with the first part. This is the algorithm I use in brief: a) first of all I choose a number...

2
голосов
2ответов
265 просмотров

Java Puzzler - Can anyone explain this behavior?

abstract class AbstractBase { abstract void print(); AbstractBase() { // Note that this call will get mapped to the most derived class's method print(); } } class DerivedClass extends AbstractBase { int value = 1; @Override void print() { System....

16
голосов
10ответов
15427 просмотров

Compile time sizeof_array without using a macro

This is just something that has bothered me for the last couple of days, I don't think it's possible to solve but I've seen template magic before. Here goes: To get the number of elements in a standard C++ array I could use either a macro (1), or a typesafe inline function (2): (1) #define si...

4
голосов
10ответов
1155 просмотров

Code Golf - Word Scrambler

Please answer with the shortest possible source code for a program that converts an arbitrary plaintext to its corresponding ciphertext, following the sample input and output I have given below. Bonus points* for the least CPU time or the least amount of memory used. Example 1: Plaintext: The ...

19
голосов
6ответов
31832 просмотров

What can be the efficient approach to solve the 8 puzzle problem?

The 8-puzzle is a square board with 9 positions, filled by 8 numbered tiles and one gap. At any point, a tile adjacent to the gap can be moved into the gap, creating a new gap position. In other words the gap can be swapped with an adjacent (horizontally and vertically) tile. The objective in the...

1
голосов
4ответов
919 просмотров

Coding brain teaser to update an array (language agnostic)

All, I need a clever way to implement this algorithm (for work) as quickly and cleanly as possible: I think I've removed all the language specific issues and boiled it down to this: I have two arrays: A and B. A has a list of names in it {Apple, Apple, Banana, Banana, Banana, Carrot, ...} eac...

4
голосов
2ответов
1433 просмотров

Java metaprogramming conundrum: get all annotations that are themselves annotated by a given annotation A

Do you think you are a java wizard? That you are well versed in the secrets of the reflection API? public @interface @a {} public @interface @b {} @Mark public @interface @c {} @Mark public @interface @d {} public @interface @e {} public Class C { @a @b @c @d @e public void x(); } pub...

1
голосов
3ответов
310 просмотров

Main class block in '{}' never executes

Consider the following code:- class Name { {System.out.println("hi");} public static void main(String[] args) { System.out.println(waffle()); } static boolean waffle() { try { return true; } finally { return false; } ...

5
голосов
3ответов
3852 просмотров

Finding patterns in Puzzle games

I was wondering, which are the most commonly used algorithms applied to finding patterns in puzzle games conformed by grids of cells. I know that depends of many factors, like the kind of patterns You want to detect, or the rules of the game...but I wanted to know which are the most commonly use...

3
голосов
4ответов
857 просмотров

Routing "paths" through a rectangular array

I'm trying to create my own implementation of a puzzle game. To create my game board, I need to traverse each square in my array once and only once. The traversal needs to be linked to an adjacent neighbor (horizontal, vertical or diagonal). I'm using an array structure of the form: boar...

3
голосов
3ответов
1141 просмотров

Solution to classic "Blockbuster"

In the UK throughout the 80's and 90's (70's too I believe!) there was a classic TV program called "Blockbuster", which had a display of hexagons in a honeycomb grid, like this (sorry for blurry pic!): (source: ukgameshows.com) As you can see, there are 5 columns of letters and four rows. 1 ...

13
голосов
3ответов
19735 просмотров

why is 24 * 60 * 60 * 1000 * 1000 divided by 24 * 60 * 60 * 1000 not equal to 1000 in Java?

why is 24 * 60 * 60 * 1000 * 1000 divided by 24 * 60 * 60 * 1000 not equal to 1000 in Java?

2
голосов
3ответов
1794 просмотров

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 p...

7
голосов
6ответов
1731 просмотров

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 ...

3
голосов
9ответов
4635 просмотров

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 t...

2
голосов
3ответов
1219 просмотров

An interesting math puzzle

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 num...

0
голосов
1ответов
863 просмотров

Reading letters from a custom iPhone keyboard

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 th...

3
голосов
7ответов
3390 просмотров

Combinatorics 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...

5
голосов
5ответов
3396 просмотров

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-mak...

8
голосов
3ответов
5439 просмотров

Are there any programming challenges out there for R users?

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

3
голосов
3ответов
364 просмотров

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...

8
голосов
11ответов
9254 просмотров

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...

3
голосов
4ответов
1250 просмотров

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

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 to form a shape in a feasable way that takes into account the fact t...

4
голосов
8ответов
440 просмотров

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 w...

16
голосов
11ответов
24244 просмотров

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...

14
голосов
8ответов
6060 просмотров

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 ...

2
голосов
8ответов
2109 просмотров

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 representat...

6
голосов
3ответов
1751 просмотров

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. (source: hacker.org) Here is how the puzzle works: by choosing a color from the ...

114
голосов
35ответов
194314 просмотров

Как найти все комбинации монет при некоторой долларовой стоимости

Я нашел фрагмент кода, который писал для подготовки к собеседованию несколько месяцев назад. Согласно моему комментарию, он пытался решить эту проблему: Учитывая некоторую долларовую стоимость в центах (например, 200 = 2 доллара, 1000 = 10 долларов), найдите все комбинации монет, состав...