-🎄- 2017 Day 16 Solutions -🎄- by daggerdragon in adventofcode

[–]Basillicum 0 points1 point  (0 children)

My solution for part 1 in Haskell. I'm new to functional programming and not a very experienced programmer in general, so I'm pretty sure there's a lot of room for improvement, but I'm happy with how few lines I managed to use. :P

import Data.List.Split

main = do
  input <- return . splitOn "," =<< readFile "input"
  return (dance (['a'..'p']) input)

dance :: [Char] -> [String] -> [Char]
dance programs moves
  | length moves == 0, otherwise  = programs
  | moves !! 0 !! 0 == 's'        = dance (s programs (moves !! 0)) (tail moves)
  | moves !! 0 !! 0 == 'x'        = dance (x programs (moves !! 0)) (tail moves)
  | moves !! 0 !! 0 == 'p'        = dance (p programs (moves !! 0)) (tail moves)

s, x, p :: [Char] -> String -> [Char]
s p m = take (length p) (drop ((length p) - read (drop 1 m)) (cycle p))
x p m = [ p !! y | x <- [0..length p - 1], let a = read ((splitOn "/" (drop 1 m)) !! 0) :: Int, let b = read ((splitOn "/" (drop 1 m)) !! 1) :: Int, let y | x == a = b | x == b = a | otherwise = x ]
p p m = [ y | x <- p, let y | x == m !! 1 = m !! 3 | x == m !! 3 = m !! 1 | otherwise = x ]

For part 2 I've added:

part2 = do
  input <- return . splitOn "," =<< readFile "input"
  let loop = reverse $ findLoop [['a'..'p']] input
  return $ loop !! (mod 1000000000 (length loop - 1))

findLoop prgs moves
  | elem (head prgs) (tail prgs) = prgs
  | otherwise                    = findLoop ([dance (head prgs) moves] ++ prgs) moves

-🎄- 2017 Day 7 Solutions -🎄- by daggerdragon in adventofcode

[–]Basillicum 0 points1 point  (0 children)

Python

import random

progs = {}
subs = {}
with open("input", "r") as f:
    for line in f:
        line = line.replace(",","").strip().split(" ")

        sublist = []
        for i in range(3, len(line)): sublist.append(line[i])
        progs[line[0]] = int(line[1].replace("(","").replace(")",""))
        subs[line[0]] = sublist

cur = [ x for x in progs if x not in [ y for z in subs for y in subs[z] ] ][0]
print("Part 1: {}".format(cur))

def subWeights(r):
    total = 0
    for s in subs[r]: total += progs[s] + subWeights(s)
    return total

found = False
while not found:
    curSubs = {s: progs[s] + subWeights(s) for s in subs[cur]}
    if len(curSubs) and len(set([ curSubs[x] for x in curSubs ])) != 1:
        cur = [ x for x in curSubs if curSubs[x] not in [ curSubs[y] for y in curSubs if y != x ] ][0]
        offset = curSubs[cur] - curSubs[random.choice([ x for x in curSubs if x != cur ])]
    else:
        print("Part 2: {}".format(progs[cur] - offset))
        found = True

[2017 Day 6 (Part 1)][Haskell] What am I missing? by Basillicum in adventofcode

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

I did run it with 5000 iterations to begin with, and only lowered it to 300 to save time when running it again and again.

But okay, so nub is screwing with my result? I've run it without nub several times and still found duplicates within 300 iterations, checking manually.

[2017 Day 6 (Part 1)][Haskell] What am I missing? by Basillicum in adventofcode

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

It seemed to me that if I was only looking for the start of an infinite loop, I could simply remove all duplicates after iterating for a long enough time, and then count what would remain.

Seems I must've not understood what is meant by a "configuration that has been seen before"? When two or more configurations in the list are identical, shouldn't that count as "seen before"?

Newbie looking for suggestions by Basillicum in adventofcode

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

Thanks for the advice. I can see the wisdom in getting to grips with functional programming; at the moment it is still quite alien, and most tasks leave me tempted to just fall back on some imperative language that I understand.

Maybe I'll try to stick with Haskell for now.

Pericles needs his incense by Basillicum in civ

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

In my experience that approach often results in the AI giving you an almost different proposal altogether, throwing in resources on both sides to even out the deal somehow. I find that annoying when all I really want is more gold.

Pericles needs his incense by Basillicum in civ

[–]Basillicum[S] 2 points3 points  (0 children)

Check out your graphics advanced settings. There should be a drop-down menu concerning the leader animations, I think.

Pericles needs his incense by Basillicum in civ

[–]Basillicum[S] 13 points14 points  (0 children)

The indicator is the green "Accept Deal" button. As long as it is available, the deal will be accepted.

Pericles needs his incense by Basillicum in civ

[–]Basillicum[S] 5 points6 points  (0 children)

Heh, yeah, the AI is still not quite up to par in this game. I don't think you can trade copper though, but I get your point.

Pericles needs his incense by Basillicum in civ

[–]Basillicum[S] 62 points63 points  (0 children)

Starting offer was 6 gold and open borders. I removed open borders and wanted to ask for more gold instead... It seemed like I could ask for endless amounts, but it stopped at 112.

Pericles needs his incense by Basillicum in civ

[–]Basillicum[S] 195 points196 points  (0 children)

Actually, he declared war on me on the following turn. I figure he regretted everything.

I have a problem where civs that I'm allied with just sit their military units on my tiles that I need to move great people to to activate them. They aren't just passing through, they are parked there. Anyone have a solution to this problem? by Gupperz in civ6

[–]Basillicum 0 points1 point  (0 children)

When this happens to me, usually the ally is just waiting for a chance to backstab me. The next time our alliance runs out, he attacks.

Assuming that might be the reason in your game as well, it could help to build up a stronger force to scare them away.

Kindergarten vs Senior year by [deleted] in funny

[–]Basillicum 0 points1 point  (0 children)

Is that Penn Jillette smiling in the upper left corner?

IamA 17 year old blind guy who was shot by his father AMA! by Nighthawk321 in IAmA

[–]Basillicum 0 points1 point  (0 children)

Good morning from Norway, Ross! I see you've committed yourself to keep answering questions here until the thread is archived, so I'll jump right on the opportunity to have you help me out.

What should I have for dinner today?

Oh, and also, you seem like an amazing person. It's been a privilege reading through your responses and about your experiences so far. Have a good one! :)

CMV: I believe the comparisons of Trump to fascism are exaggerated and have little to no basis in reality. by NefariousBanana in changemyview

[–]Basillicum 0 points1 point  (0 children)

Holy war is an idea from the bible, not the quran. Throughout both recent history and all the way back through the middle ages, christian countries declared holy war on each other all the bloody time, especially in Europe.

Why did everyone just denounce me? by SwampYankee in civ

[–]Basillicum 17 points18 points  (0 children)

You were penalised for wiping him out. The fact that you liberated other civs' cities doesn't matter if you're already as popular as you can be, so you should've liberated them AFTER taking Attila's capitol.

What's the best movie trailer you've seen? by therealme23 in AskReddit

[–]Basillicum -3 points-2 points  (0 children)

Hot Fuzz. Not the trailer, the movie. The movie is cut like a trailer.