I'VE GOT THE BYTE ON MY SIDE

57005 or alive

An elliptical pool

Jun 29, 2014 math Mathematica neat

@StevenStrogatz posed a fun question this evening:

People quickly realized the answer is “no,” but how to show it?

F# extension methods in Roslyn

Apr 30, 2014 C# F# Roslyn VB

If you scan the source code for the Roslyn project, the platform on which the next-gen C# and VB compilers are based, you might stumble across an interesting special behavior that was added in for the sole purpose of preserving backward-compatibility with F#.

From [roslyn]\Src\Compilers\CSharp\Source\Symbols\Metadata\PE\PEAssemblySymbol.cs (as of commit dc3171c8a878):

public override bool MightContainExtensionMethods
{
    get
    {
        if (!this.lazyContainsExtensionMethods.HasValue())
        {
            var moduleSymbol = this.PrimaryModule;
            var module = moduleSymbol.Module;
            // The F# compiler may not emit an assembly-level ExtensionAttribute, and previous versions of C# never checked for it.
            // In order to avoid a breaking change (while preserving the perceived performance benefits of not looking for extension
            // methods in assemblies that don't contain them), we'll also look for FSharpInterfaceDataVersionAttribute.
            var mightContainExtensionMethods = module.HasExtensionAttribute(this.assembly.Handle, ignoreCase: false) ||
                                               module.HasFSharpInterfaceDataVersionAttribute(this.assembly.Handle);

            this.lazyContainsExtensionMethods = mightContainExtensionMethods.ToThreeState();
        }

        return this.lazyContainsExtensionMethods.Value();
    }
}

The comment does a nice job of summing up the issue, but allow me to provide some additional context.

Project Euler visualizations - problem 144

Dec 10, 2013 math Mathematica neat Project Euler

Here’s another nifty Project Euler visualization, one I put together while solving problem 144 a while ago.

Project Euler visualizations - problem 431

Dec 9, 2013 math Mathematica neat Project Euler

I recently solved Project Euler problem 431, which (through a bizarre and unnecessarily confusing back-story) requires one to calculate the volume trapped above a cone, inside a cylinder.  The point of the cone is taken to be level with the top of the cylinder, but the cone angle and its horizontal offset compared to the cylinder are variable.

I solved this one with Mathematica, and along the way I cobbled together a little visualization that allows one to easily see the curve of intersection where the cone and the cylinder join together.  Why not take this opportunity to share the visualization via an embedded CDF?  I’ve been wanting to try this for a while.

Selecting a random element from a linked list - 3 approaches in F#

Nov 16, 2013 F#

You have a linked list (i.e. no random access) with an unknown number of elements and a standard random number generator. Write an algorithm that selects a random element from the list, going for best O(N) performance and memory usage.