Skip to content

Instantly share code, notes, and snippets.

View silvericarus's full-sized avatar
💭
Remembering past moments

Alberto González Rosa silvericarus

💭
Remembering past moments
View GitHub Profile
@silvericarus
silvericarus / vote.java
Created May 21, 2018 10:08
Métodos upvote y downvote
public class Vote{
public void upvote(Comentario comentario,Button upButton){
if(upButton.isChecked){
upButton.unCheck();
comentario.setPuntuacion(comentario.getPuntuacion()-1);
}else{
comentario.setPuntuacion(comentario.getPuntuacion()+1);
}
}
@silvericarus
silvericarus / extraTextTranslate.php
Last active April 10, 2019 11:51
shutter version of MarkDown
<?php
function extraTextTranslate($text){
/************
* Negrita *
***********/
$text = str_replace('*','<b>',$text);
$lastPos = 0;
$positions = array();
while (($lastPos = strpos($text, '<b>', $lastPos))!== false) {
@silvericarus
silvericarus / zipper_merge.js
Last active April 23, 2019 19:34
JS function for merging two arrays into another array double the length with its elements being the originals entwined like a zipper.
function zipper_merge(array1, array2) {
if (array1.length != array2.length) {
return null;
}
var array3 = {};
var count = 0;
var pos = 0;
while(pos<array1.length*2){
array3[pos]=array1[count];
@silvericarus
silvericarus / ft_strbinarybase.c
Created June 21, 2022 22:53
C function that returns the binary result of each character in a string.
#include <stdio.h>
#include <unistd.h>
void print_char_bnry(unsigned char c)
{
int i;
char c_tmp;
i = 8;
while (--i >= 0)
@silvericarus
silvericarus / roman_to_int.c
Last active November 19, 2022 00:40
C function that takes a string with the valid roman numerals (IVXLCDM) and return the integer that those numerals represent
int romanToInt(char *s){
int i;
int num;
num = 0;
i = 0;
while(s[i] != '\0')
{
if(s[i] == 'I')
{
if(s[i + 1] == 'V')
@silvericarus
silvericarus / lst_middle_node.c
Created November 20, 2022 00:33
C function that counts the elements in a linked list and returns the middle element.
int ft_lstsize(struct ListNode *lst)
{
int index;
index = 0;
while (lst)
{
index++;
lst = lst->next;
}
@silvericarus
silvericarus / richest_customer_wealth.c
Created November 20, 2022 01:31
C function that takes a matrix of accounts, the number of accounts, and an array with the size of each account, and returns the wealth of the richest wealth included in the matrix.
int max_wealth(int** accounts, int accountsSize, int* accountsColSize){
int mainWealth;
int tmpW;
int i;
int j;
i = 0;
mainWealth = 0;
tmpW = 0;
while(i < accountsSize)
@silvericarus
silvericarus / steps_to_zero.c
Created December 1, 2022 23:48
C function that takes a number and calculates the number of steps needed to convert that number into 0.
//If the number is even, you divide it by 2, if it's odd, you subtract one from the number. That's the possible steps.
int numberOfSteps(int num){
static int steps = 0;
int tmp = 0;
int firstCall;
firstCall = 0;
if (num % 2 == 0 && num != 0)
{
if(steps == 0)
@silvericarus
silvericarus / first_single_char.c
Created December 4, 2022 23:45
C function that takes a string and returns the index of the first unrepeated character, if it doesn't find any unique character, it returns -1
int str_len(char *s)
{
int i;
i = 0;
while(s[i] != '\0')
i++;
return (i);
}
@silvericarus
silvericarus / two_sum.js
Last active September 9, 2023 17:46
Javascript function that given an array of numbers, find the first two ones that sum to the target, and returns the positions.
/**
* @param {number[]} nums
* @param {number} target
* @return {number[]}
*/
var twoSum = function(nums, target) {
const sum = [];
for (let i = 0; i < nums.length; i++) {
for (let j = i + 1; j < nums.length; j++) {
if (nums[i] + nums[j] === target) {