Has anyone here installed friendica? I tried to give it a go yesterday with the the docker image. The login page is showing up, but it is giving me HTTP 500 errors when I click sign up I also get no errors in any logs.
SteveDinn
The Porg?
A person's state becomes the name of the zone when they're in them.
In the current version of Home Assistant, if a person is in two overlapping zones, what happens? It's possible to be in that state today.
I suppose it doesn't really matter though. I've named all my home zones similarly: home1, home2, etc. It would be easy enough to check for a zone where the object_id starts with "home"
I...honestly thought I just did that. I want to have an irregularly-shaped zone. I don't see why they couldn't logically be grouped, you just aren't able to do it right now.
Anyway, thanks for reading what I typed.
I am pretty sure I'm not confused. I want to group zones together so they can be used in automation triggers and I can change the group's membership and not have to change every automation trigger. The group's state should indicate the number of person entities that were in any zone in the group.
I'm not talking about areas at all.
Just to be clear, I don't believe grouping zones is currently possible. It's just a want I have.
You don't get the choice to use more than one zone as your official "home" zone though, do you?
Like when you create a zone, it's a circle. It has a radius. I want a zone that is an arbitrary shape, so I compose it out of several smaller zones. I want to formally make it a single zone in Home Assistant by grouping them. Currently you can't add zones to groups or create a zone with type: group
or anything like that.
This is the way. Web client to MPV Shim for local playback.
C#
Part 2 was pretty much the same as Part 2 except we can't short-circuit when we find the first match. So, implement a cache of each sub-pattern and the number of ways to form it from the towels, and things get much faster.
using System.Collections.Immutable;
using System.Diagnostics;
using Common;
namespace Day19;
static class Program
{
static void Main()
{
var start = Stopwatch.GetTimestamp();
var sampleInput = ReceiveInput("sample.txt");
var programInput = ReceiveInput("input.txt");
Console.WriteLine($"Part 1 sample: {Part1(sampleInput)}");
Console.WriteLine($"Part 1 input: {Part1(programInput)}");
Console.WriteLine($"Part 2 sample: {Part2(sampleInput)}");
Console.WriteLine($"Part 2 input: {Part2(programInput)}");
Console.WriteLine($"That took about {Stopwatch.GetElapsedTime(start)}");
}
static object Part1(Input input)
{
return input.Patterns
.Select(p => AnyTowelMatches(p, input.Towels) ? 1 : 0)
.Sum();
}
static object Part2(Input input)
{
var matchCache = new Dictionary<string, long>();
return input.Patterns
.Select(p => CountTowelMatches(p, input.Towels, matchCache))
.Sum();
}
private static bool AnyTowelMatches(
string pattern,
ImmutableArray<string> towels)
{
return towels
.Where(t => t.Length <= pattern.Length)
.Select(t =>
!pattern.StartsWith(t) ? false :
(pattern.Length == t.Length) ? true :
AnyTowelMatches(pattern.Substring(t.Length), towels))
.Any(r => r);
}
private static long CountTowelMatches(
string pattern,
ImmutableArray<string> towels,
Dictionary<string, long> matchCache)
{
if (matchCache.TryGetValue(pattern, out var count)) return count;
count = towels
.Where(t => t.Length <= pattern.Length)
.Select(t =>
!pattern.StartsWith(t) ? 0 :
(pattern.Length == t.Length) ? 1 :
CountTowelMatches(pattern.Substring(t.Length), towels, matchCache))
.Sum();
matchCache[pattern] = count;
return count;
}
static Input ReceiveInput(string file)
{
using var reader = new StreamReader(file);
var towels = reader.ReadLine()!.SplitAndTrim(',').ToImmutableArray();
var patterns = new List<string>();
reader.ReadLine();
var line = reader.ReadLine();
while (line is not null)
{
patterns.Add(line);
line = reader.ReadLine();
}
return new Input()
{
Towels = towels,
Patterns = [..patterns],
};
}
public class Input
{
public required ImmutableArray<string> Towels { get; init; }
public required ImmutableArray<string> Patterns { get; init; }
}
}
C#
Part 1 was straight forward Dykstra with a cost of 1 for each move. Part 2 was a binary search from the number of corrupted bytes given to us for Part 1 (where we know a path can be found) to the total number of corrupted bytes.
using System.Collections.Immutable;
using System.Diagnostics;
using Common;
namespace Day18;
static class Program
{
static void Main()
{
var start = Stopwatch.GetTimestamp();
var sampleInput = ReceiveInput("sample.txt");
var sampleBounds = new Point(7,7);
var programInput = ReceiveInput("input.txt");
var programBounds = new Point(71, 71);
Console.WriteLine($"Part 1 sample: {Part1(sampleInput, 12, sampleBounds)}");
Console.WriteLine($"Part 1 input: {Part1(programInput, 1024, programBounds)}");
Console.WriteLine($"Part 2 sample: {Part2(sampleInput, 12, sampleBounds)}");
Console.WriteLine($"Part 2 input: {Part2(programInput, 1024, programBounds)}");
Console.WriteLine($"That took about {Stopwatch.GetElapsedTime(start)}");
}
static int Part1(ImmutableArray<Point> input, int num, Point bounds) => FindBestPath(
new Point(0, 0),
new Point(bounds.Row - 1, bounds.Col - 1),
input.Take(num).ToImmutableHashSet(),
bounds);
static object Part2(ImmutableArray<Point> input, int num, Point bounds)
{
var start = num;
var end = input.Length;
while (start != end)
{
var check = (start + end) / 2;
if (Part1(input, check, bounds) < 0) end = check;
else start = check + 1;
}
var lastPoint = input[start - 1];
return $"{lastPoint.Col},{lastPoint.Row}";
}
record struct State(Point Location, int Steps);
static int FindBestPath(Point start, Point end, ISet<Point> corruptedBytes, Point bounds)
{
var seenStates = new Dictionary<Point, int>();
var queue = new Queue<State>();
queue.Enqueue(new State(start, 0));
while (queue.TryDequeue(out var state))
{
if (state.Location == end) return state.Steps;
if (seenStates.TryGetValue(state.Location, out var bestSteps))
{
if (state.Steps >= bestSteps) continue;
}
seenStates[state.Location] = state.Steps;
queue.EnqueueRange(state.Location.GetCardinalMoves()
.Where(p => p.IsInBounds(bounds) && !corruptedBytes.Contains(p))
.Select(p => new State(p, state.Steps + 1)));
}
return -1;
}
static ImmutableArray<Point> ReceiveInput(string file) => File.ReadAllLines(file)
.Select(l => l.Split(','))
.Select(p => new Point(int.Parse(p[1]), int.Parse(p[0])))
.ToImmutableArray();
}
C#
This one is mostly thanks to reading @mykl@[email protected]'s code to understand WTF was going on for part 2, and then once I understood the basics, finally got to solving it myself. Instructions were read in as long
because I didn't want to deal with int
vs. long
all the time.
using System.Collections.Immutable;
using System.Diagnostics;
using Common;
namespace Day17;
static class Program
{
public record State(long A, long B, long C, int InstPtr, ImmutableList<long> Output);
static void Main()
{
var start = Stopwatch.GetTimestamp();
var (sampleReg, sampleInst) = ReceiveInput("sample.txt");
var (inputReg, inputInst) = ReceiveInput("input.txt");
Console.WriteLine($"Part 1 sample: {Part1(sampleReg, sampleInst)}");
Console.WriteLine($"Part 1 input: {Part1(inputReg, inputInst)}");
(sampleReg, sampleInst) = ReceiveInput("sample2.txt");
Console.WriteLine($"Part 2 sample: {Part2(sampleReg, sampleInst)}");
Console.WriteLine($"Part 2 input: {Part2(inputReg, inputInst)}");
Console.WriteLine($"That took about {Stopwatch.GetElapsedTime(start)}");
}
static object Part1(State state, ImmutableArray<long> instructions) =>
Execute(instructions, state).Output.StringifyAndJoin(",");
static object Part2(State state, ImmutableArray<long> instructions) =>
RecursiveSolve(instructions, state with { A = 0 }, []).First();
static IEnumerable<long> RecursiveSolve(ImmutableArray<long> instructions, State state, ImmutableList<long> soFar) =>
(soFar.Count == instructions.Length) ? [state.A] :
Enumerable.Range(0, 8)
.Select(a => state with { A = (state.A << 3) + a })
.Where(newState => newState.A != state.A)
.Select(newState => new { newState, Execute(instructions, newState).Output, })
.Where(states => states.Output.SequenceEqual(instructions.TakeLast(states.Output.Count)))
.SelectMany(states => RecursiveSolve(instructions, states.newState, states.Output));
static State Execute(ImmutableArray<long> instructions, State state)
{
while (state.InstPtr < instructions.Length)
{
var opcode = instructions[state.InstPtr];
var operand = instructions[state.InstPtr + 1];
state = Operations[opcode](state, operand);
}
return state;
}
static long ComboOperand(long operand, State state) => operand switch
{
>= 0 and <= 3 => operand,
4 => state.A,
5 => state.B,
6 => state.C,
_ => throw new Exception("Invalid operand."),
};
static long Adv(long op, State state) => state.A / (long)Math.Pow(2, ComboOperand(op, state));
static readonly Func<State, long, State>[] Operations =
[
(s, op) => s with { InstPtr = s.InstPtr + 2, A = Adv(op, s) },
(s, op) => s with { InstPtr = s.InstPtr + 2, B = s.B ^ op },
(s, op) => s with { InstPtr = s.InstPtr + 2, B = ComboOperand(op, s) % 8 },
(s, op) => s with { InstPtr = (s.A == 0) ? (s.InstPtr + 2) : (op <= int.MaxValue) ? (int)op : throw new ArithmeticException("Integer overflow!") },
(s, _) => s with { InstPtr = s.InstPtr + 2, B = s.B ^ s.C },
(s, op) => s with { InstPtr = s.InstPtr + 2, Output = s.Output.Add(ComboOperand(op, s) % 8) },
(s, op) => s with { InstPtr = s.InstPtr + 2, B = Adv(op, s) },
(s, op) => s with { InstPtr = s.InstPtr + 2, C = Adv(op, s) },
];
static (State, ImmutableArray<long> instructions) ReceiveInput(string file)
{
var input = File.ReadAllLines(file);
return
(
new State(
long.Parse(input[0].Substring("Register A: ".Length)),
long.Parse(input[1].Substring("Register B: ".Length)),
long.Parse(input[2].Substring("Register C: ".Length)),
0,
[]),
input[4].Substring("Program: ".Length)
.Split(",")
.Select(long.Parse)
.ToImmutableArray()
);
}
}
Create a docker container without explicitly naming it. Job done.