Random string fun
CSS2 Cheat Sheet
Developer feeling
Linux Lovers….
What is the dumbest code ever made that has become famous?
BogoSort is a moderately well-known algorithm to sort a list. Here’s how it works:
- Put the elements of the list in a random order.
- Check if the list is sorted. If not, start over.
BogoSort has an average running time of O((n+1)!), which is not very good. It is also the rare algorithm which has NO worst-case running time; if the input has at least two elements, it is possible for the algorithm to run for any amount of time.
CodeEval: Penultimate Word
Challenge Description:
Write a program which finds the next-to-last word in a string.
Input Sample:
Your program should accept as its first argument a path to a filename. Input example is the following
some line with text another line
Each line has more than one word.
Output Sample:
Print the next-to-last word in the following way.
with another
Solution:
CodeEval: Shortest Repetition
Challenge Description:
Write a program to determine the shortest repetition in a string.
A string is said to have period p if it can be formed by concatenating one or more repetitions of another string of length p. For example, the string “xyzxyzxyzxyz” has period 3, since it is formed by 4 repetitions of the string “xyz”. It also has periods 6 (two repetitions of “xyzxyz”) and 12 (one repetition of “xyzxyzxyzxyz”).
Input Sample:
Your program should accept as its first argument a path to a filename. Each line will contain a string of up to 80 non-blank characters. E.g.
abcabcabcabc bcbcbcbcbcbcbcbcbcbcbcbcbcbc dddddddddddddddddddd adcdefg
Output Sample:
Print out the smallest period of the input string. E.g.
3 2 1 7
Solution:
The feeling when the code doesn’t work…
CodeEval: PASS TRIANGLE
CHALLENGE DESCRIPTION:
By starting at the top of the triangle and moving to adjacent numbers on the row below, the maximum total from top to bottom is 27.
5 9 6 4 6 8 0 7 1 5
5 + 9 + 6 + 7 = 27
INPUT SAMPLE:
Your program should accept as its first argument a path to a filename. Input example is the following:
5 9 6 4 6 8 0 7 1 5
You make also check full input file which will be used for your code evaluation.
OUTPUT SAMPLE:
The correct output is the maximum sum for the triangle. So for the given example the correct answer would beĀ 27