Skip to content

Instantly share code, notes, and snippets.

"""
Island Count
Given a 2D array binaryMatrix of 0s and 1s, implement a function getNumberOfIslands that returns the number of islands of 1s in binaryMatrix.
An island is defined as a group of adjacent values that are all 1s. A cell in binaryMatrix is considered adjacent to another cell if they are next to each either on the same row or column. Note that two values of 1 are not part of the same island if they’re sharing only a mutual “corner” (i.e. they are diagonally neighbors).
Explain and code the most efficient solution possible and analyze its time and space complexities.
Example:
import datetime
from datetime import date
from datetime import timedelta
def IsDate(value):
return type(value) is date
class DateRange:
"""
Iterator over every date in a range [date_a, date_b). If a predicate is defined
@frarteaga
frarteaga / MergeSort.py
Created February 11, 2020 02:37
Merge sort algorithm.
# Despues de revisar https://binary-coffee.dev/post/conociendo-el-ordenamiento-por-mezcla-merge-sort
# me animé a implementarlo en Python.
def MergeTwoOrderedLists(A, B):
"""
Merge two ordered lists.
:param A: a ordered collection with heterogeneous
comparable items with items in collection B
:param B: a ordered collection with heterogeneous
# https://binary-coffee.dev/post/fechas-palindromos
from datetime import date
from datetime import timedelta
oneDay = timedelta(days=1)
def IsPalindromoDate(date):
strDate = str(date).replace('-', '')
return strDate == strDate[: : -1]
@frarteaga
frarteaga / InsertionSort.py
Last active February 5, 2020 16:17
Python implementation of Insertion Sort algorithm
# Despues de revisar https://binary-coffee.dev/post/insertion-sort
# me animé a implementarlo en Python.
def InsertionSort(A):
"""
Insertion sort algorithm.
:param A: some mutable ordered collection with heterogeneous
comparable items inside
:return: the same collection ordered by ascending
# Funcion que calcula factoriales, ejemplo:
# $ factorial 10 5
# 10: 3628800
# 5: 120
function factorial()
{
if test $# -eq "0"; then
# Si no hay paraametros en la linea de comandos
# leemos de la entrada estandar.
using System;
using System.Collections.Generic;
using System.Linq;
namespace Utils
{
public static class CollectionExtensions
{
/// <summary>
/// Mutate collection by removing every item that predicate(item) is true.
cents=$1
time=$((cents*72 - 4))
echo "Conectado por "$time" segundos"
# connecting using https://github.com/ateijelo/nauta-cli
python nauta.py up [your username] &
@frarteaga
frarteaga / csharptimer.cs
Last active October 24, 2018 17:15
simple chsarp timer
using System;
using Timer = System.Timers.Timer;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
var timer = new Timer { Interval = 2000 }; // every two seconds
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 12 columns, instead of 4. in line 1.
Timestamp,Nombre completo: / Full name:,País: / Country:,Institución: / Institution:,¿Cómo se inició en la Programación Competitiva? / How did you started in Competitive Programming?,¿Cuántas veces ha participado en el Campamento Caribeño? / How many times have you participated in the Caribbean Camp?,¿En qué otros eventos de este tipo ha participado? / In what other similar events have you participated?,¿Cuáles recursos en línea utiliza o recomienda para el entrenamiento? / What online resources do you use or recommend for training?,¿Por cuánto tiempo ha sido entrenador? / How long have you been a coach?,¿Qué lo motivó a trabajar como entrenador? / What motivated you to serve as a coach?,"En el entrenamiento del equipo, ¿cuáles considera son sus tareas más significativas? / In the team's training, what do you consider are your most significant tasks?",¿Algo más que desee agregar? / Anything else you want to add?
3/5/2017 16:57:00,Dovier Antonio Ripoll Méndez,Cuba,Universidad de las Ciencias Informáticas (UCI)