5
For example, if n
is 5 and r
is 2, it would mean the number of lists below:
[1,1,1,1,1]
[1,1,1,2,2]
[1,1,2,2,2]
[2,2,1,1,1]
[2,2,2,1,1]
[2,2,2,2,2]
which is 6.
If n
is 4 and r
is 3:
[1,1,1,1]
[1,1,2,2]
[1,1,3,3]
[2,2,1,1]
...
[3,3,3,3]
which is 9.
where each item has a neighbour whose value is the same.
For example, [1,2,1,1,2]
is not counted, because both 2
are alone.
Goal
Your task is to write a program/function which takes two inputs in any order, and which produces the required output.
Detail
You can assume that r≥2
.
Scoring
This is code-golf. Shortest solution in bytes wins.
Bonus
Multiply your score by 0.3 if the complexity of your program is below O(e^n).
For example, 10 bytes becomes 3 bytes.
Testcases
Can be generated from this Pyth test suite.
Usage: two lines per testcase, n
on top, r
below.
n r output
2 5 5
4 4 16
6 3 33
8 2 26
Additional information
When r=2
: OEIS A006355.
what about ranking complexities from O(n^k) to O(n), craming all approaches below O(r^n) in one jar isnt that judicious (in addition that i dont claim this knowingly of any solution-shortcut) – Abr001am – 2016-05-01T12:27:57.807
@Jakube Yes you can. – Leaky Nun – 2016-05-01T13:01:50.910
I don't understand those test cases. In particular, if
n=2
, then there can only ber
solutions i.e. two of the same object. – Neil – 2016-05-01T13:41:11.283@Neil Yes, you are correct. – Leaky Nun – 2016-05-01T13:42:22.497
@Jakube Thanks, fixed. – Leaky Nun – 2016-05-01T14:28:28.897
1Also, you're using the
O
notation wrong - beingO(e^n)
means being not asymptotically greater thane^n
- son
isO(e^n)
, and being "less thanO(e^n)
" doesn't make much sense. – proud haskeller – 2016-05-01T15:40:30.0801@proudhaskeller Colloquially, "less than O(something)" means "has an upper bound of less than something". As the meaning is understood, extra qualifications are unnecessary. – Fund Monica's Lawsuit – 2016-05-01T16:12:13.773