13
1
This is a math problem which takes quite many things into question, making it rather challenging, and as you might have guessed, it's a code golf, so it should be as short as possible as well.
The input, n
, is any integer number (should at least support integers, but needn't be limited to). The output is the average of:
n
- The square of
n
- The closest prime number to
n
- The closest number to
n
in the Fibonacci sequence
Shortly, the program should print to the standard output channel the result of (n+(n*n)+closestPrime(n)+closestFib(n))/4
.
You don't have to care about possible overflows etc. Normal floating point precision is also ok.
The way the input is given is completely up to you. Shortest program (in characters) wins, as always with code golfs.
In the case a tie occurs when you are looking for the closest, choose one of the following:
- Go up
- Go down
- Choose one randomly
a) any integer includes, in my usage of the word, zero and numbers below zero. b) the first Fibonacci number is 1, isn't it? c) the first prime is 2 d) The next prime to two - do you consider it to be 2 or 3? – user unknown – 2012-05-26T22:23:49.150
Define "closest". How are ties broken? – Peter Taylor – 2011-04-06T18:53:30.947
@Peter Taylor: Move up, down, or choose one randomly. – Anto – 2011-04-06T18:55:58.410
Give some sample input/output to verify the solutions. – fR0DDY – 2011-04-07T03:26:59.383
When you say “mustn't be limited to”, what else must be supported? Or did you mean “needn't be limited to”? – Timwi – 2011-04-10T02:05:56.750
@Timwi! "needn't", sorry, will fix it – Anto – 2011-04-10T06:22:43.783
c'mon, let's get a Perl regex somewhere here! – Simon Kuang – 2014-08-03T04:23:47.887