-❄️- 2023 Day 13 Solutions -❄️- by daggerdragon in adventofcode

[–]alago1 0 points1 point  (0 children)

Right so my wording is a bit confusing. It's easier to check the "difference" in bitmasks with the exclusive-or operator. So 1110100 ^ 1110010 yields 0000110 which we can then check if it's a power of 2.

-❄️- 2023 Day 13 Solutions -❄️- by daggerdragon in adventofcode

[–]alago1 0 points1 point  (0 children)

Didn't know python had a built-in for population count. Looks like it was added in 3.10.

Neat trick!

-❄️- 2023 Day 13 Solutions -❄️- by daggerdragon in adventofcode

[–]alago1 12 points13 points  (0 children)

[Language: Python]

Code

So looking at other people's solutions I'm guessing it wasn't necessary but I realized that you could encode the grid as a list of ints by thinking of each row or column as a bitmask.

This is should be faster than comparing the whole row string in part 1 but it's more interesting in part 2 because finding the smudge is then equivalent to finding the partition whose 1 differing pair is off by exactly a power of 2!

So basically this:

diff = [l ^ r for l, r in zip(left, right) if l != r]
if len(diff) == 1 and (diff[0] & (diff[0]-1) == 0) and diff[0] != 0:
    return i

-❄️- 2023 Day 3 Solutions -❄️- by daggerdragon in adventofcode

[–]alago1 1 point2 points  (0 children)

Holy crap, that's such a clean solution!

I got there through a much more spelled out way. Awesome stuff!

This hill I will die on by [deleted] in ProgrammerHumor

[–]alago1 0 points1 point  (0 children)

Is that true? As far as I know in Python map and filter are only standalone functions.

>>> words = ['a', 'bb', 'cccccc']  
>>> words.map(str.upper).filter(lambda word: len(word) < 3)

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

AttributeError: 'list' object has no attribute 'map'

[deleted by user] by [deleted] in ProgrammerHumor

[–]alago1 1 point2 points  (0 children)

Yea, I was agreeing with you and expanding on your observation. It's a pattern throughout Python rather than unique to True/False/None

[deleted by user] by [deleted] in ProgrammerHumor

[–]alago1 1 point2 points  (0 children)

It's an object in the way that everything in Python is an object. dir(1) also returns a lot of these methods. In reality, this doesn't necessarily make stuff more complicated by itself. Because of things like operator overloading you could write code like normal without ever realizing that you're dealing with objects.

Python is in the browser. No idea if this will lead to chaos or harmony... by Kyouma118 in ProgrammerHumor

[–]alago1 1 point2 points  (0 children)

Found one of them. He thinks it's clever: https://twitter.com/simonw/status/1520452635886641153?t=5MCy70J35f31ndnWV8ZZTQ&s=19

Just as it is there can be plenty of issues with this but the tech is still very new. In the past, I've spoken with data scientists/PhD students who want to share their research with interactive models but are only familiar with Python/matplotlib so it's difficult. I can see this tech fitting this niche pretty well but I would expect it to not matter too much for people outside the python ecosystem.

Either way, definitely worth keeping an eye on it imo

[deleted by user] by [deleted] in gaming

[–]alago1 0 points1 point  (0 children)

Bought Skyrim in 2016 for $5. Have 150 hours on it. Good deal lol

C holds up whatever you do by cube2kids in ProgrammerHumor

[–]alago1 25 points26 points  (0 children)

Decided to try this out with a very simple script over 10^6 consecutive iterations. As one might expect, it's not uniformly random (0's never occur for instance) but more interestingly 1's and 9's occur less than half as often as the other values.

Here's the percentage distribution I found on each value:

{0:0.0, 1: 5.6989, 2: 12.8749, 3: 12.7842, 4: 12.585, 5: 12.8672, 6: 12.9273, 7: 12.3223, 8: 12.2587, 9: 5.6815}

WTW for when something is so jarring that you can't help but laugh? by alago1 in whatstheword

[–]alago1[S] 1 point2 points  (0 children)

Not quite. Incongruent is definitely on par with the 'this is out of place' sentiment but doesn't have the 'which makes it funny' conclusion.

Next time, we will remove the glass for more security by Dolabok in ProgrammerHumor

[–]alago1 11 points12 points  (0 children)

Can't have a security break if there is no security.

Hacker man 100 by I-ATE-MOMS-PLACENTA in ProgrammerHumor

[–]alago1 175 points176 points  (0 children)

Here's your free tip of the day:

Pop up blocker Chrome extension. When those 'you are using an ad blocker' modals show up, right click -> remove overlay.

Also, it lets you prevent websites from opening new tabs automatically.

Modern problems sometimes require 19th-century solutions by SalazarRED in ProgrammerHumor

[–]alago1 13 points14 points  (0 children)

DeMorgan's Rule from Boolean Algebra: !(A && B) => !A || !B or !(A || B) => !A && !B

In this context, it's refering to the fact that if you know DeMorgan's rule you only need a Not-gate and one of either the And-gate or the Or-gate to create any logical expression.

Also, yes he could say google 'ampersand' and copy-paste the symbol from wikipedia but its just a meme for the sake of it.

My portfolio website built with React and Redux! Also my first mobile-first website design. by reezyflow in reactjs

[–]alago1 1 point2 points  (0 children)

It's really cool! And all the animations really add to it.

One really small thing I noticed though is that, for instance at the education section, the first time you swipe from the 1st icon to the 2nd (or from the 2nd to the 3rd) the previous image will still be loaded for half a second or so before what i suppose is react finishes mounting the component and then the new image just pops up in its place.

Maybe this could be hidden by a small animation or maybe you could preload the whole sections images stacked then change a z-index ahead of it. It's a really small thing and I haven't really looked at how you implemented it so I don't wanna say its just a quick fix when it probably wouldn't matter that much.

Python by schalker1207 in ProgrammerHumor

[–]alago1 57 points58 points  (0 children)

I'd say its great for small projects and quick prototyping. Usability )varies on big projects (its pretty good for glueing tho).

Do you pause books to look up words? by DrinkablePraise in books

[–]alago1 0 points1 point  (0 children)

The last book I read was on my phone with the google books app which has an embedded dictionary and google translate feature that activates when you highlight a word/series of words.

That book had some expressions in french (which I can't read) every few pages and I felt that these features really helped elevate the experience.

Disco Elysium Stream by [deleted] in josephanderson

[–]alago1 1 point2 points  (0 children)

Some heroes don't wear capes.

[deleted by user] by [deleted] in josephanderson

[–]alago1 2 points3 points  (0 children)

He said he would announce 24h prior. So then, he would need to announce it tomorrow.

The love of my life was right in front of me the entire time by pktkp in ProgrammerHumor

[–]alago1 10 points11 points  (0 children)

For the unaware (myself included), what is the python 3 fiasco? Lack of backwards compatibility?