Skip to content

Instantly share code, notes, and snippets.

@wackywendell
wackywendell / euler70.rs
Created July 24, 2013 16:42
Code for finding the totient function of a number.
#[warn(non_camel_case_types)];
/*
Euler Challenge #70
Euler's Totient function, φ(n) [sometimes called the phi function], is used to determine the number of positive numbers less than or equal to n which are relatively prime to n. For example, as 1, 2, 4, 5, 7, and 8, are all less than nine and relatively prime to nine, φ(9)=6.
The number 1 is considered to be relatively prime to every positive number, so φ(1)=1.
Interestingly, φ(87109)=79180, and it can be seen that 87109 is a permutation of 79180.
@wackywendell
wackywendell / gist:10186578
Last active August 29, 2015 13:58
Sample IPython Notebook
{
"metadata": {
"name": "",
"signature": "sha256:7e2b0b3f559153fa30133c48b47ee3b799879a07364ebb6c8e27998d3344c6a0"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
@wackywendell
wackywendell / lifetime_fail.rs
Last active August 29, 2015 14:02
Fails to compile, with a complaint about "foo does not live long enough... reference must be valid for the static lifetime"
struct Foo {
n : int
}
struct Bar<'a> {
n : int,
other : Option<&'a mut Foo>
}
impl<'a> Bar<'a> {
@wackywendell
wackywendell / macro_test.rs
Last active August 29, 2015 14:03
Fails to compile with "rustc --opt-level 3 macro_test.rs" but compiles fine with just "rustc macro_test.rs"
#![feature(macro_rules)]
macro_rules! early_return(
($inp:expr, $($sp:ident),+) => (
match $inp {
$(
$sp(x) => { return x; }
)+
_ => {}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@wackywendell
wackywendell / counter.rs
Created August 18, 2014 17:57
A counter for Rust
/// A simple counter.
#[warn(non_camel_case_types)]
#[warn(unnecessary_qualification)]
#[warn(non_uppercase_statics)]
#[warn(missing_doc)]
extern crate collections;
use collections::TreeMap;
@wackywendell
wackywendell / ADMath Arrays
Last active August 29, 2015 14:08
admath and arrays
{
"metadata": {
"name": "",
"signature": "sha256:d6c1300ee2b30f10905ed4d219e15548afa126b2112d2ed0d6e8f4c157724905"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
@wackywendell
wackywendell / pmath
Last active January 24, 2023 08:00
Python math in the terminal
#!/usr/bin/python
"""
pmath [options] [statements...]
A simple script for performing math in the terminal, using Python functions and
syntax. I created this when I discovered how hard it was to get a cube root
using Bash or bc.
Note that 'from __future__ import division' is called, so '/' is float division,
and '//' is integer division.
<blank>
@wackywendell
wackywendell / PKGBUILD
Last active August 29, 2015 14:18
PKGBUILD for Reduce
#Maintainer: Wendell <wackywendell@gmail.com>
pkgname=reduce
pkgver=3.23.130521
pkgrel=1
pkgdesc="Reduce Software for Adding Hydrogens"
url="http://kinemage.biochem.duke.edu/software/reduce.php"
license=('unknown')
arch=('i686' 'x86_64')
depends=()
makedepends=('make')