markh's recent activity
-
Comment on Apple / iOS rant in ~tech
-
Comment on Day 6: Custom Customs in ~comp
markh 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
-
Comment on Day 5: Binary Boarding in ~comp
markh 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
-
Comment on Day 4: Passport Processing in ~comp
markh 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
-
Comment on <deleted topic> in ~tech
markh Spectacle is the most important app on MacOS.Spectacle is the most important app on MacOS.
-
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 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?
-
Comment on What's your favourite live album? in ~music
markh Stevie Ray Vaughan - In The Beginning: https://open.spotify.com/album/5judWRJxX0B8BCohZDm69R John Mayer Trio - Try!: https://open.spotify.com/album/0X9bvQYYtrAYdkO4OKtYwz Vulfpeck - Live at...Stevie Ray Vaughan - In The Beginning: https://open.spotify.com/album/5judWRJxX0B8BCohZDm69R
John Mayer Trio - Try!: https://open.spotify.com/album/0X9bvQYYtrAYdkO4OKtYwz
Vulfpeck - Live at Madison Square Garden: https://open.spotify.com/album/5KmXBjpN0wHutYBoDJBxmM
-
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 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.
-
Comment on What display theme do you use ? in ~talk
-
Comment on TV Tuesdays Free Talk in ~tv
markh 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.
-
Comment on What are you reading these days? in ~books
markh 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.
-
Comment on Fitness Weekly Discussion in ~health
markh Any recommendations for healthy pescatarian or vegetarian meal ideas?Any recommendations for healthy pescatarian or vegetarian meal ideas?
-
Comment on What programming/technical projects have you been working on? in ~comp
markh 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!
-
Comment on How to track President Trump (tracking of government employees using cell phones) in ~news
markh 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”?
-
Comment on “Join Reddit to keep reading” - an account is now required to read comment threads on the mobile website in ~tech
markh 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.
-
Comment on What are your personal picks for "Games of the Decade"? in ~games
markh 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.
-
Comment on What games have you been playing, and what's your opinion on them? in ~games
markh 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.
-
Comment on What games have you been playing, and what's your opinion on them? in ~games
markh 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.
-
Comment on Day 6: Universal Orbit Map in ~comp
markh 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}`);
-
Comment on Day 5: Sunny with a Chance of Asteroids in ~comp
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.