Two red beads are placed between every two blue beads. There are N blue beads. After looking at the arrangement below work out the number of red beads.

@
@@
@
@@
@
@@
@
@@
@
@@
@

Implement count_red_beads(n) (in PHP count_red_beads($n); in Java, Javascript, TypeScript, C, C++ countRedBeads(n)) so that it returns the number of red beads.
If there are less than 2 blue beads return 0.

Difficulty: EASY
Tags: Fundamentals

Starter code:
def count_red_beads(n):
	

Solutions:
def count_red_beads(nb):
	return max(0, 2 * (nb - 1))


def count_red_beads(n_blue):
	return (n_blue - 1) * 2 if n_blue >= 2 else 0


def count_red_beads(n):
	return max(0, 2 * (n - 1))


def count_red_beads(n):
	return 2 * (n - 1) if n > 1 else 0


count_red_beads = lambda b: b and b * 2 - 2


def count_red_beads(n):
	if n >= 2:
		red = n + (n - 2)
		return red
	else:
		return 0


def count_red_beads(N_blue):
	return (N_blue - 2) * 2 + 2 if N_blue > 2 else 0


def count_red_beads(N_blue):
	return max(N_blue - 1, 0) * 2


def count_red_beads(N_b):
	return 0 if N_b == 0 else (N_b - 1) * 2


count_red_beads = lambda n: n and (n - 1) * 2


def count_red_beads(N_blue):
	return N_blue and (N_blue - 1) * 2


def count_red_beads(n):
	return n and n * 2 - 2


count_red_beads = lambda b: (b > 1) * (b - 1) * 2


count_red_beads = lambda n: max(n - 1, 0) * 2


def count_red_beads(n):
	if n < 2:
		return 0
	elif n == 2:
		return 2
	else:
		return (n - 2) * 2 + 2


import math

def count_red_beads(n):
	if n < 2:
		return 0
	else:
		if n % 2 != 0:
			g = math.floor(n / 2)
			d = g * 4
			return d
		if n % 2 == 0:
			g = math.floor(n / 2)
			d = g * 4
			return d - 2


def count_red_beads(n):
	lista = []
	if n < 2:
		return 0
	for i in range(1, n):
		lista.append(i * 2)
	return lista[-1]


def count_red_beads(n):
	return 2 * n - 2 * (n > 0)


def count_red_beads(n):
	if n == 1 or n == 0:
		return 0
	return (n - 1) * 2


count_red_beads = lambda n: 0 if n in [0, 1] else (n - 1) * 2


def count_red_beads(n):
	return range(0, 10001, 2)[n - 1 if n > 0 else n]


def count_red_beads(n):
	if n - 2 < 0:
		return 0
	else:
		y = n * 2
		z = y - 2
		return z


def count_red_beads(n):
	counter = 0
	if n < 2:
		return counter
	else:
		for x in range(1, n):
			counter += 2
		return counter


def count_red_beads(n):
	if n < 2:
		return 0
	red = (n - 1) * 2
	return red


def count_red_beads(n):
	if n < 2:
		r = 0
	else:
		r = n * 2 - 2
	return r


def count_red_beads(n):
	if n <= 1:
		return 0
	elif n > 1:
		return n * 2 - 2


def count_red_beads(n):
	red_beads = 0
	if n < 2:
		return 0
	red_beads = (n - 1) * 2
	return red_beads


def count_red_beads(blue):
	if blue <= 1:
		return 0
	return (blue - 1) * 2


def count_red_beads(n):
	if n < 2:
		return 0
	else:
		count = 2
		for i in range(2, n):
			count += 2
		return count


def count_red_beads(n):
	if n >= 2:
		x = n - 2
		result = n + x
		return result
	else:
		return 0


def count_red_beads(n):
	count = 0
	if n < 2:
		return 0
	for x in range(1, n):
		count += 2
	return count


def count_red_beads(n):
	return 'rr'.join(['b' for b in range(n)]).count('r')


def count_red_beads(n):
	res = 0
	for i in range(1, n):
		res += 2
	return res


def count_red_beads(n):
	numOfRed = 0
	if n < 2:
		return 0
	else:
		numOfRed += n * 2 - 2
	return numOfRed


def count_red_beads(n):
	r = 2
	if n < 2:
		return 0
	for x in range(2, n):
		r += 2
	return r


def count_red_beads(n):
	if n < 2:
		return 0
	else:
		p = n * 2 - 2
		return p


def count_red_beads(x):
	if x > 1:
		return 2 * (x - 1)
	else:
		return 0


count_red_beads = lambda n: (0, (n - 1) * 2)[bool(n)]


def count_red_beads(n):
	if n < 2:
		return 0
	else:
		red_beds = n * 2 - 2
	return red_beds


def count_red_beads(n):
	if n == 1 or n == 0:
		return 0
	elif n % 2 != 0:
		return (n - 1) * 2
	else:
		return n * 2 - 2


def count_red_beads(n):
	if n < 2:
		return 0
	else:
		i = 0
		RedCount = -2
	while i < n:
		RedCount += 2
		i += 1
	return RedCount


def count_red_beads(n):
	beads = 0
	if n < 2:
		return 0
	else:
		for i in range(n - 1):
			beads += 2
	return beads


def count_red_beads(n):
	ecount = 2
	ocount = 4
	oplst1 = []
	if n < 2:
		return 0
	else:
		for i in range(2, n + 1):
			if i % 2 == 0:
				oplst1.append(ecount)
				ecount += 4
			else:
				oplst1.append(ocount)
				ocount += 4
		return oplst1[-1]


def count_red_beads(n):
	beads = ''
	for i in range(n - 1):
		beads += 'B'
		beads += 'RR'
	beads += 'B'
	return beads.count('R')


def count_red_beads(n):
	return ((n or 1) - 1) * 2