Skip to content

Instantly share code, notes, and snippets.

View GuillermoPena's full-sized avatar

Guillermo Peña GuillermoPena

  • Green Box Software
  • Madrid, Spain
View GitHub Profile
@GuillermoPena
GuillermoPena / checkio.2.02.ghostAge.py
Created June 6, 2014 10:50
CheckIO - O'Reilly Challenge 2 : Ghost Age
# CheckIO - O'Reilly Challenge 2 : Ghost Age
# http://checkio.org
# Nicola takes a moment to study the ghosts.
# He is trying to think up a new method to determine just how old these ghosts are.
# He knows that their age is somehow related to their opacity.
# To measure their opacity Nikola uses a scale of 10000 units to 0 units,
# where 10000 is a completely opaque newborn ghost (0 years old) and 0 is completely transparent.
# After some experimenting, Nikola thinks he has discovered the law of ghostly opacity.
# On every birthday, a ghost's opacity is reduced by a number of units
@GuillermoPena
GuillermoPena / checkio.3.04.findSequence.py
Created June 5, 2014 18:55
CheckIO - Electronic Station Challenge 4 : Find Sequence
# CheckIO - Electronic Station Challenge 4 : Find Sequence
# http://checkio.org
# You are given a matrix of NxN (4≤N≤10).
# You should check if there is a sequence of 4 or more matching digits.
# The sequence may be positioned horizontally, vertically or diagonally (NW-SE or NE-SW diagonals).
# Input: A list of lists. Each list contains integers.
# Output: A boolean. Whether or not a sequence exists.
# Precondition: 0≤N≤10 ∀ x ∈ matrix : 0 < x < 10
@GuillermoPena
GuillermoPena / checkio.3.03.hammingDistance.py
Created June 5, 2014 15:38
CheckIO - Electronic Station Challenge 3 : Hamming Distance
# CheckIO - Electronic Station Challenge 3 : Hamming Distance
# http://checkio.org
# The Hamming distance between two binary integers is the number of bit positions that differs
# For example:
#
# 117 = 0 1 1 1 0 1 0 1
# 17 = 0 0 0 1 0 0 0 1
# H = 0+1+1+0+0+1+0+0 = 3
@GuillermoPena
GuillermoPena / checkio.3.02.restrictedSum.py
Created June 5, 2014 15:13
CheckIO - Electronic Station Challenge 2 : Restricted sum
# CheckIO - Electronic Station Challenge 2 : Brackets
# http://checkio.org
# Our new calculator is censored and as such it does not accept certain words.
# You should try to trick by writing a program to calculate the sum of numbers.
# Given a list of numbers, you should find the sum of these numbers.
# Your solution should not contain any of the banned words, even as a part of another word.
# The list of banned words are as follows:
# sum
# import
@GuillermoPena
GuillermoPena / checkio.3.01.brackets.py
Created June 5, 2014 14:34
CheckIO - Electronic Station Challenge 1 : Brackets
# CheckIO - Electronic Station Challenge 1 : Brackets
# http://checkio.org
# You are given an expression with numbers, brackets and operators.
# For this task only the brackets matter. Brackets come in three flavors: "{}" "()" or "[]".
# Brackets are used to determine scope or to restrict some expression.
# If a bracket is open, then it must be closed with a closing bracket of the same type.
# The scope of a bracket must not intersected by another bracket.
# For this task, you should to make a decision to correct an expression or not based on the brackets.
# Do not worry about operators and operands.
@GuillermoPena
GuillermoPena / checkio.2.01.stripedWords.py
Created June 5, 2014 10:32
CheckIO - O'Reilly Challenge 1 : Striped Words
# CheckIO - O'Reilly Challenge 1 : Striped Words
# http://checkio.org
# You are given a block of text with different words.
# These words are separated by white-spaces and punctuation marks.
# Numbers are not considered words in this mission (a mix of letters and digits is not a word either).
# You should count the number of words (striped words) where the vowels with consonants are alternating, that is;
# words that you count cannot have two consecutive vowels or consonants.
# The words consisting of a single letter are not striped -- do not count those.
# Input: A text as a string (unicode)
@GuillermoPena
GuillermoPena / checkio.1.11.openLabyrinth.py
Created June 2, 2014 12:39
CheckIO - Home Challenge 11 : Open Labyrinth
# CheckIO - Home Challenge 11 : Open Labyrinth
# http://checkio.org
# The labyrinth has no walls, but pits surround the path on each side.
# If a players falls into a pit, they lose.
# The labyrinth is presented as a matrix (a list of lists): 1 is a pit and 0 is part of the path.
# The labyrinth's size is 12 x 12 and the outer cells are also pits.
# Players start at cell (1,1). The exit is at cell (10,10).
# You need to find a route through the labyrinth.
# Input: A labyrinth map as a list of lists with 1 and 0.
@GuillermoPena
GuillermoPena / checkio.1.10b.goldenPyramid.py
Created June 1, 2014 19:42
CheckIO - Home Challenge 10 : Golden Pyramid (algorithm B)
# CheckIO - Home Challenge 10 : Golden Pyramid (algorithm B)
# http://checkio.org
# Consider a tuple of tuples in which the first tuple has one integer
# and each consecutive tuple has one more integer then the last.
# Such a tuple of tuples would look like a triangle.
# You should write a program that will help Stephan find the highest possible sum
# on the most profitable route down the pyramid.
# All routes down the pyramid involve stepping down and to the left or down and to the right.
# Input: A pyramid as a tuple of tuples. Each tuple contains integers.
@GuillermoPena
GuillermoPena / checkio.1.10a.goldenPyramid.py
Last active August 29, 2015 14:01
CheckIO - Home Challenge 10 : Golden Pyramid (algorithm A)
# CheckIO - Home Challenge 10 : Golden Pyramid (algorithm A)
# http://checkio.org
# Consider a tuple of tuples in which the first tuple has one integer
# and each consecutive tuple has one more integer then the last.
# Such a tuple of tuples would look like a triangle.
# You should write a program that will help Stephan find the highest possible sum
# on the most profitable route down the pyramid.
# All routes down the pyramid involve stepping down and to the left or down and to the right.
# Input: A pyramid as a tuple of tuples. Each tuple contains integers.
@GuillermoPena
GuillermoPena / checkio.1.09.MinAndMax.py
Created May 28, 2014 17:39
CheckIO - Home Challenge 9 : Min and Max
# CheckIO - Home Challenge 9 : Min and Max
# http://checkio.org
# In this mission you should write you own py3 realisation of the built-in functions min and max.
# Some builtin functions are closed here: import, eval, exec, globals.
# Don't forget you should realize two functions in your code.
# max(iterable, *[, key]) or min(iterable, *[, key])
# max(arg1, arg2, *args[, key]) or min(arg1, arg2, *args[, key])
# Return the largest (smallest) item in an iterable or the largest(smallest) of two or more arguments.
# If one positional argument is provided, it should be an iterable.