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
#| | |
| Celsius-Fahrenheit temperature table | |
| | |
| Taken from | |
| http://programmingpraxis.com/2012/09/07/the-first-two-programs/2/ | |
| | |
| Ported to current R7RS scheme by Christian Stigen Larsen | |
| Public Domain, 2012 | |
| | |
| Works in Mickey Scheme |
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
/* | |
* Simple program I wrote after reading Felix Von Leitner's notes | |
* on optimization at http://www.fefe.de/source-code-optimization.pdf | |
* | |
* In the 90s, it used to be faster to do (x<<8)+(x<<6) than x*320, | |
* but today with the Intel Core i7, it's actually faster to do | |
* x*320. | |
* | |
* And the compiler knows it! | |
* |
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
/* | |
* To compile objective-c on the command line: | |
* | |
* gcc -framework Foundation objc-gcc.m | |
* | |
* You may have to link with -lobjc or other libs, | |
* as required. | |
*/ | |
#import <Foundation/Foundation.h> |
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
/* | |
* A simple way to format numbers as human readable strings. | |
* E.g., 123456789 ==> 123 million | |
* | |
* Written by Christian Stigen Larsen | |
* http://csl.sublevel3.org | |
* | |
* Placed in the public domain by the author, 2012 | |
*/ |
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
""" | |
Implementation of memoization decorator in Python. | |
Written by Christian Stigen Larsen | |
http://csl.sublevel3.org | |
Put in the public domain by the author, 2012 | |
This is an example of how to use decorators to implement different kind of | |
behaviour in Python. |
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
/* | |
* Reverse string in "canonical" C++ | |
* | |
* Why did I make this a gist? Because I've seen so | |
* many cumbersome ways of doing this in C++, including | |
* using <algorithm> and std::reverse, using loops and | |
* so on. Yeah, those work too, and loops are fine for | |
* C, but in C++, you should simply just use the iterators | |
* and standard constructors that std::string gives you. | |
* |
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
/* | |
* Euler's totient function phi(n). | |
* http://en.wikipedia.org/wiki/Euler%27s_totient_function | |
* | |
* This is an *EXTREMELY* fast function and uses | |
* several tricks to recurse. | |
* | |
* It assumes you have a list of primes and a fast | |
* isprime() function. Typically, you use a bitset | |
* to implement the sieve of Eratosthenes and use |
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
/* | |
* The binary gcd algorithm using iteration. | |
* Should be fairly fast. | |
* | |
* Put in the public domain by the author: | |
* | |
* Christian Stigen Larsen | |
* http://csl.sublevel3.org | |
*/ | |
int binary_gcd(int u, int 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
#!/usr/bin/env python | |
"""Functions to convert IPv4 address to integer and vice-versa. | |
Written by Christian Stigen Larsen, http://csl.sublevel3.org | |
Placed in the public domain by the author, 2012-01-11 | |
Example usage: | |
$ ./ipv4 192.168.0.1 3232235521 | |
192.168.0.1 ==> 3232235521 |
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
/* | |
* A simple sieve of Eratosthenes using bitsets, written by Christian Stigen Larsen | |
* You are free to use this code for anything (i.e., public domain). | |
* | |
* This sieve allocates the bitset on the heap, so you can calculate a lot | |
* of prime numbers. | |
*/ | |
#ifndef INC_PRIMES_H | |
#define INC_PRIMES_H |