Skip to content

Instantly share code, notes, and snippets.

@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]
@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 / 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 / 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 / frogue.fs
Last active August 29, 2015 14:15
frogue.fs
( frogue.fs 2015-02-23T09.05 by fbwright )
( A [simple] roguelike in gforth; move the @, collide with # )
( And [comments excluded] fits into a block [1000/1024 B] )
variable &i 64 constant W 16 constant H create _M W H * chars
allot 6 constant MS 32 constant MM create _O MS MM * chars allot
: U 0 -1 ; : D 0 1 ; : R 1 0 ; : L -1 0 ; : # W * + _M + ; : &
MS * _O + ; : b? H 1- mod 0= swap W 1- mod 0= or ; : p? c@ '# <>
; : #d 2dup at-xy # c@ emit ; : #n 2dup # -rot b? if '# else bl
then swap c! ; : &xy@ & 1+ dup c@ swap 1+ c@ ; : &xy! & 1+ rot
over c! 1+ c! ; : &d dup &xy@ at-xy & c@ emit ; : &n &i @ & swap
@fbwright
fbwright / novel_zip.py
Created March 28, 2015 17:43
Novel compressor
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function, division
import sys, time
if sys.version_info.major < 3:
input = raw_input
def compress(data):
freq = {}
for line in data.splitlines():
@fbwright
fbwright / brainfuck.py
Created March 28, 2015 22:36
Some of my golfed code
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#Finally finished! 2014-07-26T16:25, 768 bytes - with interactive prompt
# and reading from file
#TODO: exception-checking, maybe continuation
#Brainfuck in python
#Brainfuck instructions:
# > increment the data pointer (to point to the next cell to the right).
# < decrement the data pointer (to point to the next cell to the left).
# + increment (increase by one) the byte at the data pointer.
@fbwright
fbwright / manga.py
Created May 21, 2015 18:06
Manga downloader
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#by fbWright
from __future__ import print_function, division
import sys, bs4, requests, os, os.path, json
from urllib.parse import urlparse, urljoin
from unidecode import unidecode
if sys.version_info.major < 3:
input = raw_input
@fbwright
fbwright / sasm.py
Created May 30, 2015 14:48
Simple assembler for a simple VM
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function, division
import sys
from time import sleep
if sys.version_info.major < 3:
input = raw_input
#THIS! IS! A! FUCKING! MESS!
@fbwright
fbwright / vm_gen.py
Created May 30, 2015 15:21
VM generator
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function, division
from contextlib import contextmanager
import sys
if sys.version_info.major < 3:
input = raw_input
class CodeGenerator(object):
def __init__(self, tab=" "):