Skip to content

Instantly share code, notes, and snippets.

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
public static void PackRectanglesModify(List<PackedRectangle> rectangles)
{
rectangles.Sort
(
Comparing.CreateComparer<PackedRectangle, double>
(
rect => rect.Rectangle.Size.X * rect.Rectangle.Size.Y
)
);
rectangles.Reverse();
type IRectangle =
abstract member X : double with get, set
abstract member Y : double with get, set
abstract member Width : double
abstract member Height : double
abstract member Id : int
type internal Spot(x: double, y: double, width: double, height: double) =
member this.x = x
member this.y = y
static void Main(string[] args)
{
var rand = new Random();
int success = 0;
for (int i = 0; i < 100000; ++i)
{
var arr = Shuffle(new List<int> { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1 });
int sum = 0;
for (int j = 0; j < 3; ++j)
public static Vector4 HSVToRGB(float hue, float saturation, float value, float alpha)
{
Func<float, float> helper = (x) =>
{
float lowerBound = value * (1 - saturation);
float delta = value - lowerBound;
while (x < 0) x += 360;
x = x % 360;
return lowerBound + (float)((Math.Floor(x / 180) * value) + Math.Floor(((Math.Floor(x / 60) % 3) / 2)) * (x % 60) * (delta / 60F) * Math.Pow(-1, Math.Floor(x / 180)));
};
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <string.h>
#define DEBUG
#ifdef DEBUG
#define PRINT(...) printf(__VA_ARGS__);
@LukaHorvat
LukaHorvat / Visibility.hs
Created October 29, 2015 21:59
Visibility.hs
module Visibility where
import Data.List (sortBy, minimumBy)
import Data.Ord
import Data.Maybe (mapMaybe)
import Diagrams (Diagram, P2, (#), Located)
import qualified Diagrams as Diag
import Diagrams.Backend.Rasterific (Rasterific)
import qualified Diagrams.Backend.Rasterific as Rast
import Data.Colour (Colour)
data Node = Value Int | List [Node] | Sequence [Node]
steps :: Node -> [[Int]]
steps (Value x) = [[x]]
steps (List ns) = case substeps of
[] -> []
(x : xs) -> x ++ concat (zipWith prepend lastStates xs)
where substeps = map steps ns
lastStates = scanl1 (++) $ map last substeps
prepend pref ss = map (pref ++) ss
box :: Bool -> Angle Double -> Diagram SVG
box on angle = ((square (sqrt 2) `clipTo` rotate angle pattern) <> base) # lwO 1.5
where base = square (sqrt 2) # fc (if on then peachpuff else turquoise)
chromosome :: [Bool] -> Angle Double -> Diagram SVG
chromosome list angle = hcat $ map (pad 1.1 . (`box` angle)) list
first :: Diagram SVG
first = chromosome [True, False, True] (1/8 @@ turn)
||| padX 1.3 (chromosome [True, False] (1/8 @@ turn))