This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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))]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
: -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 ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Database.HDBC | |
import Database.HDBC.Sqlite3 | |
import Control.Exception | |
data Ctx = Ctx Connection | |
type DBResult = Either String () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket/base | |
;;; Solution to | |
;;; http://programmingpraxis.com/2014/04/15/assembler-part-1 | |
;;; | |
;;; [email protected] | |
(require racket/dict | |
racket/match | |
racket/sequence |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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)))) |