markh's recent activity

  1. Comment on Apple / iOS rant in ~tech

    markh
    Link
    Well, I'll give a counterpoint here: accessibility features are so much better on iPhone/Apple devices that Android, Windows, and Linux shouldn't even be considered. These complaints also seem...

    Well, I'll give a counterpoint here: accessibility features are so much better on iPhone/Apple devices that Android, Windows, and Linux shouldn't even be considered.

    These complaints also seem very specific to you. I've had an iPhone for a decade now and I've never had a problem. It just works, and I love it for that exact reason.

    9 votes
  2. Comment on Day 6: Custom Customs in ~comp

    markh
    Link
    Elixir! Took me a while to realize what part two was asking for. Parts One and Two defmodule Day6 do def one do File.read!("inputs/six.txt") |> String.split("\n\n") |> Enum.map(&String.replace(&1,...

    Elixir! Took me a while to realize what part two was asking for.

    Parts One and Two
    defmodule Day6 do
      def one do
        File.read!("inputs/six.txt")
        |> String.split("\n\n")
        |> Enum.map(&String.replace(&1, "\n", "", global: true))
        |> Enum.map(&String.split(&1, "", trim: true))
        |> Enum.map(&MapSet.new(&1))
        |> Enum.map(&MapSet.size(&1))
        |> Enum.reduce(&(&1 + &2))
      end
    
      def two do
        File.read!("inputs/six.txt")
        |> String.split("\n\n")
        |> Enum.map(&String.split(&1, "\n", trim: true))
        |> Enum.map(&parse/1)
        |> Enum.map(&MapSet.size/1)
        |> Enum.reduce(&(&1 + &2))
      end
    
      def parse(input) do
        input
        |> Enum.map(&String.graphemes(&1))
        |> Enum.map(&MapSet.new(&1))
        |> Enum.reduce(&MapSet.intersection/2)
      end
    end
    
    4 votes
  3. Comment on Day 5: Binary Boarding in ~comp

    markh
    Link
    Day 5! This one was fun, although I had to figure out how to slide an array in Elixir. Elixir defmodule Day5 do def one do File.read!("inputs/five.txt") |> String.split("\n") |> Enum.map(&parse/1)...

    Day 5! This one was fun, although I had to figure out how to slide an array in Elixir.

    Elixir
        defmodule Day5 do
          def one do
            File.read!("inputs/five.txt")
            |> String.split("\n")
            |> Enum.map(&parse/1)
            |> Enum.max()
          end
    
          def parse(input) do
            [[r, s]] = Regex.scan(~r/([F|B]{7})([R|L]{3})/, input, capture: :all_but_first)
    
            row = r
            |> String.replace("F", "0")
            |> String.replace("B", "1")
            |> String.to_integer(2)
    
            seat = s
            |> String.replace("L", "0")
            |> String.replace("R", "1")
            |> String.to_integer(2)
    
            row * 8 + seat
          end
    
          def two do
            [[x, _]] = File.read!("inputs/five.txt")
            |> String.split("\n")
            |> Enum.map(&parse/1)
            |> Enum.sort()
            |> Enum.chunk_every(2, 1, :discard)
            |> Enum.filter(fn [x, y] -> y - x == 2 end)
    
            x + 1
          end
        end
    
    4 votes
  4. Comment on Day 4: Passport Processing in ~comp

    markh
    Link
    Elixir, Day 4 Parts 1 and 2 defmodule Day4 do def one do File.read!("inputs/four.txt") |> String.split("\n\n") |> Enum.map(&parse/1) |> Enum.count(&valid_keys?/1) end def two do...

    Elixir, Day 4

    Parts 1 and 2
    defmodule Day4 do
      def one do
        File.read!("inputs/four.txt")
        |> String.split("\n\n")
        |> Enum.map(&parse/1)
        |> Enum.count(&valid_keys?/1)
      end
    
      def two do
        File.read!("inputs/four.txt")
        |> String.split("\n\n")
        |> Enum.map(&parse/1)
        |> Enum.reject(fn x -> !(valid_keys?(x)) end)
        |> Enum.count(&valid_values?/1)
      end
    
      def parse(input) do
        input
        |> String.split(~r/\s+/, trim: true)
        |> Enum.map(&(String.split(&1, ":")))
        |> Enum.map(fn [k, v] -> {String.to_atom(k), v} end)
        |> Map.new()
      end
    
      def valid_keys?(data) do
        Enum.all?([:byr, :iyr, :eyr, :hgt, :hcl, :ecl, :pid], fn key -> Map.has_key?(data, key) end)
      end
    
      def valid_values?(data) do
        Enum.all?(data, fn {key, value} -> valid_value?(key, value) end)
      end
    
    
      def valid_value?(:hgt, value) do
        case Regex.scan(~r/(\d+)(\w+)/, value, capture: :all_but_first) do
          [[val, "cm"]] ->
            String.to_integer(val) in 150..193
          [[val, "in"]] ->
            String.to_integer(val) in 59..76
          _ ->
            false
        end
      end
    
      def valid_value?(:byr, value), do: String.to_integer(value) in 1920..2002
      def valid_value?(:iyr, value), do: String.to_integer(value) in 2010..2020
      def valid_value?(:eyr, value), do: String.to_integer(value) in 2020..2030
      def valid_value?(:hcl, value), do: Regex.match?(~r/#[0-9a-f]{6}/, value)
      def valid_value?(:ecl, value), do: value in ["amb", "blu", "brn", "gry", "grn", "hzl", "oth"]
      def valid_value?(:pid, value), do: Regex.match?(~r/^(\d){9}$/, value)
      def valid_value?(_, _), do: true
    end
    
    3 votes
  5. Comment on <deleted topic> in ~tech

    markh
    Link Parent
    Spectacle is the most important app on MacOS.

    Spectacle is the most important app on MacOS.

    1 vote
  6. Comment on A Missouri bill intended to bar libraries from stocking “age-inappropriate sexual material” for children could land librarians who refuse to comply with it in jail in ~books

    markh
    Link
    Of all the things to target, and with everything available freely on the internet, libraries are somehow an issue in 2020?

    Of all the things to target, and with everything available freely on the internet, libraries are somehow an issue in 2020?

    10 votes
  7. Comment on What's your favourite live album? in ~music

  8. Comment on Len Gon Give It To Ya (mashup of X Gon Give It To Ya by DMX with Steal My Sunshine by Len) in ~music

    markh
    Link
    It’s as if someone made this specifically for me. Thank you for sharing this.

    It’s as if someone made this specifically for me. Thank you for sharing this.

    1 vote
  9. Comment on What display theme do you use ? in ~talk

  10. Comment on TV Tuesdays Free Talk in ~tv

    markh
    Link
    I just started season three of The Handmaid’s Tale. Really dark show but it’s really good if you’re into that kind of thing.

    I just started season three of The Handmaid’s Tale. Really dark show but it’s really good if you’re into that kind of thing.

    2 votes
  11. Comment on What are you reading these days? in ~books

    markh
    Link
    I picked up On Writing by Stephen King and it’s been great so far. If you’re interested in learning more about King, his upbringing, his writing, or how to write in general, I recommend it.

    I picked up On Writing by Stephen King and it’s been great so far. If you’re interested in learning more about King, his upbringing, his writing, or how to write in general, I recommend it.

    1 vote
  12. Comment on Fitness Weekly Discussion in ~health

    markh
    Link
    Any recommendations for healthy pescatarian or vegetarian meal ideas?

    Any recommendations for healthy pescatarian or vegetarian meal ideas?

    2 votes
  13. Comment on What programming/technical projects have you been working on? in ~comp

    markh
    Link Parent
    Have you looked into Michael Hartl’s Rails Tutorial? It’s a really great, free resource for learning Rails and building a full project!

    Have you looked into Michael Hartl’s Rails Tutorial? It’s a really great, free resource for learning Rails and building a full project!

    1 vote
  14. Comment on How to track President Trump (tracking of government employees using cell phones) in ~news

    markh
    Link Parent
    Sure, but given that the technology already exists, it seems unlikely that even making it illegal is enough to deter those who really want it. Instead, I suggest we make it public. Really, really...

    Sure, but given that the technology already exists, it seems unlikely that even making it illegal is enough to deter those who really want it.

    Instead, I suggest we make it public. Really, really public. That’ll get people to care about who is tracking them. What’s the inverse of “out of sight, out of mind”?

    1 vote
  15. Comment on “Join Reddit to keep reading” - an account is now required to read comment threads on the mobile website in ~tech

    markh
    Link Parent
    If they did, I’d stop using Reddit altogether. There are still some valuable communities on the site - niche programming, sports, and fitness communities come to mind - but Reddit as a whole isn’t...

    If they did, I’d stop using Reddit altogether. There are still some valuable communities on the site - niche programming, sports, and fitness communities come to mind - but Reddit as a whole isn’t “cool” anymore, and it never will be ever again.

    7 votes
  16. Comment on What are your personal picks for "Games of the Decade"? in ~games

    markh
    Link Parent
    To put this in perspective, if you worked 8 hours per day every single day - including Saturdays and Sundays - you would reach 3000 hours of work in 375 days, more than one year. That’s a lot of...

    To put this in perspective, if you worked 8 hours per day every single day - including Saturdays and Sundays - you would reach 3000 hours of work in 375 days, more than one year. That’s a lot of time in a game.

    2 votes
  17. Comment on What games have you been playing, and what's your opinion on them? in ~games

    markh
    Link Parent
    Haven’t started Banner Saga yet. Dark souls definitely needs to be played on a big screen. It was kind of giving me a headache when handheld, my best guess being that the textures are really hard...

    Haven’t started Banner Saga yet. Dark souls definitely needs to be played on a big screen. It was kind of giving me a headache when handheld, my best guess being that the textures are really hard to distinguish from each other leaving a strange sense of confusion or maybe vertigo that I haven’t really experienced before. Maybe that’s just me, but I don’t ever get motion sickness, so I’m not entirely sure.

    4 votes
  18. Comment on What games have you been playing, and what's your opinion on them? in ~games

    markh
    Link
    I bought Banner Saga and Dark Souls Remastered on Switch, so naturally I restarted Hollow Knight.

    I bought Banner Saga and Dark Souls Remastered on Switch, so naturally I restarted Hollow Knight.

    7 votes
  19. Comment on Day 6: Universal Orbit Map in ~comp

    markh
    Link
    I got a later start than I wanted to (by several hours), but this one was more fun and easier to understand than the previous day by a good amount. Part 1 const fs = require('fs'); const R =...

    I got a later start than I wanted to (by several hours), but this one was more fun and easier to understand than the previous day by a good amount.

    Part 1
    const fs = require('fs');
    const R = require('ramda');
    const m = fs.readFileSync('input.txt').toString().split('\n')
    
    // Generate nodes
    const generateObjects = array => {
        const nodes = R.flatten(array.map(x => x.split(')')));
        const orbits = [...new Set([...nodes])].map(x => {
            return { node: x, children: [], parent: '' };
        });
    
        for (let i = 0; i < array.length; i++) {
            const [parent, child] = array[i].split(')');
        
            orbits.find(x => {
                if (x.node === parent) {
                    x.children.push(child);
                } else if (x.node === child) {
                    x.parent = parent;
                }
            });
        }
    
        return orbits;
    }
    
    // Takes an array of nodes and returns the total number of orbits
    const findOrbits = array => {
        let orbits = 0;
    
        const recurse = (object, array) => {
            if (object.parent !== '') {
                orbits++;
                return recurse(array.find(x => x.node === object.parent), array);
            } else {
                return;
            }
        }
    
        array.forEach(x => recurse(x, array));
    
        return orbits;
    }
    
    const objects = generateObjects(m);
    const totalOrbits = findOrbits(objects);
    console.log(`Total orbits: ${totalOrbits}`);
    
    Part 2
    const fs = require('fs');
    const R = require('ramda');
    const m = fs.readFileSync('input.txt').toString().split('\n')
    
    // Generate nodes
    const generateObjects = array => {
        const nodes = R.flatten(array.map(x => x.split(')')));
        const orbits = [...new Set([...nodes])].map(x => {
            return { node: x, children: [], parent: '' };
        });
    
        for (let i = 0; i < array.length; i++) {
            const [parent, child] = array[i].split(')');
        
            orbits.find(x => {
                if (x.node === parent) {
                    x.children.push(child);
                } else if (x.node === child) {
                    x.parent = parent;
                }
            });
        }
    
        return orbits;
    }
    
    // Takes a node and returns an array of ordered nodes to root parent
    const traverse = (node, array) => {
        let nodes = [];
        const index = array.findIndex(x => x.node === node);
    
        const recurse = (object, array) => {
            if (object.parent !== '') {
                nodes.push(object.node);
                return recurse(array.find(x => x.node === object.parent), array);
            } else {
                nodes.push(object.node);
            }
        }
    
        recurse(array[index], array);
    
        return nodes;
    }
    
    // Takes two points and an input and returns a distance
    const findDistance = (a, b, input) => {
        const x = traverse(a, input);
        const y = traverse(b, input);
        const intersection = R.head(R.intersection(x, y));
    
        return [...x.slice(1, x.findIndex(x => x === intersection)), ...y.slice(1, y.findIndex(x => x === intersection)).reverse()].length;
    }
    
    const objects = generateObjects(m);
    const distance = findDistance('SAN', 'YOU', objects);
    
    console.log(`Minimum number of orbital transfers required: ${distance}`);
    
    1 vote
  20. Comment on Day 5: Sunny with a Chance of Asteroids in ~comp

    markh
    Link Parent
    Love this and love Elixir. Great work!

    Love this and love Elixir. Great work!

    3 votes