Skip to content

Instantly share code, notes, and snippets.

import std.algorithm;
import std.conv;
import std.stdio;
import std.array;
import std.range;
import std.format;
//Compile with ldc2 -O5 -release -disable-boundscheck MagicForest.d
struct forest_t{
@logicchains
logicchains / primesums.c
Created March 19, 2014 10:56
Prints the sum of primes less than or equal to input numbers.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define INITIAL_ARRAY_CAPACITY 100
int isPrime(int value){
int i;
if (value > 2 && value != 4){
for (i = 2; i < value/2; i++) {
/* After compiling it, eg. with "gcc -Wall -ansi DetermineMajorityValue.c -o DetermineMajorityValue -O3", run with:
* "DetermineMajorityValue someInputStringIWantToCheck", where that someInputString is the sequence S.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/*Defining an array in which the number of each symbol encountered is stored.
/* After compiling it, eg. with "gcc -Wall -ansi DetermineMajorityValue.c -o DetermineMajorityValue -O3", run with:
* "DetermineMajorityValue someInputStringIWantToCheck", where that someInputString is the sequence S.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/*Defining an array in which the number of each symbol encountered is stored.
@logicchains
logicchains / go++.go
Last active August 29, 2015 13:56
Simple generics implementation for Go. Run with "go++ -i=myFileName.go".
package main
import(
"io/ioutil"
"strings"
"fmt"
"flag"
"os/exec"
)
@logicchains
logicchains / D.d
Created February 16, 2014 10:53
TestDMemoryLayout
import std.stdio;
import std.datetime;
enum {
NUM_RECORDS = 50 * 1000 * 444
}
DMemoryTrade[NUM_RECORDS] trades = void;
#define _POSIX_C_SOURCE 200809L
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#define NUM_RECORDS (50 * 1000 * 1000)
struct CMemoryTrade {
package main
import (
"fmt"
"runtime"
"time"
)
const (
NUM_RECORDS = 50 * 1000 * 1000
@logicchains
logicchains / Scala implementation query
Created December 13, 2013 11:51
Scala implementation query
I'm running another benchmark next month, and as you contributed a Scala implementation to the previous two benchmarks I did, I wondered if you'd be interested in contributing one to this one? It's an OpenGL animation benchmark.
@logicchains
logicchains / Businesscard?
Created September 25, 2013 04:41
Rust implementation of C++ raytracer.
use std::num;use std::rand::Rng;struct Vec {x:f32,y:f32,z:f32}
impl Add<Vec, Vec> for Vec {fn add(&self, other: &Vec) -> Vec {Vec::new(self.x + other.x, self.y + other.y, self.z + other.z)}}
impl Mul<f32, Vec> for Vec {fn mul(&self, &scale: &f32) -> Vec {Vec::new(self.x * scale, self.y * scale, self.z * scale)}}
impl num::Zero for Vec {fn zero() -> Vec {Vec::new(0., 0., 0.)}fn is_zero(&self) -> bool {self.x == 0. && self.y == 0. && self.z == 0.}}
impl Vec {pub fn new(x: f32, y: f32, z: f32) -> Vec {Vec { x: x, y: y, z: z }}
pub fn dot(&self, other: &Vec) -> f32 {self.x * other.x + self.y * other.y + self.z * other.z}
pub fn cross(&self, other: &Vec) -> Vec {Vec::new(self.y * other.z - self.z * other.y,self.z * other.x - self.x * other.z,self.x * other.y - self.y * other.x)}
pub fn normalise(&self) -> Vec {*self * (1. / num::sqrt(self.dot(self)))}}
static G: &'static [i32] =&[0b0000000000000000000,0b0000000000000000000,0b0000000000000000000,0b1110000000000000100,0b1001010010011000100,0b1110010010100011111,0b11