Skip to content

Instantly share code, notes, and snippets.

View rbelando's full-sized avatar
🏠
Working from home

rbelando

🏠
Working from home
  • Olivia Smile
  • Montgat
View GitHub Profile
# Given an array of 0s and 1s that represent a garden, where 0 is a plot that
# hasn’t been planted on, and 1 is a plot that has been planted on, return true
# if n plants can be planted without touching another plant.
def can_plant(garden: list, position: int):
position = position - 1
available = get_available_plots(garden)
available_count = len(available)
if available_count > position:
@rbelando
rbelando / pascals_triangle.py
Created March 17, 2021 18:55
return an array of the values in that row of Pascal’s Triangle
# Given a rowIndex, return an array of the values in that row of Pascal’s Triangle.
# Example:
# $ pascals(0)
# $ [1]
# $ pascals(3)
# $ [1,3,3,1]
def pascals(n):
list = []
index_value = 1
array = ['h','e','l','o',' ','w','r','d','!',',']
string = array[0].capitalize() + array[1] + array[2] + array[2] + array[3] +\
array[9] + array[4] + array[5] + array[3] + array[6] + array[2] + array[7] + array[8]
print(string)
def factorial(number: int):
if number == 0:
r = 1
else:
r = number * factorial(number - 1)
return r
def is_factorial(number: int) -> bool:
result = False
struct Element {
var name: String
var weakness: String
var beat: String
init(name: String, weakness: String, beat: String) {
self.name = name
self.weakness = weakness
self.beat = beat
}