Given a function which produces a random integer in the range 1 to 5, write a function which produces a random integer in the range 1 to 7
What is simple solution What is effective solution to less minimum memory and(or) cpu speed? ...
What is simple solution What is effective solution to less minimum memory and(or) cpu speed? ...
Suppose we have a vector/array in C++ and we wish to count which of these N elements has maximum repetitive occurrences and output the highest count. Which algorithm is best suited for this job. example: int a = { 2, 456, 34, 3456, 2, 435, 2, 456, 2} the output is 4 because 2 occurs 4 times. That is the maximum number of times 2 occu...
Problem: Given a list of strings, find the substring which, if subtracted from the beginning of all strings where it matches and replaced by an escape byte, gives the shortest total length. Example: "foo", "fool", "bar" The result is: "foo" as the base string with the strings "\0", "\0l", "bar" and a total length of 9 bytes. "\0" is ...
Without running this code, identify which Foo method will be called: class A { public void Foo( int n ) { Console.WriteLine( "A::Foo" ); } } class B : A { /* note that A::Foo and B::Foo are not related at all */ public void Foo( double n ) { Console.WriteLine( "B::Foo" ); } } static void Main( string[]...
This is a part algorithm-logic question (how to do it), part implementation question (how to do it best!). I'm working with Django, so I thought I'd share with that. In Python, it's worth mentioning that the problem is somewhat related to how-do-i-use-pythons-itertoolsgroupby. Suppose you're given two Django Model-derived classes: fro...
I saw this question on Reddit, and there were no positive solutions presented, and I thought it would be a perfect question to ask here. This was in a thread about interview questions: Write a method that takes an int array of size m, and returns (True/False) if the array consists of the numbers n...n+m-1, all numbers in that range a...
There is another recent Project Euler question but I think this is a bit more specific (I'm only really interested in PHP based solutions) so I'm asking anyway. Question #5 tasks you with: "What is the smallest number that is evenly divisible by all of the numbers from 1 to 20?" Now, I have solved it twice. Once very inefficiently and ...
With one worker, who can only perform one task at a time (but can switch between tasks instantly) Given a list of tasks, -- defined as "n seconds, every m seconds" (eg, 5 seconds every 3600 seconds) How could I find the best starting times and count for each task? If every task were "1 second, every 60 seconds", each would have an uni...
We all know that you can overload a function according to the parameters: int mul(int i, int j) { return i*j; } std::string mul(char c, int n) { return std::string(n, c); } Can you overload a function according to the return value? Define a function that returns different things according to how the return value is used: int n = mul(...
... using any comparison operators... and without using if, else, etc. ...
I'm practicing for the upcoming ACM programming competition in a week and I've gotten stumped on this programming problem. The problem is as follows: You have a puzzle consisting of a square grid of size 4. Each grid square holds a single coin; each coin is showing either heads (H) and tails (T). One such puzzle is shown here: H...
Is there a practical algorithm that gives "multiplication chains" To clarify, the goal is to produce a multiplication change of an arbitrary and exact length Multiplication chains of length 1 are trivial. A "multiplication chain" would be defined as 2 numbers, {start} and {multiplier}, used in code: Given a pointer to array of size ...
You are given a 32-bit unsigned integer array with length up to 232, with the property that more than half of the entries in the array are equal to N, for some 32-bit unsigned integer N. Find N looking at each number in the array only once and using at most 2 kB of memory. Your solution must be deterministic, and guaranteed to find N. ...
It's kind of a C puzzle. You have to tell if the program finish its execution, if so, how much time it takes to run and what it returns to the OS. static unsigned char buffer[256]; int main(void) { unsigned char *p, *q; q = (p = buffer) + sizeof(buffer); while (q - p) { p = buffer; while (!++*p++); } return...
Hey!! I am trying to resolve Euler Problem 18 -> http://projecteuler.net/index.php?section=problems&id=18 I am trying to do this with c++ (I am relearning it and euler problems make for good learning/searching material) #include <iostream> using namespace std; long long unsigned countNums(short,short,short array[][15],short,boo...
Okay, this bugged me for several years, now. If you sucked in statistics and higher math at school, turn away, now. Too late. Okay. Take a deep breath. Here are the rules. Take two thirty sided dice (yes, they do exist) and roll them simultaneously. Add the two numbers If both dice show <= 5 or >= 26, throw again and add the result to...
Edit: this puzzle is also known as "Einstein's Riddle" The Who owns the Zebra is an example of a classic set of puzzles and I bet that most people on Stack Overflow can solve it with pen and paper. But what would a programmatic solution look like? Based on the clues listed below... There are five houses. Each house has its own unique...
This is intended to be a more concrete, easily expressable form of my earlier question. Take a list of words from a dictionary with common letter length. How to reorder this list tto keep as many letters as possible common between adjacent words? Example 1: AGNI, CIVA, DEVA, DEWA, KAMA, RAMA, SIVA, VAYU reorders to: AGNI, CIVA, SI...
Programing puzzles can be a great way to practice your skills and kill time between projects. What sources do you use for programing puzzles? ...
[EDIT]In Short: How would you write an automatic spell checker? The idea is that the checker builds a list of words from a known good source (a dictionary) and automatically adds new words when they are used often enough. Words which haven't been used a while should be phased out. So if I delete part of a scene which contains "Mungrohype...