Skip to content

Instantly share code, notes, and snippets.

View mllopart's full-sized avatar

Marc Llopart mllopart

View GitHub Profile
@mllopart
mllopart / TowerHanoi.lisp
Last active April 4, 2017 14:22
Tower of Hanoi problem in LISP
(defun Hanoi (n origin destination auxiliar)
(if (= n 1) (moure 1 origin destination)
(progn (Hanoi (- n 1) origin auxiliar destination)
(moure n origin destination)
(Hanoi (- n 1) auxiliar destination origin))))
(defun moure (k origin destination)
(print (list 'move 'disk k
'from 'column origin
'to 'column destination)))
@mllopart
mllopart / discover_kill_sessions.sql
Last active May 23, 2017 16:09
Oracle - Query to detect active sessions, in order to kill them :)
/*Query to detect active sessions, in order to kill them in Oracle */
SELECT s.inst_id,
s.sid,
s.serial#,
p.spid,
s.username,
s.osuser,
s.machine,
s.program,
'ALTER SYSTEM KILL SESSION '''||s.sid||','||s.serial#||''' IMMEDIATE;' as cmd
@mllopart
mllopart / randomArray.js
Created June 13, 2017 18:36
Random numbers in an array
/*Function to return an array containing *length* random numbers
and having the range from 0 to *max* */
function randomArray(length, max) {
return Array.apply(null, Array(length)).map(function() {
return Math.round(Math.random() * max);
});
}
/* function than shuffle an array */
function shuffle(array) {
@mllopart
mllopart / sum_integers_from_coma_string.php
Last active June 14, 2017 16:37
From the variable input sum the integer values of it
<?php
$input = "1,2,3,4,5,6,7";
$sum = 0;
print($input);
$input_arr = explode(",", $input);
foreach($input_arr as &$inp)
{
@mllopart
mllopart / Dragonball.php
Created June 14, 2017 17:04
Example of an easy class in PHP
<?php
class Dragonball {
public $ballCount = 0;
public function iFoundaBall() {
if ($this->ballCount < 7) {
$this->ballCount++;
} else {
echo("You can ask your wish!");
$this->ballCount = 0;
@mllopart
mllopart / groupByOwners.php
Created June 14, 2017 20:16
Implement a groupByOwners function that: Accepts an associative array containing the file owner name for each file name. Returns an associative array containing an array of file names for each owner name, in any order. For example, for associative array ["Input.txt" => "Randy", "Code.py" => "Stan", "Output.txt" => "Randy"] the groupByOwners func…
<?php
class FileOwners
{
public static function groupByOwners($files)
{
$file_return = [];
$files_copy = $files;
print_r($files);
@mllopart
mllopart / diagonal_difference.py
Created June 16, 2017 14:29
Diagonal Difference - Hackerrank test
#!/bin/python3
#Given a square matrix of size NxN , calculate the absolute difference between the sums of its diagonals.
import sys
n = int(input().strip())
a = []
for a_i in range(n):
@mllopart
mllopart / plus_minus.py
Created June 16, 2017 15:46
Plus Minus Hackerrank
#!/bin/python3
'''
Given an array of integers, calculate which fraction of its elements are positive,
which fraction of its elements are negative, and which fraction of its elements are zeroes,
respectively. Print the decimal value of each fraction on a new line.
'''
import sys
@mllopart
mllopart / staircase.py
Created June 16, 2017 16:10
Staircase Hackerrank test
#!/bin/python3
'''
Consider a staircase of size n=4:
#
##
###
####
Observe that its base and height are both equal to , and the image
@mllopart
mllopart / mini_max_sum.py
Created June 16, 2017 16:43
Mini-Max Sum Hackerrank
#!/bin/python3
'''
Given five positive integers, find the minimum and maximum values
that can be calculated by summing exactly four of the five integers.
Then print the respective minimum and maximum values as a single line
of two space-separated long integers.
'''
import sys