background preloader

Puzzles

Facebook Twitter

Wolfram

Ita. Technology, one bit at a time. Collection Of Puzzles For Programmers. Collection Of Puzzles For Programmers by SQLDenis on March 2, 2009 in category Ethics and IT.

Collection Of Puzzles For Programmers

Article views: 84,093 Instapaper Did you know that we have a nice collection of puzzles here on less than dot? Some are harder than others so there is something for everyone. Here is a partial list of what we have Friday the Thirteenths The goal is to identify all friday the thirteenths for a given timeframe Regular Pentagon Given a grid co-ordinate (x,y) as the centre point of a regular pentagon, and the sum of the length of the sides, return the co-ordinates of each point as: “Top”, “MidLeft”, “MidRight”, “BottomLeft”, “BottomRight” and the distance from the centre to each of the points. ASCII Art Shapes Create some ASCII art in the shortest code possible Finding Prime Numbers Find every prime number between 0 and 1,000,000 Calculating the Fibonacci Sequence Calculate ‘X’ numbers in the Fibonacci Sequence, which is essentially adding the previous 2 occurring numbers together to make the next puzzles. How to Shuffle an Array (Correctly) Today at a career fair, an Amazon recruiter asked me how to shuffle an array.

Sounds like an easy problem, right? It turns out a good majority of people posting code to the internet get it wrong. But before reading on, try it out yourself, see what you come up with, and then Google for "array shuffle" or "randomize array" to see what other people think. Two approaches came to mind: iterate through all of the elements, swapping each element with some random location in the array, or iterate through all of the elements, swapping each element with some random current-or-later location in the array. If you're like me, something bugs you about both these approaches.

Only later did I prove to myself that the current-or-later algorithm works. What about the alternative, just swapping each element with any old element? Let's start with the fact that the number of possible permutations of an n-element array is n!. But this equation is not satisfiable for all values of n. Ruby Quiz. Ninety-Nine Lisp Problems. P01 (*) Find the last box of a list.

Ninety-Nine Lisp Problems

Example: * (my-last '(a b c d)) (D) P02 (*) Find the last but one box of a list. Example: * (my-but-last '(a b c d)) (C D) P03 (*) Find the K'th element of a list. The first element in the list is number 1. P04 (*) Find the number of elements of a list.P05 (*) Reverse a list.P06 (*) Find out whether a list is a palindrome. A palindrome can be read forward or backward; e.g. P07 (**) Flatten a nested list structure. Transform a list, possibly holding lists as elements into a `flat' list by replacing each list with its elements (recursively). Example: * (my-flatten '(a (b (c d) e))) (A B C D E) Hint: Use the predefined functions list and append. P08 (**) Eliminate consecutive duplicates of list elements. If a list contains repeated elements they should be replaced with a single copy of the element.