Instantly share code, notes, and snippets.

View VennDiagram.m
VennDiagram[n_, ineqs_: {}] := Module[{i, r = .6, R = 1, v, x, y, f},
v = Table[Circle[r {Cos[#], Sin[#]} &[2 Pi (i - 1)/n], R], {i, n}];
{
If[ineqs == {}, {},
f = And @@ (v /. Circle[{xx_, yy_}, rr_] :> (x - xx)^2 + (y - yy)^2 < rr^2)[[ineqs]];
RegionPlot[ImplicitRegion[f,
{x, y}], Axes -> False,
DisplayFunction -> Identity][[1]]
],
v
View 100weightchars.md

� � � � � � � � �

View four-coloring.m
map = Import["http://mathforum.org/wagon/fall97/images/5colormap.gif"];
matrix = MorphologicalComponents[map];
vars = Flatten[Map[{p[#], q[#]} &, Rest[Union[Flatten[matrix]]]]];
f[r_] := Map[If[Length[Union[#]] > 2, Sort[Select[#, Positive]], Nothing] &,
Partition[r, 4, 1]];
neighbours = Union[Flatten[Map[f, Join[matrix, Transpose[matrix]]], 1]];
View MyCos.java
/*
<dependencies>
<dependency>
<groupId>org.apfloat</groupId>
<artifactId>apfloat</artifactId>
<version>1.8.2</version>
</dependency>
</dependencies>
*/
import org.apfloat.*;
View cuda-cos-vs-fcos.cu
//On Ubuntu, you need to install CUDA and:
//sudo apt-get install libboost-dev
//On Windows, I don't know the way to build this code.
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cuda_runtime.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
View cuda-cos.cu
//On Ubuntu, you need to install CUDA and:
//sudo apt-get install libboost-dev
//On Windows, I don't know the way to build this code.
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cuda_runtime.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
View quad.cpp
//Pre build: sudo apt-get install libboost-dev
//To build: g++ quad.cpp -lquadmath
#include <cmath>
#include <ctime>
#include <quadmath.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
using namespace std;
namespace mp = boost::multiprecision;
View fcos.cpp
//On Ubuntu, you need:
//sudo apt-get install libboost-dev
#include <iostream>
#include <cmath>
#include <ctime>
#include <boost/multiprecision/cpp_bin_float.hpp>
using namespace std;
using namespace boost::multiprecision;
View tupper
960939379918958884971672962127852754715004339660129306651505519271702802395266424689642842174350718121267153782770623355993237280874144307891325963941337723487857735749823926629715517173716995165232890538221612403238855866184013235585136048828693337902491454229288667081096184496091705183454067827731551705405381627380967602565625016981482083418783163849115590225610003652351370343874461848378737238198224849863465033159410054974700593138339226497249461751545728366702369745461014655997933798537483143786841806593422227898388722980000748404719
View primefactorization.nb
factor[n_] := Reverse[Flatten[
Map[Table[#[[1]], {#[[2]]}] &, FactorInteger[n]]]]
On[Assert];
Assert[factor[24] == {3, 2, 2, 2}];
draw[origin_, frame_, delta_, {p_, rest___}, start_] := {
Circle[origin, frame],
With[{r = If[p == 1, 1, frame Sin[Pi/p]/(1 + Sin[Pi/p])]},
Table[