• 1 Post
  • 124 Comments
Joined vor 1 Jahr
cake
Cake day: 1. September 2023

help-circle

  • C#

    using MathNet.Numerics.LinearAlgebra;
    public class Day02 : Solver
    {
      private ImmutableList<Vector<Double>> data;
    
      public void Presolve(string input)
      {
        data = input.Trim().Split("\n")
            .Select(
                line => Vector<Double>.Build.DenseOfEnumerable(line.Split(' ').Select(double.Parse))
            ).ToImmutableList();
      }
    
      private bool IsReportSafe(Vector<Double> report) {
        Vector<Double> delta = report.SubVector(1, report.Count - 1)
            .Subtract(report.SubVector(0, report.Count - 1));
        return (delta.ForAll(x => x > 0) || delta.ForAll(x => x < 0))
            && Vector<Double>.Abs(delta).Max() <= 3;
      }
    
      private bool IsDampenedReportSafe(Vector<Double> report) {
        for (Double i = 0; i < report.Count; ++i) {
          var dampened = Vector<Double>.Build.DenseOfEnumerable(
                report.EnumerateIndexed()
                    .Where(item => item.Item1 != i)
                    .Select(item => item.Item2));
          if (IsReportSafe(dampened)) return true;
        }
        return false;
      }
    
      public string SolveFirst() => data.Where(IsReportSafe).Count().ToString();
    
      public string SolveSecond() => data.Where(IsDampenedReportSafe).Count().ToString();
    }
    

  • C#

    public class Day01 : Solver
    {
      private ImmutableArray<int> left;
      private ImmutableArray<int> right;
    
      public void Presolve(string input)
      {
        var pairs = input.Trim().Split("\n").Select(line => Regex.Split(line, @"\s+"));
        left = pairs.Select(item => int.Parse(item[0])).ToImmutableArray();
        right = pairs.Select(item => int.Parse(item[1])).ToImmutableArray();
      }
    
      public string SolveFirst() => left.Sort().Zip(right.Sort()).Select((pair) => int.Abs(pair.First - pair.Second)).Sum().ToString();
    
      public string SolveSecond() => left.Select((number) => number * right.Where(v => v == number).Count()).Sum().ToString();
    }
    






  • First of all, you can totally do it! The field is massive, but also full of very bad programmers, and seeing how you were able to write a coherent text of three paragraphs, that already puts you ahead of the curve. Determination and perseverance is key.

    I would suggest to play to your strengths. Java is still Java. Most of the progress since the 1990s was in the libraries and tooling, which only recently have become passable. The language itself also evolved somewhat, but there’s nothing that you won’t pick up in a couple of days of working with it.

    Start with [1], work through all the boxes that are unfamiliar to you, practice a little on a pet project, or an open source project, and you’ll land a job in no time.

    [1] https://roadmap.sh/java


  • You likely have a mental model of Subversion, so what I would suggest is to try to forget as much of it as possible first, as Git is very different.

    Take a tutorial that is aimed at Git beginners, e.g. [1]. This will help you start building a new mental model as well as get first practical experience.

    After that, read the official docs starting wtih the object model[2]. The reason why many people struggle to get into git, especially after using other VCS, is that it was built from the ground up, without much regard of the established conventions and terminology. Linus Torvalds once mentioned that he used his experience designing file systems when developing git.

    So the object model of git is very simple, but also not intuitive. However, once you understand it, everything will start making sense, including the xkcd you’ve linked.

    [1] https://gitimmersion.com/ [2] https://git-scm.com/book/en/v2/Git-Internals-Git-Objects









  • I can’t imagine how normal people use any software at all. When something doesn’t work for me, often I can figure out what could’ve gone wrong. For instance, there might be bug in the JavaScript form handler, and I can just bypass it. Or an app doesn’t invalidate its cache properly, so I just need to flush it manually.