5 kyu
Fibo akin
495 of 1,996g964
Description:
Be u(n) a sequence beginning with:
u[1] = 1, u[2] = 1, u[3] = 2, u[4] = 3, u[5] = 3, u[6] = 4,
u[7] = 5, u[8] = 5, u[9] = 6, u[10] = 6, u[11] = 6, u[12] = 8,
u[13] = 8, u[14] = 8, u[15] = 10, u[16] = 9, u[17] = 10, u[18] = 11,
u[19] = 11, u[20] = 12, u[21] = 12, u[22] = 12, u[23] = 12 etc...
- How is
u[8]
calculated?
We have u[7] = 5
and u[6] = 4
. These numbers tell us that we have to go backwards from index 8
to index 8 - 5 = 3
and to index 8 - 4 = 4
so to index 3
and 4
.
u[3] = 2
and u[4] = 3
hence u[8] = u[3] + u[4] = 2 + 3 = 5
.
- Another example: let us calculate
u[13]
. At indexes12
and11
we have8
and6
. Going backwards of8
and6
from13
we get indexes13 - 8 = 5
and13 - 6 = 7
.
u[5] = 3
and u[7] = 5
so u[13] = u[5] + u[7] = 3 + 5 = 8
.
Task
- Express u(n) as a function of n, u[n - 1], u[n - 2]. (not tested).
- Given two numbers
n, k (integers > 2)
write the functionlength_sup_u_k(n, k) or lengthSupUK or length-sup-u-k
returning the number of termsu[i] >= k
with1 <= i <= n
. If we look above we can see that betweenu[1]
andu[23]
we have fouru[i]
greater or equal to12
:length_sup_u_k(23, 12) => 4
- Given two numbers
- Given
n (integer > 2)
write the functioncomp(n)
(cmp
in COBOL) returning the number of times where a term ofu
is less than its predecessor up to and including u[n].
- Given
Examples:
u(900) => 455 (not tested)
u(90000) => 44337 (not tested)
length_sup_u_k(23, 12) => 4
length_sup_u_k(50, 10) => 35
length_sup_u_k(500, 100) => 304
comp(23) => 1 (since only u(16) < u(15))
comp(100) => 22
comp(200) => 63
Note: Shell
Shell tests only lengthSupUk
Algorithms
Recursion
Stats:
Created | Jun 28, 2016 |
Published | Jun 28, 2016 |
Warriors Trained | 11970 |
Total Skips | 5184 |
Total Code Submissions | 5404 |
Total Times Completed | 1996 |
Ruby Completions | 53 |
Python Completions | 495 |
Java Completions | 178 |
C# Completions | 115 |
Elixir Completions | 32 |
Clojure Completions | 23 |
JavaScript Completions | 253 |
CoffeeScript Completions | 9 |
TypeScript Completions | 64 |
Haskell Completions | 45 |
C++ Completions | 214 |
PHP Completions | 48 |
F# Completions | 21 |
C Completions | 190 |
Crystal Completions | 9 |
OCaml Completions | 24 |
Rust Completions | 100 |
Swift Completions | 49 |
Go Completions | 93 |
R Completions | 33 |
Shell Completions | 7 |
Kotlin Completions | 54 |
Fortran Completions | 12 |
Groovy Completions | 7 |
Julia Completions | 22 |
Scala Completions | 27 |
PowerShell Completions | 10 |
Nim Completions | 6 |
Reason Completions | 4 |
Lua Completions | 30 |
Pascal Completions | 8 |
Perl Completions | 7 |
COBOL Completions | 6 |
D Completions | 7 |
Erlang Completions | 5 |
Total Stars | 177 |
% of votes with a positive feedback rating | 88% of 337 |
Total "Very Satisfied" Votes | 267 |
Total "Somewhat Satisfied" Votes | 59 |
Total "Not Satisfied" Votes | 11 |
Total Rank Assessments | 8 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 4 kyu |
Lowest Assessed Rank | 6 kyu |