Skip to content

Instantly share code, notes, and snippets.

View Denommus's full-sized avatar

Yuri Albuquerque Denommus

  • Brick Abode
  • Florianópolis, SC, Brazil
View GitHub Profile
import Control.Applicative
process :: [[[a]]] -> [[a]]
process [] = []
process [x] = x
process (x : xs) = (++) <$> x <*> process xs
main :: IO ()
main = putStrLn . show . process $ [[[3], [5]], [[1]]]
@Denommus
Denommus / ishappy.hs
Last active August 29, 2015 14:01
Check if a number is happy or not
digs :: Int -> [Int]
digs = map (read . return) . show
process :: Int -> Int
process = sum . map (^2) . digs
isHappy :: Int -> Bool
isHappy x = isHappyHelper x []
@Denommus
Denommus / problem_b.hs
Last active August 29, 2015 13:59
Solution for the second problem of the Google Code Jam 2014 Qualification Round
import System.Environment
import Control.Monad
import System.IO
calculateTime :: Double -> Double -> Double -> Double
calculateTime c f x = loop 2
where loop rate
| outright <= buying = outright
| otherwise = waiting + loop newRate
where waiting = c / rate
@Denommus
Denommus / problem_b.lisp
Created April 13, 2014 02:18
Problem B for qualification round of Google Code Jam 2014
#!/usr/bin/sbcl --script
(setf *read-default-float-format* 'double-float)
(defun calculate-time (c f x)
(labels ((calculate-time-helper (c f x n time-spent)
(let* ((time-with-current (/ x (+ (* n f) 2)))
(time-for-farm (/ c (+ (* n f) 2)))
(time-with-farm (+ time-for-farm
(/ x (+ (* (1+ n) f) 2)))))
@Denommus
Denommus / problem_a.lisp
Created April 13, 2014 02:18
Problem A for Qualification Round of Google Code Jam 2014
#!/usr/bin/sbcl --script
(load "~/quicklisp/setup.lisp")
(require 'cl-ppcre)
(defun read-rows (file)
(loop for i from 0 to 3
collect (mapcar #'parse-integer
(cl-ppcre:split " " (read-line file)))))
@Denommus
Denommus / problem_b.c
Last active August 29, 2015 13:59
Cookie problem from GSoC 2014 in C
#include <stdio.h>
double calculateTime(double c, double f, double x) {
double totalTime = 0;
int n = 0;
double timeWithCurrent, timeForFarm, timeWithFarm;
do {
timeWithCurrent = x/((f*n)+2);
timeForFarm = c/((f*n)+2);
timeWithFarm = timeForFarm+(x/(((1+n)*f)+2));
@Denommus
Denommus / aks.rs
Last active August 29, 2015 13:56
AKS test for primes
extern mod extra;
use extra::bigint::BigInt;
use extra::bigint::Plus;
use extra::bigint::Minus;
use extra::bigint::Zero;
use extra::bigint::ToBigInt;
fn coefficients(p: uint) -> ~[BigInt] {
if p==0 {
~[BigInt::new(Plus, ~[1])]
@Denommus
Denommus / palindrome.lisp
Last active January 3, 2016 22:49
Palindrome program in Common Lisp
(defun palindrome (str)
(loop
for i from 0
for a across str
for b across (reverse str)
always (char= a b)
until (> i (/ (length str) 2))))
@Denommus
Denommus / tree.rs
Last active January 3, 2016 04:49
Tree implementation in Rust, both with mutable and immutable append.
use std::vec::append_one;
#[deriving(Clone)]
struct Tree<T>(T, ~[Tree<T>]);
impl<T: ToStr> ToStr for Tree<T> {
fn to_str(&self) -> ~str {
let &Tree(ref data, ref children) = self;
data.to_str() + " -> " + children.to_str()
}
@Denommus
Denommus / factorial.lisp
Last active February 4, 2025 14:49
A simple tail-recursive factorial example
(defun factorial (number)
(labels ((factorial-helper (x accumulator)
(if (zerop x)
accumulator
(factorial-helper (- x 1) (* accumulator x)))))
(factorial-helper number 1)))