The number ```1331``` is the first positive perfect cube,  higher than ```1```, having all its digits odd (its cubic root is ```11```).

The next one is ```3375```.

In the interval [-5000, 5000] there are six pure odd digit perfect cubic numbers and are: ```[-3375,-1331, -1, 1, 1331, 3375]```

Give the numbers of this sequence that are in the range ```[a,b] ```(both values inclusive)

Examples:
``` python
odd_dig_cubic(-5000, 5000) == [-3375,-1331, -1, 1, 1331, 3375] # the output should be sorted.
odd_dig_cubic(0, 5000) == [1, 1331, 3375]
odd_dig_cubic(-1, 5000) == [-1, 1, 1331, 3375]
odd_dig_cubic(-5000, -2) == [-3375,-1331]

```
Features of the random tests for python:
```
number of Tests = 94
minimum value for a = -1e17
maximum value for b = 1e17
```
You do not have to check the entries, ```a``` and ```b``` always integers and ```a < b``` 

Working well in Python 2 and Python 3.
Translation into Ruby is coming soon.

Source: codewars | Difficulty: EASY
Tags: Dynamic programming

Fundamentals

Data structures

Mathematics

Starter code: def odd_dig_cubic(a, b):
	

Solutions:
from bisect import bisect_left, bisect
ss = set('13579')
ns = [i ** 3 for i in range(1, int((10 ** 17) ** (1 / 3)) + 3, 2) if set(str(i ** 3)) <= ss]
ns = [-n for n in ns[::-1]] + ns

def odd_dig_cubic(a, b):
	return ns[bisect_left(ns, a):bisect(ns, b)]


import math

def odd_dig_cubic(a, b):
	ret = []
	st = int(math.ceil(abs(a) ** (1.0 / 3.0)))
	en = int(abs(b) ** (1.0 / 3.0))
	if a < 0:
		st *= -1
	if b < 0:
		en *= -1
	for i in range(st, en):
		c = i ** 3
		if any((j in '02468' for j in str(c))):
			continue
		ret += [c]
	return ret


(s, hh) = (-464148, [])
while s < 464159:
	v = s ** 3
	(sv, b) = (str(v), 1)
	for c in sv:
		if not c in '-13579':
			b = 0
			break
	if b:
		hh.append(v)
	s += 1

def odd_dig_cubic(a, b):
	r = []
	for i in hh:
		if i >= a:
			if i <= b:
				r.append(i)
			else:
				break
	return r


CUBICS = [1, 1331, 3375, 35937, 59319, 357911, 753571, 5177717, 5359375, 5735339, 9393931, 17373979, 37595375, 37159393753, 99317171591, 175333911173, 397551775977, 1913551573375, 9735913353977, 11997979755957, 17171515157399, 335571975137771, 1331399339931331, 1951953359359375, 7979737131773191, 11751737113715977, 13337513771953951]
CUBICS = [-x for x in reversed(CUBICS)] + CUBICS

def odd_dig_cubic(a, b):
	return [x for x in CUBICS if a <= x <= b]


odd_dig_cubic = lambda a, b: [n ** 3 for n in range(int(a // abs(a or 1) * abs(a) ** 3 ** (-1)) | 1, int(b // abs(b or 1) * abs(b) ** 3 ** (-1)) | 1 + 2, 2) if a <= n ** 3 <= b and set(str(n ** 3)) <= set('-13579')]


import re
M = [M ** 3 for M in range(1, 2000000) if re.match('[13579]+$', str(M ** 3))]
M = sorted(M + [-M for M in M])
odd_dig_cubic = lambda Q, S: [V for V in M if Q <= V <= S]


def odd_dig_cubic(a, b):
	A = [-355519351557373375, -119397111955573375, -99133919737193375, -13337513771953951, -11751737113715977, -7979737131773191, -1951953359359375, -1331399339931331, -335571975137771, -17171515157399, -11997979755957, -9735913353977, -1913551573375, -397551775977, -175333911173, -99317171591, -37159393753, -37595375, -17373979, -9393931, -5735339, -5359375, -5177717, -753571, -357911, -59319, -35937, -3375, -1331, -1, 1, 1331, 3375, 35937, 59319, 357911, 753571, 5177717, 5359375, 5735339, 9393931, 17373979, 37595375, 37159393753, 99317171591, 175333911173, 397551775977, 1913551573375, 9735913353977, 11997979755957, 17171515157399, 335571975137771, 1331399339931331, 1951953359359375, 7979737131773191, 11751737113715977, 13337513771953951, 99133919737193375, 119397111955573375, 355519351557373375]
	return [i for i in A if a <= i <= b]


def get_podpc():
	r = []
	x = 1
	while x * x * x <= 1e+17:
		y = x * x * x
		if all((int(d) % 2 == 1 for d in str(y))):
			r.append(y)
		x += 2
	return sorted([-1 * x for x in r] + r)
arr = get_podpc()

def odd_dig_cubic(a, b):
	return [x for x in arr if a <= x <= b]


def int_root3(x):
	x3 = int(x ** (1 / 3))
	while (x3 + 1) ** 3 < x:
		x3 += 1
	return x3

def odd_dig_cubic(a, b):
	if 0 <= a <= b:
		left = int_root3(a) + 1 | 1
		right = int_root3(b) | 1
	elif a <= 0 <= b:
		left = 1
		right = int_root3(b) | 1
	else:
		left = int_root3(abs(b)) + 1 | 1
		right = int_root3(abs(a)) | 1
	result = []
	for i in range(left, right + 1, 2):
		i3 = i ** 3
		if set(str(i3)) <= set('13579'):
			if a <= i3 <= b:
				result.append(i3)
			if a <= -i3 <= b:
				result.append(-i3)
	return sorted(result)