Skip to content

Instantly share code, notes, and snippets.

View jlcarrascof's full-sized avatar

Javier Jesus Martínez Fariñas jlcarrascof

View GitHub Profile
@jlcarrascof
jlcarrascof / challenge-day2.py
Last active February 10, 2024 14:03
Codigo Facilito Python Challenge - Day 2
# CodigoFacilito Challenge 2: Registro de usuarios
num_users = int(input('¿Cuántos nuevos usuarios se pretenden registrar? '))
# Itera sobre el número de usuarios a registrar
for i in range(0, num_users):
print("Registro del usuario:", i+1)
# Solicita y valida el nombre
while True:
@jlcarrascof
jlcarrascof / challenge-day1.py
Created February 6, 2024 06:15
Codigo Facilito Python Challenge - Day 1
# Request data from the user and store it in variables
first_name = input('Enter your First Name: ')
last_name = input('Enter your Last Name: ')
telephone = int(input('Enter your Telephone Number: '))
email = input('Enter your e-mail: ')
# Print the requested results.
print('Hola' + ' ' + first_name + ' ' + last_name + ', en breve recibirás un correo a ' + email + '.')
@jlcarrascof
jlcarrascof / word_ladder.rb
Created October 19, 2023 14:09
Given two words (beginWord and endWord), and a dictionary's word # list, find the length of shortest transformation sequence from # beginWord to endWord
# -*- coding: utf-8 -*-
#
# @lc app=leetcode id=127 lang=ruby
#
# [127] Word Ladder
#
# https://leetcode.com/problems/word-ladder/description/
#
# Given two words (beginWord and endWord), and a dictionary's word
# list, find the length of shortest transformation sequence from
@jlcarrascof
jlcarrascof / decorator_spec.rb
Created October 11, 2023 03:11
Requirement 2 - Decorator test
require_relative '../lib/models/decorator'
require_relative '../lib/models/persons'
describe 'Tests For Decorator class:' do
# we need to provide data for the parameters
person = Person.new('harry Potter', 20, parent_permission: true)
# created instance of decorator class
decorator = Decorator.new(person)
@jlcarrascof
jlcarrascof / capitalize_decorator_spec.rb
Last active October 11, 2023 03:11
Requirement 1 - Capitalize decorator test
require_relative '../lib/models/decorator'
require_relative '../lib/models/persons'
describe 'Tests For Decorator class:' do
# we need to provide data for the parameters
person = Person.new('harry Potter', 20, parent_permission: true)
# created instance of decorator class
decorator = Decorator.new(person)
@jlcarrascof
jlcarrascof / add_strings.rb
Created October 7, 2023 05:03
Add Strings
"""
Adds two strings representing non-negative integers.
Args:
num1: A string representing a non-negative integer.
num2: A string representing a non-negative integer.
Returns:
A string representing the sum of num1 and num2.
"""
@jlcarrascof
jlcarrascof / bit_counting.rb
Last active October 6, 2023 13:14
Bit Counting
# Write a function that takes an integer as input, and returns the number of bits that are equal to one in the binary representation of that number. You can guarantee that input is non-negative.
# Example: The binary representation of 1234 is 10011010010, so the function should return 5 in this case
def count_bits(n)
count = 0
while n > 0
count += n & 1
n >>= 1
end
@jlcarrascof
jlcarrascof / challenge.rb
Created September 29, 2023 21:26
Algo & DS - Binary Search Tree operations challenge
class Node
attr_reader :data
attr_accessor :left, :right
def initialize data
@data = data
end
end
def array_to_tree(array, index = 0)
# use your function from the previous challenge
@jlcarrascof
jlcarrascof / bubblesort.js
Created September 28, 2023 14:16
Bubble sort in Pair Programming
function bubbleSort(arr) {
const n = arr.length;
let swapped;
do {
swapped = false;
for (let i = 0; i < n - 1; i++) {
if (arr[i] > arr[i + 1]) {
// Swap the elements if they are in the correct order
const temp = arr[i];
@jlcarrascof
jlcarrascof / BinaryTree.js
Last active September 22, 2023 13:50
Binary Tree Challenge - 22-09-2023
function leftmostNodesSum(array) {
let sum = 0;
let index = 0;
while (index < array.length && array[index] !== 0) {
sum += array[index];
index = 2 * index + 1;
}
return sum;