We have the following recursive function:



The 15-th term; ```f(14)``` is the first term in having more that 100 digits.

In fact, 
```
f(14) = 2596253046576879973769082409566059879570061514363339324718953988724415850732046186170181072783243503881471037546575506836249417271830960970629933033088

It has 151 digits.
```
Make the function ```something_acci()```, that receives ```num_dig``` (number of digits of the value) as unique argument.

```something_acci()``` will output a tuple/array with the ordinal number in the sequence for the least value in having equal or more than the given number of digits.

Let's see some cases:
```python
something_acci(20) == (12, 25)
# f(11) = 1422313222839141753028416

something_acci(100) == (15, 151)
```
The number of digits given will be always more than 5. ```num_dig > 5```.

Happy coding!!!

And the name for this kata? You have three words of the same meaning in Asian Languages.

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Mathematics

Complete search

Starter code: def something_acci(num_digits):
	

Solutions:
from functools import reduce

def product(ar):
	return reduce(lambda x, y: x * y, ar)

def something_acci(num_digits):
	seq = [1, 1, 2, 2, 3, 3]
	while len(str(seq[-1])) < num_digits:
		seq.append(product(seq[-3:]) - product(seq[-6:-3]))
	return (len(seq), len(str(seq[-1])))


def something_acci(num_digits):
	(a, b, c, d, e, f) = (1, 1, 2, 2, 3, 3)
	count = 6
	while True:
		sf = str(f)
		if len(sf) >= num_digits:
			return (count, len(sf))
		(a, b, c, d, e, f) = (b, c, d, e, f, d * e * f - a * b * c)
		count += 1


from functools import lru_cache

@lru_cache()
def f(n):
	return (1, 1, 2, 2, 3, 3)[n] if n < 6 else f(n - 1) * f(n - 2) * f(n - 3) - f(n - 4) * f(n - 5) * f(n - 6)

def something_acci(num_digits):
	(n, l) = (8, 4)
	while l < num_digits:
		n += 1
		l = len(str(f(n)))
	return (n + 1, l)


from functools import reduce
from operator import mul

def something_acci(n):
	li = [1, 1, 2, 2, 3, 3]
	while True:
		li.append(reduce(mul, li[-3:]) - reduce(mul, li[-6:-3]))
		if len(str(li[-1])) >= n:
			return (len(li), len(str(li[-1])))


def something_acci(num_digits):
	x = [1, 1, 2, 2, 3, 3]
	while True:
		if len(str(x[-1])) >= num_digits:
			return (len(x), len(str(x[-1])))
		else:
			x.append(x[-1] * x[-2] * x[-3] - x[-4] * x[-5] * x[-6])


from math import log10
seq = {0: 1, 1: 1, 2: 2, 3: 2, 4: 3, 5: 3}
len_seq = {0: 1, 1: 1, 2: 1, 3: 1, 4: 1, 5: 1}
next_term = lambda n: seq[n - 1] * seq[n - 2] * seq[n - 3] - seq[n - 4] * seq[n - 5] * seq[n - 6]
count_digits = lambda n: int(log10(n)) + 1

def something_acci(num_digits):
	i = 0
	while True:
		if i not in seq:
			n = next_term(i)
			(seq[i], len_seq[i]) = (n, count_digits(n))
		if len_seq[i] >= num_digits:
			return (i + 1, len_seq[i])
		i += 1


def something_acci(num_digits):
	a = [1, 1, 2, 2, 3, 3]
	while a[-1] < 10 ** (num_digits - 1):
		a.append(a[-1] * a[-2] * a[-3] - a[-4] * a[-5] * a[-6])
	return (len(a), len(str(a[-1])))