Unable to load image

r/drama Advent of Code S02E01 - Official DISCUSSION Thread

Ok you Python-using heathens. What did you think for difficulty this time around?

Post your coding atrocities below.

For those of you who missed the early signups. Feel free to join the leaderboard late (though rankings are based on time).

42
Jump in the discussion.

No email address required.

HI PEOPLE HERE FROM THE STICKY

DONT WORRY ABOUT BEING LATE. LAST YEAR FINISHING EVERY DAY AT ALL WAS ALREADY TOP 10 PRETTY MUCH

JUST GET IT NOW AND DO IT WHEN YOU HAVE TIME

Jump in the discussion.

No email address required.

Alrighty, enough solutions have been posted that this won't be a major spoiler anymore.

Here's a nice, clean, Pythonic solution:

from num2words import num2words as n2w
𝓜 = {𝓕(𝓭):𝓭 for 𝓕 in [n2w,str] for 𝓭 in range(10)}
屎 = lambda 鲤: [(屙(鲤,屁), 𝓜[屁]) for 屙 in [str.find,str.rfind] for 屁 in 𝓜 if 屁 in 鲤]
ඞ = lambda ම: min(ම)[1]*10+max(ම)[1]
print(sum(ඞ(屎(𝓛)) for 𝓛 in open('feed&seed.txt').readlines()))
Jump in the discussion.

No email address required.

import num2words

:marseycringe2:

Jump in the discussion.

No email address required.

Cry more. While you spent nine hours typing out the names of all the digits, my four hundred gigabyte python venv was already blasting through problems which haven't even been posted yet.

Jump in the discussion.

No email address required.

lol import problemsolver

Jump in the discussion.

No email address required.

"I used Python but had someone else solve it for me"

:#marseynerd2talking:

Jump in the discussion.

No email address required.

Most based solution

Jump in the discussion.

No email address required.

屙鲤屁

i wonder if anyone realised what those characters meant :marseywink:

Jump in the discussion.

No email address required.

bash chads stay winning hahahahaha you fricking losers

https://i.rdrama.net/images/17014115319550986.webp

Jump in the discussion.

No email address required.

Obscenely based, can't wait until day 18

Jump in the discussion.

No email address required.

im not even using bash in this one it's just shell

this isn't even my final form

Jump in the discussion.

No email address required.

score = sum([int(''.join((lambda digits : (digits[0], digits[-1]))([char for char in line if char.isdigit()]))) for line in lines])

one line of pure python :marseygigachad:

edit apparently there are two parts :marseygigaretard:

also did part 2 in one line :marseychadretardtrump:

print(sum([int(''.join((lambda digits : (digits[0], digits[-1]))([number for number, index in sorted([item for sublist in [get_matches(line, number_pair) for number_pair in [(str(i+1), str(i+1)) for i in range(10)]+[(string, str(i+1)) for i, string in enumerate(['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'])]] for item in sublist], key=lambda a : a[1])]))) for line in lines]))
Jump in the discussion.

No email address required.

I got both puzzles but don't laugh at my solution for the 2nd one :marseysad:

I've been very, very slowly teaching myself Python after learning Matlab at college

https://i.rdrama.net/images/17014130661729786.webp https://i.rdrama.net/images/17014130662879624.webp

Jump in the discussion.

No email address required.

Everywhere that you think you need a tree of if/elif/else based on the same value you can use a dict:

val_map = {
 'one': 1,
 'two': 2,
 # ...
}

Then you get the value using val1 = val_map[val1] or if you need a default, your else here, use .get(key, default):

val1 = val_map.get(val1, int(val1))
Jump in the discussion.

No email address required.

zoz

Jump in the discussion.

No email address required.

zle

Jump in the discussion.

No email address required.

zozzle

Jump in the discussion.

No email address required.

:marseynotes:

That's a better example of the use of a dictionary than anything those coding bootcamps told me

Jump in the discussion.

No email address required.

:#capyhackerlove::#capyhackerlove::#capyhackerlove:

Proud of you, little buddy.

Jump in the discussion.

No email address required.

Never be ashamed of your solution if it gets the work done.

Especially since your solution is clean and understandable by everyone. Sure it's a bit convoluted, but who cares ;)

Jump in the discussion.

No email address required.

Part 2 solution is keyed, ignore the haters

Jump in the discussion.

No email address required.

I think your solution for the second one is really cute. In the future you can just use rfind though.

I love the little word games some people play with it to get it to work

Jump in the discussion.

No email address required.

My solution is nothing special (maybe a little bit inefficient but who cares)

https://i.rdrama.net/images/1701425805834543.webp

@L this can be used to generate images of code https://carbon.vercel.app

Jump in the discussion.

No email address required.

The O(logn) virgins fear the O(n^2) chad

Jump in the discussion.

No email address required.

I'll put it in my template for tomorrow. I'll actually be able to post code then too since it's a weekend.

Jump in the discussion.

No email address required.

r←⊃⎕NGET'i1.txt'1
d←'one' 'two' 'three' 'four' 'five' 'six' 'seven' 'eight' 'nine'
f←{+/⍎¨(1∘↑,¯1∘↑)¨(∊∘⎕d⊢⍤/⊢)¨⍵}
g←{m←+/¨p←⍷∘⍵¨d ⋄ (m/'123456789')@(∊(⊢⊢⍤/⍳∘≢)¨p)⊢⍵}
⎕←f r ⋄ ⎕←f g¨r
Jump in the discussion.

No email address required.

you didnt answer me last year so im gonna ask again, do you own an apl keyboard? i cant imagine trying to write apl without one but i also cant imagine learning how to use one.

Jump in the discussion.

No email address required.

I use a regular physical board (right ctrl to switch layouts) with the layout open in a terminal:

https://i.rdrama.net/images/170141423679296.webp

You barely look at the keyboard when you're typing anyway.

Jump in the discussion.

No email address required.

neat, ty

Jump in the discussion.

No email address required.

apl

you got me into it. i started learning dyalog a few days ago. i wanted to play with the bitmask aspect of it so i did this

input←⊃⎕NGET 'i1.txt' 1

⍝ First we begin by defining our functions
Nums←{⍵∩'0123456789'}
]dinput
GetLongValue←{
   left←⊣/⍵
   right←⊢/⍵
   ⍎left,right
}

⍝ Next we process our input so that we trim out the text characters
Processed←Nums¨input ⍝ All the numbers in the input lines

⍝ Next were going to create input masks to apply different logic based on if a line has >=2 numbers or not
NormalInputsMask←{(⍴⍵)>1}¨Processed ⍝ This mask will be used for  long values
ShortInputsMask←~NormalInputsMask ⍝ This mask will be used for short values

ShortValues←(⊃¨ShortInputsMask)/Processed
LongValues←(⊃¨NormalInputsMask)/Processed

Short←⍎¨2/¨ShortValues
Long←GetLongValue¨LongValues
((+/Long)++/Short)
Jump in the discussion.

No email address required.

Got ugly once I spotted the portmaeaus

:#marseyabandoned:

https://i.rdrama.net/images/17014163215883934.webp

Jump in the discussion.

No email address required.

Oh I like this one

Jump in the discussion.

No email address required.

clever

Jump in the discussion.

No email address required.

Regex is king:

https://i.rdrama.net/images/17014259927056096.webp

Side note: Nim has a nice bit of syntactic sugar for matching regexes:

import std/re
let regex = re".*?(drama)"
const text = "rdrama.net"
if text =~ regex:
   echo matches[0] # prints "drama"

However, it will only use an existing matches array if it's declared in the enclosing scope, not any scopes above it. This means the array would be recreated every loop cycle, making it several times slower :marseysadge:

Jump in the discussion.

No email address required.

literally, For the first:

https://i.rdrama.net/images/17014402120388875.webp

For the second:

https://i.rdrama.net/images/17014400076768467.webp

Got pretty much the same thing, but couldnt figure out how to do a backward regex cause I suck at regex but go off i guess

Jump in the discussion.

No email address required.

Regex is the way, but I completely admit to getting stuck for a minute because I forgot about match consumption and lookahead and all that shit that you tend not to think about from day to day: https://stackoverflow.com/questions/11430863/how-to-find-overlapping-matches-with-a-regexp

// LOL nope:
let matches = Array.from(line.matchAll(/[1-9]|one|two|three|four|five|six|seven|eight|nine/g));

// Better:
let matches = Array.from(line.matchAll(/(?=([1-9]|one|two|three|four|five|six|seven|eight|nine))/g));
Jump in the discussion.

No email address required.

https://i.rdrama.net/images/1701436366578111.webp

Maybe c++ is not the right choice for this.

Jump in the discussion.

No email address required.

There's a LOT of file parsing involved. But I think if you keep building a library of all these functions by the end of the month and reusing them it won't be horrible

Jump in the discussion.

No email address required.

wtf.. pretty sure i can do it in C with a few for loops I think you overdid it a bit there lmao

Jump in the discussion.

No email address required.

was nice that he threw in the "word numbers can actually be portmanteaus" bit cause it made it not braindead, but i feel like there will be a lot more of this trickery

oh wait i didnt even use islice after all

https://i.rdrama.net/images/17014120779218445.webp

Jump in the discussion.

No email address required.

Wait that rule was there? I didn't do it either lmao

Jump in the discussion.

No email address required.

my example data for p2 was

two1nine
eightwothree
abcone2threexyz
xtwone3four
4nineeightseven2
zoneight234
7pqrstsixteen

i didnt want to think about trying to handle shit like eleven, twelve, and thirteen because they are gay edge cases but it never came up so ime assuming the -teen suffixes were dropped in to bait people

Jump in the discussion.

No email address required.

Oh I thought you said palindrome whoops

Yeah the text explicitly said only up to 9 was considered. It's an English test

Jump in the discussion.

No email address required.

wait did it? :#marseyhungover:

Jump in the discussion.

No email address required.

>It looks like some of the digits are actually spelled out with letters: one, two, three, four, five, six, seven, eight, and nine also count as valid "digits".

Yeah it gave a very clear list

Jump in the discussion.

No email address required.

vomited the ugliest, least efficient or concise or consistent code I could and I was still so SLOW

<4 mins for p1 and 34 mins for p2

https://files.catbox.moe/0zm8oq.png

Jump in the discussion.

No email address required.

I thought you meant the shitty vomit code took 34 minutes to execute at first and I was almost impressed

Jump in the discussion.

No email address required.

That would be like that old chess game from the early 90s where if you turned up the "AI" it just intentionally took like a minute to "figure out" its move.

Jump in the discussion.

No email address required.

Wait the rankings are based on time that is so f****** gay I'd have to get up at like 1:00 in the morning to compete f*** that


Give me your money and I'll annoy people with it :space: https://i.rdrama.net/images/16965516366194396.webp

Jump in the discussion.

No email address required.

This was last years. If you do it at all you'll be fine even if it's late

https://i.rdrama.net/images/17014368739755745.webp

Jump in the discussion.

No email address required.

There's major burnout around day 10 or so. Last year, day 12 was some pathfinding thing. I was on vacation, and I had spent a couple hours on it, and like a lightbulb going off over my head I was like "what in the frick am I doing with my spare time?" and I quit. I have a feeling that's a pretty typical experience with this thing unless you're hardcore.

Jump in the discussion.

No email address required.

"Get up" 🤔🤭

Jump in the discussion.

No email address required.

I go to bed at 7pm


Give me your money and I'll annoy people with it :space: https://i.rdrama.net/images/16965516366194396.webp

Jump in the discussion.

No email address required.

Based boomersleeper.

Jump in the discussion.

No email address required.

it keeps my complexion healthy :marseywholesome:


Give me your money and I'll annoy people with it :space: https://i.rdrama.net/images/16965516366194396.webp

Jump in the discussion.

No email address required.

https://i.rdrama.net/images/17014484671925075.webp

Jump in the discussion.

No email address required.

Am I just r-slurred or is there not enough information for the second part? I don't know if characters can be reused or not, IE is eightwo interpreted as 82 or 8wo

Jump in the discussion.

No email address required.

In your example eightwo is 82 (8 is the first number, 2 is the last number)

Jump in the discussion.

No email address required.

std::string fan vs std::string_view enjoyer

Jump in the discussion.

No email address required.

1/5 Imma just read the file and add them all up

Jump in the discussion.

No email address required.

brain++

Jump in the discussion.

No email address required.

Fear my shitcode. Sepples returning -1 on not finding stuff fricked me for the longest time and I kept adding bloat trying to compensate for things I thought might be causing the issue :marseyraging:

Got it working though, I'm shaking the rust off bros :marsey#exciteddance:

https://i.rdrama.net/images/17014585467690508.webp

Jump in the discussion.

No email address required.

Took me a long time to remember to do this but I beat the release of day two :)

I bounced off haskell immediately and cbf re-learning from scratch so it's rust season again:

// line, head, tail, recursive
fn part2(line: String, first: Option<char>, last: Option<char>) -> String {
   let mut new_first = first;
   let mut new_last = last;

   if line.len() == 0 {
       return format!("{}{}", first.unwrap(), last.unwrap());
   } else {
       for p in [
           ("one", '1'),
           ("two", '2'),
           ("three", '3'),
           ("four", '4'),
           ("five", '5'),
           ("six", '6'),
           ("seven", '7'),
           ("eight", '8'),
           ("nine", '9'),
       ] {
           if line.starts_with(p.0) {
               if first.is_none() {
                   new_first = Some(p.1);
               }
               new_last = Some(p.1);
               break;
           }
       }

       let mut ln_new = line.chars();
       let c = ln_new.next().unwrap();
       if c.is_digit(10) {
           if first.is_none() {
               new_first = Some(c);
           }
           new_last = Some(c);
       }

       return part2(ln_new.collect(), new_first, new_last);
   }
}

fn main() {
   // Part One
   let lines = include_str!("input.txt").lines().collect::<Vec<_>>();
   let mut n = 0;
   for line in lines.clone() {
       let mut first: Option<char> = None;
       let mut last: Option<char> = None;
       for c in line.chars() {
           if c.is_digit(10) {
               if first.is_none() {
                   first = Some(c);
               }
               last = Some(c);
           }
       }

       n += format!("{}{}", first.unwrap(), last.unwrap())
           .parse::<i32>()
           .unwrap();
   }

   println!("Part 1: {}", n);

   // Part Two
   let mut m = 0;
   for line in lines {
       m += part2(line.to_string(), None, None).parse::<i32>().unwrap();
   }

   println!("Part 2: {}", m);
}
Jump in the discussion.

No email address required.

I have to say rust is less ugly than I thought it'd be. Why did they choose let var: Type = ... instead of just Type var = ...?

Jump in the discussion.

No email address required.

Most of the time it will infer the type from what's passed in/used later, but yeah shit can get cluttered

Jump in the discussion.

No email address required.

You had a chance to not be completely worthless, but it looks like you threw it away. At least you're consistent.

Jump in the discussion.

No email address required.

Ugly but it works.

# Part One
with open("1.txt") as infile:
   data = infile.read()

total = 0
for line in data.splitlines():
   digits = [c for c in line if c.isdigit()]
   v = int(digits[0]+ digits[-1])
   total += v
print(total)

# Part Two
import re

words = ['zero','one','two','three','four','five','six','seven','eight','nine']
ws = '|'.join(words)
pat = re.compile(fr'(?=({ws}|\d))')
total = 0
for line in data.splitlines():
   g = pat.findall(line)
   a, b = g[0], g[-1]
   v = str(a if a.isdigit() else words.index(a)) + str(b if b.isdigit() else words.index(b))
   total += int(v)
print(total)
Jump in the discussion.

No email address required.

Post your coding atrocities below.

You would like to know my secrets, wouldn't you, filthy silvercel?

Jump in the discussion.

No email address required.

what is this btw

Jump in the discussion.

No email address required.

Fistmas themed coding puzzles.

https://adventofcode.com

Join the rdrama leaderboard with code 2416137-393b284c.

Jump in the discussion.

No email address required.

ez

Jump in the discussion.

No email address required.

Oh shit, it's that time of the year already?

Python was too easy last year, so this time I'm using C++.

#include <iostream>
#include <fstream>
#include <string>
#include <vector>

using std::string;
using std::ifstream;
using std::cout;
using std::vector;

auto main(int argc, char * argv[]) -> int
{
   ifstream readfile("day1_input.txt");
   string readline;
   vector<string> num_strings{"one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
   int result = 0;

   while(getline(readfile, readline)){
       char first = 'x';
       char second = 'x';
       readline = readline.substr(0, readline.size()-1);

       for(int i=0;i<readline.size();i++) {
           if(readline[i] < 97 || readline[i] > 122\. {
               first = readline[i];
               break;
           }
           else {
               for (int n=0;n<num_strings.size();n++)
                   if((i + num_strings[n].size()) <= readline.size() && readline.substr(i, num_strings[n].size()) == num_strings[n]) {
                       first = '0' + (n+1);
                       break;
                   }
               if (first != 'x') break;
           }
       }
       for(int i=readline.size()-1;i>=0;i--) {
           if(readline[i] < 97 || readline[i] > 122\. {
               second = readline[i];
               break;
           }
           else {
               for (int n=0;n<num_strings.size();n++)
                   if((i + num_strings[n].size()) <= readline.size() && readline.substr(i, num_strings[n].size()) == num_strings[n]) {    
                       second = '0' + (n+1);
                       break;
                   }
               if (second != 'x') break;
           }
       }
       string concat = string{first, second};
       result += std::stoi(concat);
   }
   cout << result << '\n';
}
Jump in the discussion.

No email address required.

>too easy last year

so you must have made the leaderboard every day, huh?

Jump in the discussion.

No email address required.

The challenges open at 5am my time so frick that noise. :marseysipping:

My personal goal is just to get all the stars within 24 hours of them dropping.

Jump in the discussion.

No email address required.

>challenge opens in two hours

neighbor you stay up til 3am anyways, wtf do you care?

Jump in the discussion.

No email address required.

  .-""-.
 /,..___\
() {_____}
  (/-@-@-\)
  {`-=^=-'}
  {  `-'  } Merry Fistmas!
   {     }
    `---'
Jump in the discussion.

No email address required.

It's nothing good. I'm trying to learn a faster language and I picked Rust because I really like their package manager. I'd rather use C tbh, I've tried it before and prefer it, but everytime I try to use Cmake I have the urge to kill whoever designed it.

https://i.rdrama.net/images/1702410997426287.webp

I might go back and do the second part later

Jump in the discussion.

No email address required.

Link copied to clipboard
Action successful!
Error, please refresh the page and try again.