Programming Challenges

Hello everyone and welcome to Jackson's Compendium of Programming Challenges!!

In the Forums, I will post some challenging problems for the more advanced people.

The idea behind these problems is you will be given a hypothetical scenario in which there is something you need to work out, such as how many ways you can move between two points on a roadmap, or which choices you will select to maximise your score in a game. You don't want to do it by hand because that would be too long and boring. Instead, you will make a computer program to solve the problem for you. Hooray!

Each problem has a specific task which your computer program must complete correctly.

If you think you have a solution to a problem you can show me, send it to me (jackson.gatenby of gmail) or upload the source file to this page (please to be not stealing code and using it for own submissions…).

I will always accept solutions in C, C++ and Python. Others, please try to arrange with me. No, I cannot (or do not want to) fluently read Brainf***, Whitespace, or any other esoteric languages. If these aren't enough for you, tell me and I'll show you more.

See below for some of the recent challenges… For a full list, find "Programming Challenges" in the forums


Fibonacci

The Fibonacci sequence is well known in mathematics. The first two values are 1 and 1, and every other value is the sum of the two previous values. The first dozen Fibonacci numbers are thus

1 1 2 3 5 8 13 21 34 55 89 144…

Write a program that displays the largest Fibonacci number less than or equal to a limit supplied to the program on each test run. For example, if the limit is 50, the program should just show 34.

Constraints - you may assume the limit is less than one million.

Run your program on the following three test cases:

Test Input
8
234
876543

Comments: 0


Super Primes

What are Super Primes?

  • A Super Prime is a prime number with the additional interesting property that as each digit is removed from the right the number which remains is a prime.

Instructions

The following is a list of Super Primes of length 4:
2333
2339
2393
2399
2939
3119
3137
3733
3739
3793
3797
5939
7193
7331
7333
7393

Instructions

  • Write a program that prints all super primes of length 6
  • Your output should contain each Super Prime on a line each.
  • Output sould be in ascending order.
  • No other output should be produced by your program other than the numbers.

If you can use File I/O, output your answer to "primes.txt"

Comments: 0


Wordsworth

You are to write a program which will work out the value of a piece of text. It is to do this by counting the number of letters in each word in the text.

The text is a list of words, separated by at least one spaces, possibly together with some punctuation and/or line breaks. The length of each word corresponds to a digit in the "value", with a word of length 10 corresponding to the digit 0. There is to be a decimal point after the first digit.

For example the phrase "How I need a monkey" has words of length 3, 1, 4, 1 and 6 respectively. This is worth 3.1416 (coincidentally this is pi to 4 decimal places).

You are to write a program which, given such a message, returns its value.

You may assume that there are between two and sixty words in the message, and that no word is longer than ten letters. You may also assume that the input will all be on one line of text, and each word will have at least one letter.

Sample Input Sample Output
But a time I spent wandering in bloomy night yon towers 3.1415926536
By fleeing a dinosaur in Slovakia, a dinosaur in Slovakia made escape! 2.71828182846
S. Wordsworth 1.0

Comments: 0

Unless stated otherwise Content of this page is licensed under Creative Commons Attribution-NonCommercial 3.0 License