Skip to content

Instantly share code, notes, and snippets.

@fbwright
fbwright / easter.fs
Created February 21, 2015 18:29
/r/dailyprogrammer Challenge #202 - Easter Challenge
( easter.fs 2015-02-21T18.23 by fbwright )
( An implementation of the Butcher's algorithm )
: easter { year -- year month day }
year 19 mod { a } year 100 / { b } year 100 mod { c }
19 a * b + b 4 / - 15 + b b 8 + 25 / - 1 + 3 / - 30 mod { d }
32 b 4 mod 2 * + c 4 / 2 * + d - c 4 mod - 7 mod { e }
d e + 114 + d 11 * a + e 22 * + 451 / 7 * - { f }
f 31 mod 1+ ( day ) f 31 / ( month ) year ;
: test ( -- ) cr
2014 easter . . . cr ( Should be 2014 4 20 )
@fbwright
fbwright / ch202.fs
Last active August 29, 2015 14:15
/r/dailyprogrammer Challenge #202 - I AM BENDER. PLEASE INSERT GIRDER.
( ch202.fs 2015-02-22T19.49 by fbwright )
1024 CONSTANT buffer-size
CREATE buffer-in buffer-size CHARS ALLOT
CREATE index-in 1 CELLS ALLOT
CREATE buffer-out buffer-size 8 / CHARS ALLOT
CREATE index-out 1 CELLS ALLOT
( Iterates over buffer-in: every 8 cells it pushes a char to )
( buffer-out and increases index-out by 1 )
: parse-buffer ( -- ) 0 index-out ! 0 index-in @ 0 u+do
7 i 8 mod - buffer-in i + c@ case
@fbwright
fbwright / bankBannersReverse.py
Last active August 29, 2015 14:14
/r/dailyprogrammer Challenge #199 - Bank Number Banners
font = [111, 9, 94, 91, 57, 115, 119, 73, 127, 123]
def bannerToNumber(banner):
number = ""
for i in range(9):
start, end = i*3, (i+1)*3
digit = banner[0][start:end].strip() + \
banner[1][start:end] + \
banner[2][start:end]
#value = sum(list(map(lambda i, n: 2**i if n != ' ' else 0, range(7), reversed(digit))))
@fbwright
fbwright / isbn.nim
Last active August 29, 2015 14:13
ISBN Validator
## [2015-01-12] Challenge #197 [Easy] ISBN Validator
## 2015-01-21 15:08 - by Frankie Brogan
import strutils, parseopt2, version, strfmt, math, unittest
type
TISBNKind* = enum
ISBN10, ISBN13
TISBN* = object
case kind*: TISBNKind
of ISBN10: isbn_10*: array[0..9, int]
of ISBN13: isbn_13*: array[0..12, int]