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
from collections.abc import Mapping, MutableMapping | |
class Table(MutableMapping): | |
def __init__(self): | |
self.__table = [] # the internal table as a list of key-value pairs | |
def __len__(self): | |
return len(self.__table) | |
def __str__(self): |
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
import java.io.Reader; | |
import java.io.StringReader; | |
import java.io.IOException; | |
import static java.lang.Character.isDigit; | |
enum State { START, ZERO, DEC, OCT, X, HEX } | |
public class String2int { | |
public static int string2int(String digits) { | |
return (int)string2long(digits); |
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
#include <stdlib.h> | |
#include <stdio.h> | |
#include <ctype.h> | |
int e_atoi(char *str) { | |
enum { ST_START, ST_ZERO, ST_DEC, ST_OCT, ST_X, ST_HEX } state = ST_START; | |
int result = 0; | |
for (int c = *(str++); c != '\0'; c = *(str++)) { | |
switch (state) { |
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
import scala.collection.mutable | |
class HashTable[K, V](n: Int) extends mutable.AbstractMap[K, V] { | |
protected var table = mutable.ArraySeq.fill(n)(Nil:List[(K, V)]) | |
protected var count = 0 | |
def this() = this(10) | |
override def size: Int = count |
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
import java.util.*; | |
public class HashTable<K, V> extends AbstractMap<K, V> { | |
protected SimpleEntry<K, V>[] table_; | |
protected int count_ = 0; | |
private HashTable<K, V> self = this; | |
public HashTable(int n) { | |
table_ = (SimpleEntry<K, V>[])new SimpleEntry[n]; | |
} |
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
import scala.collection.mutable | |
class LinearSearchTable[K, V] extends mutable.AbstractMap[K, V] { | |
protected val table = new mutable.ArrayBuffer[(K,V)] | |
private def lin_search(key: K): Int = { | |
var (ix, result) = (0, -1) | |
while (ix < table.size && | |
{ if (key == table(ix)._1) { result = ix; false } else true }) | |
ix += 1 |
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
import java.util.ArrayList; | |
import java.util.Map; | |
import java.util.Set; | |
import java.util.Iterator; | |
import java.util.AbstractMap; | |
import java.util.AbstractSet; | |
public class LinearSearchTable<K, V> extends AbstractMap<K, V> { | |
class Entry extends SimpleEntry<K, V> { |
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
#include <stdlib.h> | |
#include <stdio.h> | |
int gcd(int m, int n) { | |
int r = m % n; | |
if (r == 0) { | |
return n; | |
} | |
else { | |
return gcd(n, r); |
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
ArrayList<Star> stars = new ArrayList<Star>(); | |
ArrayList<Crystal> snow = new ArrayList<Crystal>(); | |
void setup() { | |
size(800, 600); | |
colorMode(HSB, 360, 1.0, 1.0, 1.0); | |
for (int i = 0; i < 30; i++) { | |
stars.add(new Star(random(width), random(0.7 * height), 30)); | |
} |
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
;;;; | |
;;;; Sieve of Eratosthenes | |
;;;; | |
(require srfi/2) ; and-let* | |
(require srfi/4) ; homogenous numeric vector | |
(require srfi/42) ; list comprehension | |
;;;; | |
;;;; |
NewerOlder