Skip to content

Instantly share code, notes, and snippets.

View bbarry's full-sized avatar

Bill Barry bbarry

  • Ren Inc
  • Pennsylvania
View GitHub Profile
@bbarry
bbarry / PrimeTests.cs
Created February 21, 2017 23:44
Miller–Rabin primality test in C# for 32 and 64 bit numbers; 32bit version is approximately 35 times faster than NaiveIsPrime on average; 64 bit ver is untested
public static class PrimeTests {
public static bool IsPrime(uint n) {
if (n < 2) return false;
if (n == 2 || n == 3 || n == 5 || n == 7) return true;
if (n % 2 == 0) return false;
var n1 = n - 1;
var r = 1;
var d = n1;

and the whole idea that the Misfit crew are actively destroying a culture to save a species... The People will lose their language in a few generations because English is in every way imaginable superior.

And then Julian is also about to jump them ahead a technology progression that took humans around 10-60,000 years:

  • The People don't have writing (8,000 BC).
  • They haven't invented a wheel (10,000 BC).
  • Vemik is apparently the inventor of the Bow (65,000 BC).
  • They barely have pottery (16,000 - 30,000 BC)
  • They appear to not have invented the Loom (36,000 BC)
  • They don't seem to know what charcoal is (100,000 - 790,000 BC)
using System;
using System.Collections.Generic;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
namespace ConsoleApp2 {
public class Benchmarking {
private static int[] gArray;
private static List<int> gList;
[Fact(Skip = "This test generator is capable of producing crashes that are not yet fixed; see, for example, Fuzz5815")]
public void Fuzz()
{
int dt = Math.Abs(new DateTime().Ticks.GetHashCode() % 10000000);
// generate a pattern-matching switch randomly from templates
string[] expressions = new[]
{
"M", // a method group
@bbarry
bbarry / _1_source.cs
Last active November 23, 2016 19:25
async inlined
using System;
using System.Threading.Tasks;
public class C {
static async Task A()
{
var a = 0;
await B();
Console.Write(a++);
await B();
@bbarry
bbarry / Program.cs
Last active September 11, 2016 18:48
testing program for verifying linear algorithm compared to quadratic algorithm for roslyn issue 13685: https://github.com/dotnet/roslyn/issues/13685
using System;
using System.Collections.Generic;
using System.Linq;
using Combinatorics.Collections;
namespace ConsoleApp1
{
public class Program
{
public static void Main(string[] args)
/// <summary>
/// A skip list is an ordered collection with O(log(n)) average case searching, inserting and removal. It also provides
/// O(n) enumeration and constant time access to the first element.
/// While the standard implementation is nondeterministic and based on overlapping forward linked lists, this
/// implementation is deterministic and uses double linked lists to provide constant time acess to the last element and
/// O(n) enumeration in reverse order as well as optimized insertion and removal for items in the last position.
/// </summary>
/// <typeparam name="T"></typeparam>
[PublicAPI]
[DebuggerDisplay("Count = {Count}, First = {SafeFirst}, Last = {SafeLast}")]
@bbarry
bbarry / ChangeMaker.cs
Created June 15, 2016 22:20
change making algorithm
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
namespace ConsoleApplication1
{
public class Program
@bbarry
bbarry / Knapsack.cs
Created June 14, 2016 14:50
various knapsack implementations
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
namespace ConsoleApplication1
{
public class Program
{