Categories
Puzzles

Cut a gold bar into seven pieces with two cuts.

This is how the problem was phrased when I found it on the web.

You’ve got someone working for you for seven days and a gold bar to pay them. The gold bar is segmented into seven connected pieces. You must give them a piece of gold at the end of every day. If you are only allowed to make two breaks in the gold bar, how do you pay your worker?

Categories
Programming

Function to generate the Fibonacci numbers.

Write a function to print the Fibonacci numbers.

The fibonacci sequence is a set of numbers formed by

F_n = F_{n-1} + F_{n-2},\!\,

with seed values

F_0 = 0 \quad\text{and}\quad F_1 = 1.

This generates the numbers using the following set of rules….

 \begin{align} 0 + 1 &= 1 \\ 1 + 1 &= 2 \\ 1 + 2 &= 3 \\ 2 + 3 &= 5 \\ 3 + 5 &= 8 \\ 5 + 8 &= 13 \\  &\;\vdots \end{align}

So the fibonacci sequence is 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89,…

Categories
Uncategorized

Given a string containing a sentence reverse the words in a string.

Reverse the words in a sentence, i.e. “My name is Chris” becomes “Chris is name My.” Optimize for speed. Optimize for space.

Categories
Uncategorized

Calculate a substring

Find a substring. Optimize for speed. Optimize for space.

Categories
Uncategorized

Compare two strings

Compare two strings using O(n) time with constant space.
Categories
Uncategorized

Implement the standard string library functions

  • Implement strstr() (or some other string library function).
   strlen()    Get length of a string.
   strcpy()    Copy one string to another.
   strcat()    Link together (concatenate) two strings.
   strcmp()    Compare two strings.
   strchr()    Find character in string.
   strstr()    Find string in string.
   strlwr()    Convert string to lowercase.
   strupr()    Convert string to uppercase.
Categories
Uncategorized

Implement an algorithm to do wild card string matching

Implement an algorithm to do wild card string matching
Categories
Uncategorized

Write a function to print all of the permutations of a string

  • Write a function to print all of the permutations of a string.
Categories
Uncategorized

Write A to I

  • Write a function that takes in a string parameter and checks to see whether or not it is an integer, and if it is then return the integer value
Categories
Uncategorized

Algorithm to reverse a linked list in O(n) time

Implement an algorithm to reverse a linked list. Now do it without recursion.