Algorithms 1
Solve these problems in either Java or Python and email your solution to ben@suits.org.au
Problem 1
Given a list of numbers as input from stdin, output the two numbers with the smallest difference.
Example:
Input
5 26 78 51 100 62 84
Output
78 84
Problem 2
Given some n and a string, caesar cypher the string by the number n ignoring spaces and punctuation. All letters will be lower case.
Example:
Input
2
hello world!
Output
jgnnq yqtnf!
Problem 3
Given some number n, determine whether it is a Lonely Prime. Print "yes" if it is, "no" if it is not.
A number X is not lonely if there exists another number Z whose digits summed, plus itself, are equal to X.
So 15 is not lonely as (12 + 1 + 2 = 15).
A number Y is prime if it is greater than 1 and is only cleanly divisible (ie no remainder) by 1 and itself.
A number is a lonely prime if it is both lonely and prime.
Example:
Input
15
Output
no
Input
31
Output
yes
Problem 4
Jason loves potatoes, carrots and broccolli just like any good boy. Except he never
likes eating any of these foods alone. He can fit two pieces of food on his fork at once.
Given how many pieces of potatoes, carrots and broccolli there are print out a series of
steps he can take to eat the serving correctly. If there is no solution you should print
"none".
Input Format:
np nc nb
(Number of Potatoes, Number of Carrots, Number of Brocolli)
Output Format:
Series of Combinations on new lines for each combination.
(Each combination can be either pc, cb or pb (Potato-Carrots, Carrots-Broccoli or Potato-Broccoli)
Example:
Input
2 2 2
Output
pc
cb
pb
Input
3 3 3
Output
None