mirror of
https://github.com/Xevion/exercism.git
synced 2025-12-06 15:15:01 -06:00
'init'
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -1,2 +1,5 @@
|
|||||||
*
|
*
|
||||||
!**/*.py
|
!**/**/
|
||||||
|
!**/**/*.py
|
||||||
|
*_test.py
|
||||||
|
**/**/__pycache
|
||||||
2
python/armstrong-numbers/armstrong_numbers.py
Normal file
2
python/armstrong-numbers/armstrong_numbers.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
def is_armstrong_number(number):
|
||||||
|
return sum([int(digit) ** len(str(number)) for digit in str(number)]) == number
|
||||||
4
python/hamming/hamming.py
Normal file
4
python/hamming/hamming.py
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
def distance(strand_a, strand_b):
|
||||||
|
if len(strand_a) != len(strand_b):
|
||||||
|
raise ValueError(f'strand_a (length {len(strand_a)}) has a different length from strand_b (length {len(strand_b)}), hamming distance cannot be computed.')
|
||||||
|
return len(strand_a) - len([char for index, char in enumerate(strand_a) if char == strand_b[index]])
|
||||||
2
python/hello-world/hello_world.py
Normal file
2
python/hello-world/hello_world.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
def hello():
|
||||||
|
return "Hello, World!"
|
||||||
10
python/high-scores/high_scores.py
Normal file
10
python/high-scores/high_scores.py
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
def latest(scores):
|
||||||
|
return scores[-1]
|
||||||
|
|
||||||
|
|
||||||
|
def personal_best(scores):
|
||||||
|
return max(scores)
|
||||||
|
|
||||||
|
|
||||||
|
def personal_top_three(scores):
|
||||||
|
return sorted(scores, reverse=True)[:3]
|
||||||
2
python/isogram/isogram.py
Normal file
2
python/isogram/isogram.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
def is_isogram(string):
|
||||||
|
return len(list(set(string))) == len(string)
|
||||||
2
python/leap/leap.py
Normal file
2
python/leap/leap.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
def leap_year(year):
|
||||||
|
return (year % 100 == 0 and year % 400 == 0) or (year % 100 != 0 and year % 4 == 0)
|
||||||
11
python/matrix/matrix.py
Normal file
11
python/matrix/matrix.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
class Matrix(object):
|
||||||
|
def __init__(self, matrix_string):
|
||||||
|
self.matrix_string = matrix_string
|
||||||
|
self.rows = [list(map(int, row.split(' '))) for row in self.matrix_string.split('\n')]
|
||||||
|
self.columns = [list(column) for column in zip(*(row for row in self.rows))]
|
||||||
|
|
||||||
|
def row(self, index):
|
||||||
|
return self.rows[index - 1]
|
||||||
|
|
||||||
|
def column(self, index):
|
||||||
|
return self.columns[index - 1]
|
||||||
6
python/pangram/pangram.py
Normal file
6
python/pangram/pangram.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import string
|
||||||
|
charset = string.ascii_lowercase
|
||||||
|
|
||||||
|
def is_pangram(sentence):
|
||||||
|
dictionary = {char : True if char in sentence.lower() else False for char in charset}
|
||||||
|
return all(dictionary.values())
|
||||||
19
python/protein-translation/protein_translation.py
Normal file
19
python/protein-translation/protein_translation.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
from itertools import takewhile
|
||||||
|
|
||||||
|
# Processing of data into a dictionary from a list taken from the site.
|
||||||
|
# I would have preferred being able to process the data from a module, or maybe a text file,
|
||||||
|
# but that's a whole lot of effort for something as simple as this.
|
||||||
|
data = [['AUG', 'Methionine'],
|
||||||
|
['UUU', 'UUC', 'Phenylalanine'],
|
||||||
|
['UUA', 'UUG', 'Leucine'],
|
||||||
|
['UCU', 'UCC', 'UCA', 'UCG', 'Serine'],
|
||||||
|
['UAU', 'UAC', 'Tyrosine'],
|
||||||
|
['UGU', 'UGC', 'Cysteine'],
|
||||||
|
['UGG', 'Tryptophan'],
|
||||||
|
['UAA', 'UAG', 'UGA', 'STOP']]
|
||||||
|
protein_definitions = {codon : definition for definition, codons in [(subarray[-1], subarray[:-1]) for subarray in data] for codon in codons }
|
||||||
|
|
||||||
|
def proteins(strand):
|
||||||
|
strand = [strand[index * 3:(index * 3)+3] for index, char in enumerate(strand[::3])]
|
||||||
|
strand = takewhile(lambda x : x != 'STOP', (protein_definitions[codon] for codon in strand))
|
||||||
|
return list(strand)
|
||||||
2
python/raindrops/raindrops.py
Normal file
2
python/raindrops/raindrops.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
def convert(n):
|
||||||
|
return ''.join(['Pling' if n % 3 == 0 else '', 'Plang' if n % 5 == 0 else '', 'Plong' if n % 7 == 0 else '']) or str(n)
|
||||||
2
python/reverse-string/reverse_string.py
Normal file
2
python/reverse-string/reverse_string.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
def reverse(text):
|
||||||
|
return text[::-1]
|
||||||
17
python/robot-name/robot_name.py
Normal file
17
python/robot-name/robot_name.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
from random import choices
|
||||||
|
from string import ascii_uppercase
|
||||||
|
from itertools import product
|
||||||
|
from random import shuffle
|
||||||
|
|
||||||
|
nums = (str(x).zfill(3) for x in range(1000))
|
||||||
|
front = (''.join(fr) for fr in product(ascii_uppercase, ascii_uppercase))
|
||||||
|
names = [l + n for l, n in product(front, nums)]
|
||||||
|
shuffle(names)
|
||||||
|
name_iter = iter(names)
|
||||||
|
|
||||||
|
class Robot(object):
|
||||||
|
def __init__(self):
|
||||||
|
self.reset()
|
||||||
|
|
||||||
|
def reset(self):
|
||||||
|
self.name = next(name_iter)
|
||||||
5
python/series/series.py
Normal file
5
python/series/series.py
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
from itertools import takewhile
|
||||||
|
def slices(series, length):
|
||||||
|
if length > len(series) or length <= 0:
|
||||||
|
raise ValueError('[length] parameter cannot be {}.'.format('longer than [series]' if length > len(series) else 'shorter than zero'))
|
||||||
|
return list(takewhile(lambda x : len(x) == length, (series[index:index+length] for index in range(len(series)))))
|
||||||
2
python/two-fer/two_fer.py
Normal file
2
python/two-fer/two_fer.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
def two_fer(name='you'):
|
||||||
|
return f'One for {name}, one for me.'
|
||||||
Reference in New Issue
Block a user