<PlatformTarget>AnyCPU</PlatformTarget>
<DocumentationFile>bin\$(Configuration)\$(AssemblyName).XML</DocumentationFile>
<Prefer32Bit>true</Prefer32Bit>
- <StartArguments>20</StartArguments>
+ <StartArguments>21</StartArguments>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<DocumentationFile>bin\$(Configuration)\$(AssemblyName).XML</DocumentationFile>
<Prefer32Bit>true</Prefer32Bit>
- <StartArguments>20</StartArguments>
+ <StartArguments>21</StartArguments>
</PropertyGroup>
<PropertyGroup>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
<Compile Include="Day18Part2.fs" />
<Compile Include="Day19.fs" />
<Compile Include="Day20.fs" />
+ <Compile Include="Day21.fs" />
<Compile Include="Program.fs" />
<None Include="App.config" />
<Content Include="Data\day01.input">
<Content Include="Data\day20.input">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
+ <None Include="Data\day21.input" />
<Content Include="packages.config" />
</ItemGroup>
<ItemGroup>
- <Reference Include="mscorlib" />
<Reference Include="FSharp.Core">
- <Name>FSharp.Core</Name>
- <AssemblyName>FSharp.Core.dll</AssemblyName>
- <HintPath>$(MSBuildProgramFiles32)\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\$(TargetFSharpCoreVersion)\FSharp.Core.dll</HintPath>
+ <HintPath>..\packages\FSharp.Core.4.2.3\lib\net45\FSharp.Core.dll</HintPath>
</Reference>
+ <Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
--- /dev/null
+module AdventOfCode2017.Day21
+
+open System
+
+type M = bool[,]
+
+let parseInput (lines : string[]) : (M * M) list =
+ let readMat (str : string) =
+ str.Split '/' |> Array.map (Array.ofSeq >> Array.map ((=) '#')) |> array2D
+
+ (*
+
+ let l = str.Length
+ let m = Array2D.zeroCreate l l : M
+ let rows = str.Split '/'
+ for i = 0 to l - 1 do
+ for j = 0 to l - 1 do
+ m.[i, j] <- rows.[i].[j] = '#'
+ m*)
+
+
+ lines
+ |> List.ofArray
+ |> List.map (
+ fun line ->
+ let matPair = line.Split ([| "=>" |], StringSplitOptions.RemoveEmptyEntries)
+ readMat matPair.[0], readMat matPair.[1]
+ )
+
+let fractalArt (patterns : (M * M) list) : int =
+ let turn (m : M) =
+ let l = Array2D.length1 m
+ let m' = Array2D.zeroCreate l l
+ if Array2D.length1 m = 2 then
+ m'.[0,0] <- m.[1,0]
+ m'.[0,1] <- m.[0,0]
+ m'.[1,1] <- m.[0,1]
+ m'.[1,0] <- m.[1,1]
+ else
+ m'.[0,0] <- m.[2,0]
+ m'.[0,1] <- m.[1,0]
+ m'.[0,2] <- m.[0,0]
+ m'.[1,2] <- m.[0,1]
+ m'.[2,2] <- m.[0,2]
+ m'.[2,1] <- m.[1,2]
+ m'.[2,0] <- m.[2,2]
+ m'.[1,0] <- m.[2,1]
+ m'
+
+ let flip (m : M) =
+ let l = Array2D.length1 m
+ let m' = Array2D.zeroCreate l l
+ if Array2D.length1 m = 2 then
+ m'.[0,0] <- m.[0,1]
+ m'.[0,1] <- m.[0,0]
+ m'.[1,1] <- m.[1,0]
+ m'.[1,0] <- m.[1,1]
+ else
+ m'.[0,0] <- m.[0,2]
+ m'.[1,0] <- m.[1,2]
+ m'.[2,0] <- m.[2,2]
+ m'.[0,2] <- m.[0,0]
+ m'.[1,2] <- m.[1,0]
+ m'.[2,2] <- m.[2,0]
+ m'
+
+ let variants (m : M) : M list =
+ let l = List.unfold (fun (i, m) -> if i < 4 then Some (m, (i + 1, turn m)) else None) (0, m)
+ if Array2D.length1 m > 2 then l @ (l |> List.map flip) else l
+
+ let next (m : M) : M =
+ let l = Array2D.length1 m
+ if l % 2 = 0 then
+ let l' = l + l / 2
+ else
+
+ let mutable n = 0
+ next (array2 [ [ false; true; false ]; [ false; false; true ]; [ true; true; true] ]) |> Array2D.iter (fun e -> if e then n <- n + 1)
+ n
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<packages>
+ <package id="FSharp.Core" version="4.2.3" targetFramework="net462" />
<package id="System.ValueTuple" version="4.4.0" targetFramework="net462" />
</packages>
\ No newline at end of file
--- /dev/null
+namespace AdventOfCode2017.Tests
+
+open System
+open Xunit
+open Xunit.Abstractions
+open Swensen.Unquote
+
+open AdventOfCode2017
+
+type ``Day21 tests`` (output : ITestOutputHelper) =
+
+ [<Fact>]
+ let ``(Part1) From web page`` () =
+ ()
+
+ [<Fact>]
+ let ``(Part2) From web page`` () =
+ ()
\ No newline at end of file
<Compile Include="Day18 tests.fs" />
<Compile Include="Day19 tests.fs" />
<Compile Include="Day20 tests.fs" />
+ <Compile Include="Day21 tests.fs" />
<Content Include="App.config" />
<Content Include="packages.config" />
</ItemGroup>