I just went to look for answers this, since report-uri.com is killing its free tier, and the lowest paid is way higher than my usage justifies. What did you settle on?
New account since lemmyrs.org went down, other @Deebster
s are available.
I just went to look for answers this, since report-uri.com is killing its free tier, and the lowest paid is way higher than my usage justifies. What did you settle on?
One core was busier, but it wasn’t at 100%. My Rust code yesterday was the same, perhaps it’s taking too much time accessing memory.
The time was wall time (as per Starship’s output) but it was still waaay too slow to bother with again!
Have you tried gxhash or one of the other non-cryptographic hashers?
I just ran this on a laptop - it worked (part one only) but took 4h28m21s so Nushell is not a language for AoC (or I just coded it very poorly).
Six minutes? 😅 I was feeling crappy about my 30 seconds (my naive big O cubed(?) logic means my code spends most of its time testing array equalities - 72 billion samples in the flamegraph!)
How have I never noticed that scan()
exists? Very handy.
I liked the zipping of the offset prices, neater than my helper method.
Not too hard today, apart from yesterday’s visit to a cocktail bar leaving me a little hazy in the mind.
use std::{fs, str::FromStr};
use color_eyre::eyre::{Report, Result};
use gxhash::{HashMap, HashMapExt};
const SECRETS_PER_DAY: usize = 2000;
const SEQ_LEN: usize = 4;
type Sequence = [i8; SEQ_LEN];
fn produce(n: usize) -> usize {
let n = (n ^ (n * 64)) % 16777216;
let n = (n ^ (n / 32)) % 16777216;
(n ^ (n * 2048)) % 16777216
}
#[derive(Debug)]
struct Buyer {
prices: [u8; SECRETS_PER_DAY + 1],
changes: [i8; SECRETS_PER_DAY],
}
impl Buyer {
fn price_at_seq(&self, seq: &Sequence) -> Option<u8> {
self.changes
.windows(SEQ_LEN)
.position(|win| win == *seq)
.and_then(|i| self.price_for_window(i))
}
fn price_for_window(&self, i: usize) -> Option<u8> {
self.prices.get(i + SEQ_LEN).copied()
}
}
struct BananaMarket {
buyers: Vec<Buyer>,
}
impl FromStr for BananaMarket {
type Err = Report;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let buyer_seeds = s
.lines()
.map(|s| s.parse::<usize>())
.collect::<Result<Vec<_>, _>>()?;
let buyers = buyer_seeds
.into_iter()
.map(|seed| {
let mut prices = [0; SECRETS_PER_DAY + 1];
let mut changes = [0; SECRETS_PER_DAY];
let mut secret = seed;
let mut price = (seed % 10) as u8;
prices[0] = price;
for i in 0..SECRETS_PER_DAY {
let last_price = price;
secret = produce(secret);
price = (secret % 10) as u8;
prices[i + 1] = price;
changes[i] = price as i8 - last_price as i8;
}
Buyer { prices, changes }
})
.collect();
Ok(Self { buyers })
}
}
impl BananaMarket {
fn sell_with_seq(&self, seq: &Sequence) -> usize {
self.buyers
.iter()
.map(|b| b.price_at_seq(seq).unwrap_or(0) as usize)
.sum()
}
fn maximise_bananas(&self) -> usize {
let mut cache: HashMap<Sequence, usize> = HashMap::new();
for seq in self
.buyers
.iter()
.flat_map(|buyer| buyer.changes.windows(SEQ_LEN))
{
let seq = seq.try_into().unwrap();
cache.entry(seq).or_insert_with(|| self.sell_with_seq(&seq));
}
cache.into_values().max().unwrap_or(0)
}
}
fn part1(filepath: &str) -> Result<usize> {
let input = fs::read_to_string(filepath)?
.lines()
.map(|s| s.parse::<usize>())
.collect::<Result<Vec<_>, _>>()?;
let res = input
.into_iter()
.map(|n| (0..SECRETS_PER_DAY).fold(n, |acc, _| produce(acc)))
.sum();
Ok(res)
}
fn part2(filepath: &str) -> Result<usize> {
let input = fs::read_to_string(filepath)?;
let market = BananaMarket::from_str(&input)?;
Ok(market.maximise_bananas())
}
fn main() -> Result<()> {
color_eyre::install()?;
println!("Part 1: {}", part1("d22/input.txt")?);
println!("Part 2: {}", part2("d22/input.txt")?);
Ok(())
}
Wayne Industries Organic Fertilizer
I missed that line too:
Because there is only a single path from the start to the end
So I also did my pathfinding for every variation in the first part, but realised something must be wrong with my approach when I saw part 2.
That full version is extremely satisfying. I think it’d be even better if there were sound - maybe ascending notes in a scale like in some puzzle games.
I like the take that they have in that thread: Perforce is forking Puppet into a non-Open Source version (but they’re keeping the name).
But I said how they work, not, say, how to use a computer to get onto a website. I’m thinking of future generation’s makers and tinkerers, which seemed to be the gist of the article you posted.
The surface of computing is quite polished nowadays, but that’s not entirely helpful when you can’t access anything under the surface to learn what makes it tick.
I feel this article is looking at a bit of silver as if it’s the lining and writing an article about the cloud.
Definitely there’s less knowledge about how computers work nowadays: e.g. universities now have to teach Computer Science students how file systems and directories work, because kids are used to saving everything in the default folder and just searching for what they want (and we’re talking to those geeky enough to be doing CS).
But there’s more complexity now, and a lot of that stuff is just irrelevant busy work. I remember juggling IRQ lines when installing hardware but luckily that’s auto-configured now. I used to create boot discs and eke out enough memory by skipping the better graphics, mouse driver, etc when not needed but did that teach me much?
On the other hand, we used to have LAN parties as teenagers and would rebuild the networking stack for each game, including some performance tweaks (“Red Alert needs NetBIOS over IPX, right?” “Yeah, but disable the turbo encabulator”) and ¾ of us went on to do CS at uni. We certainly never thought of a web browser as “the internet” and we’re confident to explore knowing we could fix what we broke (and did, often).
The main thing I remember about Dijkstra’s algorithm was that at uni when we coded it up in the lab my version had a bug where a certain node was always 0, so I just left the mouse cursor on top of that mode when I demoed it - got full marks 🤓
I think just announce it’s a thing and let people post as they will. I don’t think a daily thread is necessary, for the reason you say but also that individual posts would get more attention - and extra attention is warranted since there’s a lot of extra work that goes in to them.
Perhaps you could run an “advent of vis” where on the first of Jan we post visualisations of our solutions for day 1, etc.
Maybe you’re already editing it in, but there’s no description in your post.
That’s a six book series, if I remember rightly. I love Pratchett’s stuff (Men at Arms is next on my Discworld reread) but I was thinking of his solo stuff. Normally I just start at the first published if I think I’ll enjoy the whole lot.
I haven’t read anything by him, where is a good place to start? Here?
Perhaps they should keep working on it, then. Easier said than done, I know…