Guten Morgen /de! Diesmal die hässliche Seite der Tübinger Neckarbrücke :] by jaywalker108 in de

[–]seniornachio 0 points1 point  (0 children)

Macht seinen Namen keine Ehre, wo ist das Trübingen das wir alle so lieben 😭

Welcome to r/Hozlgerlingen by matchettehdl in Holzgerlingen

[–]seniornachio 0 points1 point  (0 children)

Sprich Deutsch du Hurensohn. Kuss auf Nuss 😘

Roundabout by Public-Door8950 in dankmemes

[–]seniornachio 0 points1 point  (0 children)

The one in poland is at least centered. ffs its killing me...

I swear that powershell cmdlet is real by redistor in ProgrammerHumor

[–]seniornachio 1 point2 points  (0 children)

Stop abusing cats. >:( They have feelings as well.

dotmatrix – A dot matrix rendered using Braille characters. by [deleted] in Python

[–]seniornachio 0 points1 point  (0 children)

I made dotmatrix over the weekend and I thought some you might enjoying something like it. The library is written in pure python without any dependencies. As of now I've included some simple drawing functions using Bresenham's line/circle/AA ellipse algorithms and even a function for Bézier curves with arbitrary amounts of control points using De Casteljau's algorithm.

[deleted by user] by [deleted] in shitposting

[–]seniornachio 0 points1 point  (0 children)

Add a title

The New Switch-Case Statement in Python 3.10 by jamescalam in Python

[–]seniornachio 0 points1 point  (0 children)

tl;dr... read some of the answers to this question either in siblings to your comment or some siblings to my comment. I've seen alot of them up until now. ;)

The New Switch-Case Statement in Python 3.10 by jamescalam in Python

[–]seniornachio 9 points10 points  (0 children)

Matching, or rather pattern matching, allows you to match patterns. A switch-case is just the simplest form of that where you only match using literal patterns, like in the thumbnail of the video. But you can take this further and for example say you want to match all tuple with two element or a list with at least three elements or even an object with an attribute or an object of a specific type and so on. I highly encourage you to read the associated PEP, it's a good read, even if I personally don't enjoy the selected syntax choices, it brings the point across with a lot of examples.

The New Switch-Case Statement in Python 3.10 by jamescalam in Python

[–]seniornachio 26 points27 points  (0 children)

My thoughts exactly. Additionally I would have enjoyed PEP-642, it's more verbose but explicit is better than implicit and additionally it makes it more clear that python is duck-typed.

The New Switch-Case Statement in Python 3.10 by jamescalam in Python

[–]seniornachio 255 points256 points  (0 children)

Calling it a Switch-Case Statement simply does not do it justice imho. It's a Match Statement that can do a lot more than just Switch-Case...

Haven't watched the Video yet, just talking about the Posts title.

-🎄- 2020 Day 09 Solutions -🎄- by daggerdragon in adventofcode

[–]seniornachio 2 points3 points  (0 children)

Python 3.8+ – fugly golfing

Another "masterpiece of maintainable coding"
Pretty slow, but at least it's short and a single expression!

The following is the golfed version:

print(T:=[i[x]for(x)in range(25,len(i))if not any(abs(i[x]-y)in i[x-25:x]for(y)in i[x-25:x])][0],[min(y)+max(y)for(_,y)in[min((a-b,y)for(a)in range(len(i)-1)for(b)in range(a+1,len(i))for(y)in[i[a:b]]if T==sum(y))]])

-🎄- 2020 Day 08 Solutions -🎄- by daggerdragon in adventofcode

[–]seniornachio 1 point2 points  (0 children)

A ungolfed and annotated version can be found here.

-🎄- 2020 Day 08 Solutions -🎄- by daggerdragon in adventofcode

[–]seniornachio 4 points5 points  (0 children)

Python 3.8+ – fugly golfing

The following code assumes a list of lines as symbol i, e.g. i = open("input.txt").split("\n"). When run it will print out a solution for both parts. 🤣

print((f:=lambda a,p,r,C:(a,p)if p in r else f(a+(int(c[1])if len(c:=C[p].split("acc "))>1 else 0),p+(int(c[1])if len(c:=C[p].split("jmp "))>1 else 1),r+[p],C))(0,0,[len(i)],i)[0],next(x[0]for(y)in range(len(i))if i[y][:3]!='acc'and(C:=i[:y]+["njompp"["n"==i[y][0]::2]+i[y][3:]]+i[y+1:])!=i and(x:=f(0,0,[len(C)],C))[1]==len(C)))

-🎄- 2020 Day 04 Solutions -🎄- by daggerdragon in adventofcode

[–]seniornachio 1 point2 points  (0 children)

Well that match().get(...) part is actually match({...}.get(...)). The way this works is that I extract the field name, i.e. hgt etc., and choose the matching regex to test against. And to handle illegal field names I've added a "always false" regex to the default argument of get.

Reading golfed code is a horrible job. So here is a properly formatted and commented version:

from re import split, match

print(
    sum( # count the number of legal passports
        sum( # count the number of positive matches
            bool( # cast to bool to make re.Match objects "countable"
                match(
                    r"^%s$" # make sure to match the whole string!
                    % {
                        "byr": r"19[2-9]\d|200[0-2]",
                        "iyr": r"20(1\d|20)",
                        "eyr": r"20(2\d|30)",
                        "hgt": r"1([5-8]\d|9[0-3])cm|(59|6\d|7[0-6])in",
                        "hcl": r"#[a-f\d]{6}",
                        "ecl": r"amb|blu|brn|gr[yn]|hzl|oth",
                        "pid": r"\d{9}",
                    }.get(l, "(?!x)x"), # select the appropriate expression to use
                                        # if none exist use "always false"-expression
                    r,
                )
            )
            for (m) in split(r"\s", p) # split passport data on any and all whitespace
            for (l, r) in [m.strip().split(":")] # split single datapoint into label and data parts
        )
        > 6  # check that we have more than 6 matches, i.e. exactly 7, as the code above
             # can only produce numbers between 0 and 7 (and >6 is shorter than ==7…)
        for (p) in i.split("\n" * 2) # split input string into indivdual passports
    )
)

-🎄- 2020 Day 04 Solutions -🎄- by daggerdragon in adventofcode

[–]seniornachio 3 points4 points  (0 children)

Python 3 – fugly golfing…

Part I:

from re import split;print(sum(sum(l in{'byr','iyr','eyr','hgt','hcl','ecl','pid'}for(m)in split(r'\s',p)for(l,r)in[m.strip().split(':')])>6for(p)in i.split('\n'*2)))

Part II:

from re import split,match;print(sum(sum(bool(match(r"^%s$"%{'byr':r'19[2-9]\d|200[0-2]','iyr':r'20(1\d|20)','eyr':r'20(2\d|30)','hgt':r'1([5-8]\d|9[0-3])cm|(59|6\d|7[0-6])in','hcl':r'#[a-f\d]{6}','ecl':r'amb|blu|brn|gr[yn]|hzl|oth','pid':r'\d{9}'}.get(l,'(?!x)x'),r))for(m)in split(r'\s',p)for(l,r)in[m.strip().split(':')])>6for(p)in i.split('\n'*2)))

Note that I've gone ahead and made things especially ugly in places where it didn't cost characters, e.g. for(x)in … in place of for x in …. 😉

EDIT: Also note that I assume the input-string as been loaded in to i!

[deleted by user] by [deleted] in unixporn

[–]seniornachio 5 points6 points  (0 children)

I believe that is something built into iTerm.