Skip to content

Instantly share code, notes, and snippets.

View adolfopa's full-sized avatar

Adolfo Pérez Álvarez adolfopa

  • Liferay Inc.
  • Madrid
View GitHub Profile
#lang racket
(define (part-1)
(with-input-from-file "input"
(thunk
(define input
(for/list ([ln (in-lines)])
(string->number ln)))
(for/fold ([n 0] [p (first input)])
([x (in-list (rest input))])
@adolfopa
adolfopa / hof.f
Created February 10, 2017 23:36
Implementation of some higher order functions in Forth
: -range ( a-addr1 u -- a-addr2 a-addr1 )
cells over + ;
: range ( a-addr1 u -- a-addr1 a-addr2)
-range swap ;
: map! ( xt a-addr u -- )
range ?do i @ over execute i ! cell +loop ;
: foldl ( xt w1 a-addr u2 -- w2 )
module Main where
import Database.HDBC
import Database.HDBC.Sqlite3
import Control.Exception
data Ctx = Ctx Connection
type DBResult = Either String ()
-- CIS 194: Homework 3 (http://www.cis.upenn.edu/~cis194/hw/03-ADTs.pdf)
module HW03 where
data Expression =
Var String
| Val Int
| Op Expression Bop Expression
deriving (Show, Eq)
-- CIS 194: Homework 2 (http://www.cis.upenn.edu/~cis194/hw/02-lists.pdf)
{-# OPTIONS_GHC -Wall #-}
module HW02 where
-- Supporting code
data Peg = Red | Green | Blue | Yellow | Orange | Purple
deriving (Show, Eq, Ord)
@adolfopa
adolfopa / CIS 194 HW1 (Haskell)
Last active August 29, 2015 14:18
Solution to CIS 194 intro to functional programming (HW1)
-- CIS 194: Homework 1 (http://www.cis.upenn.edu/~cis194/hw/01-intro.pdf)
-- Exercise 1
lastDigit :: Integer -> Integer
lastDigit n = n `mod` 10
dropLastDigit :: Integer -> Integer
dropLastDigit n = n `div` 10
#lang racket/base
;;; Solution to
;;; http://programmingpraxis.com/2014/04/15/assembler-part-1
;;;
;;; adolfo.pa@gmail.com
(require racket/dict
racket/match
racket/sequence
/*
* C solution to http://programmingpraxis.com/2011/08/16/insert-into-a-cyclic-sorted-list/
*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
struct node {
int value;
@adolfopa
adolfopa / word-breaks.rkt
Created August 12, 2011 14:31
Racket and Python solutions to Programming Praxis exercise "Word breaks" August 12, 2011
#lang racket
(require rackunit)
(define dictionary
(set "a" "brown" "apple" "pie"))
(define (in-prefixes str)
(define (pos->element i)
(values (substring str 0 (+ 1 i)) (substring str (+ 1 i))))