🎉 Hello world
This commit is contained in:
92
ElectronicStation/find-sequence.py
Normal file
92
ElectronicStation/find-sequence.py
Normal file
@@ -0,0 +1,92 @@
|
||||
def checkio(matr):
|
||||
"""
|
||||
Given the matrix NxN (4<=N<=10). Check if 4 numbers in sequence in a column or in a row or diagonally exist.
|
||||
"""
|
||||
for r in matr: # horizontal
|
||||
if checkline(r):
|
||||
return True
|
||||
for r in zip(*matr): # vertical
|
||||
if checkline(r):
|
||||
return True
|
||||
print(matr)
|
||||
for r in range(0, len(matr)): # diagonal
|
||||
for c in range(0, len(matr[0])):
|
||||
ret = []
|
||||
rx = r
|
||||
cx = c
|
||||
while True:
|
||||
print('r = ', str(rx))
|
||||
print('c = ', str(cx))
|
||||
ret.append(matr[rx][cx])
|
||||
rx = rx + 1
|
||||
cx = cx + 1
|
||||
if cx >= len(matr[0]) or rx >= len(matr):
|
||||
break
|
||||
if checkline(ret):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def checkline(l):
|
||||
c = 0
|
||||
p = ''
|
||||
for x in l:
|
||||
if p == '':
|
||||
p = x
|
||||
c = 1
|
||||
continue
|
||||
if p == x:
|
||||
c += 1
|
||||
if c >= 4:
|
||||
return True
|
||||
else:
|
||||
c = 0
|
||||
p = x
|
||||
return False
|
||||
# len([x for x in l if l.count(x) == 4]) > 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
assert checkio([
|
||||
[1, 1, 1, 1],
|
||||
[1, 2, 3, 4],
|
||||
[5, 4, 3, 1],
|
||||
[6, 1, 3, 2]
|
||||
]) == True, "First, horizontal"
|
||||
assert checkio([
|
||||
[7, 6, 5, 7, 9],
|
||||
[8, 7, 3, 6, 5],
|
||||
[4, 0, 6, 5, 4],
|
||||
[9, 8, 4, 0, 5],
|
||||
[2, 10, 7, 2, 10]
|
||||
]) == False, "Second"
|
||||
assert checkio([
|
||||
[10, 1, 9, 6, 4, 1],
|
||||
[2, 5, 4, 2, 2, 7],
|
||||
[2, 2, 1, 2, 6, 4],
|
||||
[3, 2, 2, 1, 0, 2],
|
||||
[7, 9, 6, 2, 5, 7],
|
||||
[7, 3, 10, 5, 6, 2]
|
||||
]) == True, "Third"
|
||||
assert checkio([
|
||||
[6, 6, 7, 7, 7],
|
||||
[1, 7, 3, 6, 5],
|
||||
[4, 1, 2, 3, 2],
|
||||
[9, 0, 4, 0, 5],
|
||||
[2, 0, 7, 5, 10]
|
||||
]) == False, "fourth"
|
||||
assert checkio([
|
||||
[1, 1, 1, 6, 1, 1, 1],
|
||||
[2, 5, 4, 2, 2, 7, 2],
|
||||
[2, 6, 1, 2, 6, 4, 3],
|
||||
[3, 2, 2, 1, 0, 2, 4],
|
||||
[7, 9, 6, 2, 5, 7, 5],
|
||||
[7, 3, 10, 5, 6, 2, 5],
|
||||
[7, 3, 10, 5, 6, 2, 5]
|
||||
]) == False, "Fifth"
|
||||
assert checkio([
|
||||
[1, 1, 3, 1],
|
||||
[1, 2, 3, 4],
|
||||
[5, 4, 3, 1],
|
||||
[6, 1, 3, 2]
|
||||
]) == True, "Six, vertircal"
|
19
ElectronicStation/roman-numerals.py
Normal file
19
ElectronicStation/roman-numerals.py
Normal file
@@ -0,0 +1,19 @@
|
||||
def checkio(data):
|
||||
mille = ['', 'M', 'MM', 'MMM']
|
||||
centaine = ['', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM']
|
||||
dixaine = ['', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC']
|
||||
unite = ['', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX']
|
||||
return mille[int(data / 1000)] + \
|
||||
centaine[int(data % 1000 / 100)] + \
|
||||
dixaine[int(data % 1000 % 100 / 10)] + \
|
||||
unite[int(data % 1000 % 100 % 10)]
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# These "asserts" using only for self-checking and not necessary for auto-testing
|
||||
assert checkio(6) == 'VI', '6'
|
||||
assert checkio(76) == 'LXXVI', '76'
|
||||
assert checkio(499) == 'CDXCIX', '499'
|
||||
assert checkio(3888) == 'MMMDCCCLXXXVIII', '3888'
|
||||
assert checkio(3999) == 'MMMCMXCIX', '3999'
|
||||
print('Done! Go Check!')
|
39
ElectronicStation/speechmodule.py
Normal file
39
ElectronicStation/speechmodule.py
Normal file
@@ -0,0 +1,39 @@
|
||||
def checkio(number):
|
||||
toStr = ""
|
||||
hasSpecials = False
|
||||
numbers = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
|
||||
deci = {1: "ten", 2: "twenty", 3: "thirty", 4: "forty", 5: "fifty", 6: "sixty", 7: "seventy", 8: "eighty",
|
||||
9: "ninety"}
|
||||
specials = {11: "eleven", 12: "twelve", 13: "thirteen", 14: "fourteen", 15: "fifteen", 16: "sixteen",
|
||||
17: "seventeen", 18: "eighteen", 19: "nineteen"}
|
||||
isHundred = number / 100
|
||||
isDeci = (number % 100) / 10
|
||||
isNum = ((number % 100) % 10)
|
||||
|
||||
if isHundred >= 1:
|
||||
toStr += numbers[isHundred] + " hundred"
|
||||
if isDeci == 1 and (isNum != 0):
|
||||
if toStr:
|
||||
toStr += " "
|
||||
toStr += specials[isDeci * 10 + isNum]
|
||||
hasSpecials = True
|
||||
elif isDeci > 1:
|
||||
if toStr:
|
||||
toStr += " "
|
||||
toStr += str(deci[int(isDeci)])
|
||||
if hasSpecials == False and isNum != 0:
|
||||
if toStr:
|
||||
toStr += " "
|
||||
toStr += numbers[isNum]
|
||||
return toStr
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
assert checkio(4) == 'four', "First"
|
||||
assert checkio(133) == 'one hundred thirty three', "Second"
|
||||
assert checkio(12) == 'twelve', "Third"
|
||||
assert checkio(101) == 'one hundred one', "Fifth"
|
||||
assert checkio(212) == 'two hundred twelve', "Sixth"
|
||||
assert checkio(40) == 'forty', "Seventh, forty - it is correct"
|
||||
|
||||
print('All ok')
|
Reference in New Issue
Block a user