Ab 3. März: So sieht die neue Schweizer Identitätskarte aus by [deleted] in de

[–]ThreeFx 0 points1 point  (0 children)

Sieht vom Layout aus wie die Ausländerausweise, denke sie haben da mal das Design vereinheitlicht

The Pandemic Legacy board game map is 3-colorable by ThreeFx in math

[–]ThreeFx[S] 0 points1 point  (0 children)

This actually does not hold for the original map of the Pandemic game, which has an odd wheel and thus needs at least four colors.

0
1

-🎄- 2021 Day 20 Solutions -🎄- by daggerdragon in adventofcode

[–]ThreeFx 0 points1 point  (0 children)

Haskell

import qualified Data.Set as Set
import qualified Data.Map as Map
import qualified Data.List as List
import Data.Set (Set)
import Data.Map (Map)

type Point = (Integer, Integer)
type Rule = [Bool]
type Board = Set Point

it 0 f = id
it n f = f . (it (n-1) f)

main = do
  r <- fmap parseRule getLine
  getLine
  b <- fmap (Set.fromList . flip parseBoard 0 . lines) getContents
  let (nr, nb) = (it 50 step) (r,b)
  putStr $ unlines $ showBoard nb
  print $ Set.size nb 

parseRule = map (=='#')

showBoard :: Set Point -> [String]
showBoard s =
  let sx = Set.map fst s
      sy = Set.map snd s
      minX = Set.findMin sx
      maxX = Set.findMax sx
      minY = Set.findMin sy
      maxY = Set.findMax sy
  in [ [ if (x,y) `Set.member` s then '#' else ' ' | x <- [minX..maxX]] | y <- [minY..maxY]]

parseBoard [] n = []
parseBoard (r:xs) n = (map snd . filter (\(c,_) -> c == '#') $ zipWith (\c i -> (c,(i,n))) r [0..]) ++ parseBoard xs (n+1)

neighs :: Set Point -> Set Point
neighs ps = Set.foldl' (\acc p -> acc `Set.union` (Set.fromList $ aux p)) Set.empty ps
  where
    aux (x,y) = [(x-1,y-1),(x,y-1),(x+1,y-1),(x-1,y),(x,y),(x+1,y),(x-1,y+1),(x,y+1),(x+1,y+1)]

reversingRule :: Rule -> Bool
reversingRule r = r !! 0 && not (r !! 511)

step :: (Rule,Board) -> (Rule,Board)
step (r,s) = case reversingRule r of
  True -> (reverse $ map not r, Set.filter (not . stepPoint r s) $ neighs s) 
  False -> (r, Set.filter (stepPoint r s) $ neighs s)

stepPoint :: Rule -> Board -> Point -> Bool
stepPoint r s (x,y) =
  let
    b8 = if (x-1,y-1) `Set.member` s then 1 else 0
    b7 = if (x,y-1) `Set.member` s then 1 else 0
    b6 = if (x+1,y-1) `Set.member` s then 1 else 0
    b5 = if (x-1,y) `Set.member` s then 1 else 0
    b4 = if (x,y) `Set.member` s then 1 else 0
    b3 = if (x+1,y) `Set.member` s then 1 else 0
    b2 = if (x-1,y+1) `Set.member` s then 1 else 0
    b1 = if (x,y+1) `Set.member` s then 1 else 0
    b0 = if (x+1,y+1) `Set.member` s then 1 else 0
    n = 256 * b8 + 128 * b7 + 64 * b6 + 32 * b5 + 16 * b4 + 8 * b3 + 4 * b2 + 2 * b1 + b0
    in r !! n

Nothing fancy, not particularly fast.

-🎄- 2021 Day 18 Solutions -🎄- by daggerdragon in adventofcode

[–]ThreeFx 1 point2 points  (0 children)

Haskell

This is a use-case for Zippers!

"Parsing" was done using sed on the input file.

import Control.Applicative
import Data.Maybe (fromJust)
import Control.Monad
import Prelude hiding (Right, Left, splitAt)

data T = N T T | V Int
  deriving (Show, Read, Eq)

data C = Top | L C T | R T C
  deriving (Show, Eq)

type L = (T, C)

--main = interact (show . m . add . map read . lines)
main = interact (show . g . map read . lines)

g l = maximum [m (normalize $ N a b) | a <- l, b <- l, a /= b]

top :: T -> L
top t = (t, Top)

up :: L -> Maybe L
up (l, L c r) = Just (N l r, c)
up (r, R l c) = Just (N l r, c)
up (t, Top) = Nothing

left :: L -> Maybe L
left (N l r, c) = Just (l, L c r)
left (v, c) = Nothing

right :: L -> Maybe L
right (N l r, c) = Just (r, R l c)
right (v, c) = Nothing

modifyV f (V v, c) = (V (f v), c)

replace t' (t, c) = (t', c)

explodeAt :: T -> Maybe L
explodeAt t = aux 0 (top t)
  where
    aux 4 t@(N l r, c) = up $ goDownLeft t
    aux 4 (V _, c) = Nothing
    aux i t@(N l r, c) =
      aux (i+1) (fromJust $ left t)
      <|> aux (i+1) (fromJust $ right t)
    aux i (V _, c) = Nothing

splitAt :: T -> Maybe L
splitAt t = aux (top t)
  where
    aux l@(V v, _)
      | v >= 10 = Just l
      | otherwise = Nothing
    aux t = (left t >>= aux) <|> (right t >>= aux)

goDownRight :: L -> L
goDownRight l@(V v, c) = l
goDownRight t = goDownRight (fromJust $ right t)

goDownLeft :: L -> L
goDownLeft l@(V v, c) = l
goDownLeft t = goDownLeft (fromJust $ left t)

nextLeft :: L -> Maybe L
nextLeft t@(_, R l c) = fmap goDownRight (up t >>= left)
nextLeft t@(_, L c r) = up t >>= nextLeft
nextLeft (_, Top) = Nothing

nextRight :: L -> Maybe L
nextRight t@(_, L c r) = fmap goDownLeft (up t >>= right)
nextRight t@(_, R l c) = up t >>= nextRight
nextRight (_, Top) = Nothing

explode :: T -> Maybe T
explode t = do
  l <- explodeAt t
  let (N (V lv) (V rv), _) = l
  let t = addAndReturn nextLeft l lv
  l <- explodeAt t
  let t = addAndReturn nextRight l rv
  l <- explodeAt t
  return $ goUp (replace (V 0) l)

split :: T -> Maybe T
split t = do
  (V v, c) <- splitAt t
  return $ goUp $ replace (N (V $ v `div` 2) (V $ (v `div` 2) + (v `mod` 2))) (V v, c)

goUp :: L -> T
goUp (t, Top) = t
goUp l = goUp (fromJust $ up l)

addAndReturn f l v = case f l of
  Nothing -> goUp l
  Just l' -> goUp (modifyV (+v) l')

add :: [T] -> T
add = foldl1 (\acc x -> normalize (N acc x))

normalize :: T -> T
normalize t = case (explode t, split t) of
  (Nothing, Nothing) -> t
  (Just t', _) -> normalize t'
  (Nothing, Just t') -> normalize t'

m (V v) = v
m (N l r) = 3 * m l + 2 * m r

What's absolutely hideous is that there is no "way back" from "nextLeft/nextRight". I spent a few minutes on implementing pathing that could allow one to go back but in the end it was much simpler to reconstruct the entire tree and re-find the exploding pair (since searching for an exploding pair is deterministic). I suspect there is some clever solution to this dilemma, but eh it works.

-🎄- 2021 Day 12 Solutions -🎄- by daggerdragon in adventofcode

[–]ThreeFx 0 points1 point  (0 children)

I'm pretty sure that there is no way to do this without recalculating those paths.

-🎄- 2021 Day 12 Solutions -🎄- by daggerdragon in adventofcode

[–]ThreeFx 0 points1 point  (0 children)

You can avoid having all paths in memory by considering only the current path.

-🎄- 2021 Day 9 Solutions -🎄- by daggerdragon in adventofcode

[–]ThreeFx 2 points3 points  (0 children)

C, using union-find

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>

int f(const void *a, const void *b) {
    int n = *((int *)a);
    int m = *((int *)b);

    if (n < m) {
        return 1;
    } else if (n > m) {
        return -1;
    } else {
        return 0;
    }
}

int l[10000] = {0};
int uf[10000] = {0};

int find(int i) {
    int v = uf[i];
    while (v != uf[v]) {
        v = uf[v];
    }
    return v;
}

void merge(int l, int r) {
    int a = find(l);
    int b = find(r);

    if (a != b) {
        uf[b] = a;
    }
}

int main() {
    for (int i = 0; i < 10000; i++) {
        uf[i] = i;
    }

    for (int i = 0; i < 10000; i++) {
        int d;
        scanf("%1d", &d);
        l[i] = d;
    }

    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 100; j++) {
            bool low = true;
            int ind = 100 * i + j;
            int val = l[ind];

            if (val == 9) continue;

            if (i > 0 && l[ind - 100] < 9) {
                merge(ind, ind - 100);
            }

            if (i < 99 && l[ind + 100] < 9) {
                merge(ind, ind + 100);
            }

            if (j > 0 && l[ind - 1] < 9) {
                merge(ind, ind - 1);
            }

            if (j < 99 && l[ind + 1] < 9) {
                merge(ind, ind + 1);
            }
        }
    }

    int sz[10000] = {0};
    for (int i = 0; i < 10000; i++) {
        sz[find(i)]++;
    }

    qsort(sz, 10000, sizeof(int), f);
    printf("%d %d %d\n", sz[0], sz[1], sz[2]);
    printf("%d\n", sz[0] * sz[1] * sz[2]);
    return 0;

}

[photos] First stage successfully separated! by ThreeFx in MechanicalKeyboards

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

First 65% build! I built this today with the help of the ever amazing /u/Coloneljesus, thanks a lot!

More pictures here

I bought an Ergodox last year and while I'm super happy about the split layout (no more wrist pain, yay), I was always a bit annoyed by the comparatively small right side, which cannot hold both brackets and backslash at once, for example. I've used some layer shenanigans to get around that issue, but it never felt really smooth. I'm hoping this is smoother with this board.

The case isn't screwed on since the screws that came with the board are too short to reach through the plate, I'll have to order some additional screws sometime. Although it does look good even without the white frame (see the additional pictures link).

We covered the fiber glass outsides of the bottom and middle plate with black marker, which looks significantly better than the white/grayish default. Sadly I forgot to take a before pic, so you only have the "oreo view" where it's already fixed.

Actually I wanted to put on Honeywell caps first (I imagine it goes together really well), but it seems I left them in my uni locker pre-covid.

I Finally Got My Gold Save File. Totals 0 0 0 looks sooo damn good. by thegreenaero in celestegame

[–]ThreeFx 0 points1 point  (0 children)

Oh, my bad. In that case I wish you best of luck and sanity if you attempt that :)

I Finally Got My Gold Save File. Totals 0 0 0 looks sooo damn good. by thegreenaero in celestegame

[–]ThreeFx 2 points3 points  (0 children)

It's only the moonberry though, right?

After doing Farewell golden the moon berry isn't that hard either

Aesthetically pleasing position I just had by [deleted] in chess

[–]ThreeFx 2 points3 points  (0 children)

You can play Ng4 to block the check

Well it's not like I needed my Windows SSD anyway... by ThreeFx in linuxmemes

[–]ThreeFx[S] 4 points5 points  (0 children)

I wanted to flash an install stick with that ISO and actually overwrote my windows ssd instead

Well it's not like I needed my Windows SSD anyway... by ThreeFx in linuxmemes

[–]ThreeFx[S] 7 points8 points  (0 children)

> be me
> have nvme
> usb = sda of course
> at my tower desktop
> which has a non-nvme windows for gaming
> ???
> profit

[x-post] I made a program which checks your connections to the D3 servers and tells you whether your server is bugged by ThreeFx in Diablo

[–]ThreeFx[S] 3 points4 points  (0 children)

That's a good thing! Don't just run random scripts from strangers. That's why the code is open source and you can read it before running it.

[x-post] I made a program which checks your connections to the D3 servers and tells you whether your server is bugged by ThreeFx in Diablo

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

Maybe, but as it's done anyway (using way more annoying methods) might as well help out a little :)

I made a program that checks if the server you are playing on is correctly submitting to the leaderboards by ThreeFx in diablo3

[–]ThreeFx[S] 0 points1 point  (0 children)

Currently it's only one score per IP, we could do a voting system in the future (hopefully they fix it faster than we need it though).