Skip to content

Instantly share code, notes, and snippets.

@moreirayokoyama
moreirayokoyama / PascalTriangleRecursive.scala
Created June 21, 2016 22:22
Pascal Triangle recursive
def PascalTriangleRecursive(row: Int, triangle: List[List[Int]], rows: Int): List[List[Int]] = {
val newRow =
if(row == 0)
List(1)
else {
val lastRow = 0 +: (triangle.last :+ 0)
for((i, j) <- lastRow.init zip lastRow.tail)
yield i + j
}
val newTriangle = triangle :+ newRow
@moreirayokoyama
moreirayokoyama / sum.c
Created March 11, 2014 12:22
The objective of the exercise was to accept two operands with any length (not restricted to any datatype size limitation) and perform a sum operation with both.
#include <stdio.h>
#include <stdlib.h>
int digit_to_int(char d)
{
char str[2];
str[0] = d;
str[1] = '\0';
return (int) strtol(str, NULL, 10);
}
@moreirayokoyama
moreirayokoyama / gist:2002607
Created March 8, 2012 18:42
Mod 10 (declarative fashion)
function mod10(numbers) {
var multipliers = [2, 1];
var multiplicands = numbers.reverse();
var products = mapProducts(multiplicands, multipliers);
var mod = products.map(
function (number) {
return number.toString().split('').map(
function (str) {
return parseInt(str);
}).sum();
string sep = "";
response.Write(sep + "Tipo Retorno");
sep = "\t";
response.Write(sep + "Marca");
sep = "\t";
response.Write(sep + "Unidade");
sep = "\t";
response.Write(sep + "Sala");
sep = "\t";