Skip to content

Instantly share code, notes, and snippets.

@sinclairtarget
sinclairtarget / bernoulli.c
Created August 17, 2018 20:22
Lovelace's Note G Program in C
#include <stdio.h>
/*
* Calculates what Ada Lovelace labeled "B7", which today we would call the 8th
* Bernoulli number.
*/
int main(int argc, char* argv[])
{
// ------------------------------------------------------------------------
// Data
@darrylsloan
darrylsloan / connect4.asm
Created July 6, 2017 14:16
Connect 4 (Z80 assembly language for the ZX Spectrum 48K)
; CONNECT 4 by Darryl Sloan, 3 July 2017
org 50000
last_k equ 23560
ld hl, udgs ; UDGs
ld (23675), hl ; set up UDG system variable
ld a, 2 ; upper screen
call 5633 ; open channel
@pathikrit
pathikrit / NorvigSpellChecker.scala
Last active May 1, 2023 17:41
Scala implementation of Peter Norvig's spellchecker (http://norvig.com/spell-correct.html)
class NorvigSpellChecker(corpus: String, alphabet: Seq[Char] = 'a' to 'z', level: Int = 2) {
val words = s"[${alphabet.head}-${alphabet.last}]+".r.findAllIn(corpus.toLowerCase).toSeq
val count = words.groupBy(_.toSeq).mapValues(_.size) withDefaultValue 0
def edit(n: Int)(word: Seq[Char]): Set[Seq[Char]] = n match {
case 0 => Set(word)
case 1 =>
val splits = word.indices map word.splitAt
val deletes = splits collect {case (a, b0 +: b1) => a ++ b1}
/**
* Created by Hugo Sereno Ferreira on 15/06/14.
*/
import org.scalajs.dom
import scala.collection._
import Page.renderer
sealed trait Opcode
object Mov extends Opcode { override def toString = "MOV" }
@hugoferreira
hugoferreira / CoreWar.scala
Last active November 13, 2020 20:16
Scala.js implementation of the MARS simulator (Core War)
/**
* Created by Hugo Sereno Ferreira on 15/06/14.
*/
import org.scalajs.dom
import scala.collection._
sealed trait Opcode
object Mov extends Opcode { override def toString = "MOV" }
object Add extends Opcode { override def toString = "ADD" }
@alxbok
alxbok / Parser.scala
Created September 4, 2011 11:35
JSON parsing
import scala.util.parsing.json.JSON
case class Widget(name: String, flavour: String)
case class Contract(vendor: String, colour: String, widgets: List[Widget])
object Parser {
def parseContract(json: String): Option[Contract] = {
for {
AsMap(contract) <- JSON.parseFull(json)