[ 3 / biz / cgl / ck / diy / fa / g / ic / jp / lit / sci / tg / vr / vt ] [ index / top / reports / report a bug ] [ 4plebs / archived.moe / rbt ]

Due to resource constraints, /g/ and /tg/ will no longer be archived or available. Other archivers continue to archive these boards.Become a Patron!

/g/ - Technology

View post   

[ Toggle deleted replies ]
File: 27 KB, 407x446, grad.png [View same] [iqdb] [saucenao] [google] [report]
68761730 No.68761730 [Reply] [Original] [archived.moe] [rbt]

T-minus Ten Minutes Edition

Previous thread: >>68757392

>Advent of Code is a series of small programming puzzles for a variety of skill levels. They are self-contained and are just as appropriate for an expert who wants to stay sharp as they are for a beginner who is just learning to code. Each puzzle calls upon different skills and has two parts that build on a theme.
You need to register with an account but you can appear as anonymous.

Private leaderboard join code:


People who are inactive for 5 days will be kicked, but other leaderboards can be made if desired.

Alternative leaderboard for those waiting for inactives to be kicked from the first:


>> No.68761745
File: 35 KB, 277x245, honkhonkmotherfucker.jpg [View same] [iqdb] [saucenao] [google] [report]


>> No.68761747

holy shit you only just made it with 60000 ms to spare

>> No.68761751
File: 260 KB, 553x900, 1501356406011.jpg [View same] [iqdb] [saucenao] [google] [report]


>> No.68761754


>> No.68761755
File: 2.34 MB, 450x258, 1375579098628.gif [View same] [iqdb] [saucenao] [google] [report]

>> No.68761757


>> No.68761763
File: 592 KB, 914x898, 1494840171364.png [View same] [iqdb] [saucenao] [google] [report]

here we go

>> No.68761765
File: 326 KB, 1100x450, dab_on_the_sneeds.gif [View same] [iqdb] [saucenao] [google] [report]


>> No.68761767


>> No.68761768
File: 1.60 MB, 1280x720, australia's got talent.webm [View same] [iqdb] [saucenao] [google] [report]


>> No.68761772

Will today's problem be the brainlet filter?

>> No.68761773

>10 threads in 3 days

>> No.68761774
File: 17 KB, 320x276, 615269-uncle_gabby.jpg [View same] [iqdb] [saucenao] [google] [report]

>that fucking CG
get that shit outta here

>> No.68761775

>hate python
>use it anyway because best option for slapping shit together

>> No.68761780
File: 153 KB, 426x470, dabs.png [View same] [iqdb] [saucenao] [google] [report]

>promised myself I won't get panicky this time
>already panicking


>> No.68761782

aka everyone on the leaderboards because it's the best for throwing shit together

>> No.68761783

Fuck yeah I finished my taquitos just in tome

>> No.68761789

Fuck I need to take a shit

>> No.68761790

where are my O(n^2) lads at?

>> No.68761791
File: 145 KB, 670x424, comfy.jpg [View same] [iqdb] [saucenao] [google] [report]


>> No.68761792

Infinite matrix here we come

>> No.68761793

The guy in the lead is using ruby

>> No.68761795


>> No.68761797


>> No.68761798
File: 22 KB, 112x112, rem think.png [View same] [iqdb] [saucenao] [google] [report]


>> No.68761805
File: 67 KB, 393x363, bocchi smile hood.png [View same] [iqdb] [saucenao] [google] [report]


>> No.68761806
File: 2.01 MB, 158x158, 1418754418138.gif [View same] [iqdb] [saucenao] [google] [report]

Who knew AoC turned me into a competition-ready speed eater

>> No.68761807



>> No.68761808

rem is a cute
i am a suicide
advent of code is hard

>> No.68761814
File: 373 KB, 509x725, himiko.png [View same] [iqdb] [saucenao] [google] [report]

i hope you lads have your scratch paper ready

>> No.68761815

>wc -l input.txt
Fuck yeah, I will O(n^2) all day if the inputs are gonna be that small

>> No.68761816


Actually he made it with 555,000 ms to spare.

>> No.68761817
File: 752 KB, 1000x1230, 1538946916763.jpg [View same] [iqdb] [saucenao] [google] [report]


>> No.68761820

Damn, I won't be able to do today's in time

>> No.68761821
File: 45 KB, 548x395, Screenshot from 2018-12-03 05-56-48.png [View same] [iqdb] [saucenao] [google] [report]


>> No.68761822
File: 14 KB, 416x416, 1535050408899.gif [View same] [iqdb] [saucenao] [google] [report]

/ready for brainlet filter/ over here boss

>> No.68761823

Ready and willing!

>> No.68761825
File: 327 KB, 500x504, 1494615907561.png [View same] [iqdb] [saucenao] [google] [report]


>> No.68761826

my code maaaaaaaaagic is ready UwU

>> No.68761827
File: 1.03 MB, 500x500, 1538610024083.gif [View same] [iqdb] [saucenao] [google] [report]


>> No.68761828

goodnight /aocg/. I'll join you on problem 3 sometime tomorrow

>> No.68761832

wtf it drops in two minutes, why would you go to sleep now

>> No.68761833

the perfect tune for right now

>> No.68761835
File: 75 KB, 604x415, 1520402280735.jpg [View same] [iqdb] [saucenao] [google] [report]


>> No.68761836

>Tfw downloaded the 500mb input file for the "bonus challenge" and still trying to figure out how to make it run efficientlyefficiently

>> No.68761838
File: 46 KB, 640x362, star-wars4-movie-screencaps.com-13175.jpg [View same] [iqdb] [saucenao] [google] [report]

Attention! This is Red Leader, I need all languages to report in and form up in attack formation!

>> No.68761839
File: 276 KB, 395x355, chio_gaming.png [View same] [iqdb] [saucenao] [google] [report]

Good luck, guys!

>> No.68761841
File: 29 KB, 480x480, 1538671861161.jpg [View same] [iqdb] [saucenao] [google] [report]


>> No.68761842

Last call to fire up any documentation you need for quick reference.

>> No.68761846


>> No.68761847


>> No.68761848


>> No.68761849

MATLAB ready!

>> No.68761851

wew is anyone else getting sleepy ITT? Who's John Podesta again?

>> No.68761854

who are you kidding, it's all python up in here

>> No.68761856


>> No.68761857
File: 66 KB, 600x450, 1479270626571.jpg [View same] [iqdb] [saucenao] [google] [report]


>> No.68761858
File: 3.38 MB, 432x324, 1534758533417.gif [View same] [iqdb] [saucenao] [google] [report]


>> No.68761860


>> No.68761861


>> No.68761862


>> No.68761863


>> No.68761864


>> No.68761869

Because I have work tomorrow and the time that the problems drop happens to be exactly the latest I can stay up without being tired the next day.

>> No.68761871


>> No.68761873


>> No.68761874

Oh, this gon' be bad...

>> No.68761875


>> No.68761881
File: 56 KB, 313x254, laughterstops.jpg [View same] [iqdb] [saucenao] [google] [report]


>> No.68761882
File: 22 KB, 375x369, 1505931274240.png [View same] [iqdb] [saucenao] [google] [report]

>> No.68761883


>> No.68761885


>> No.68761889


>> No.68761890


>> No.68761892

I'm not even gonna bother trying to rush this.

>> No.68761894


>> No.68761897

based aoc guy dropping the brainlet filter on day 3

>> No.68761899

yeah, fuck this, im going to bed and going to work, will try to do after work

>> No.68761900

Bye guys, I'm going to rest

>> No.68761903

Look out brainlet's.
THE WALL is here.

>> No.68761904

1000x1000 array coming up

>> No.68761910


>> No.68761912

>petertseng beat me by ~10s on both parts

>> No.68761916


>> No.68761918

Wait fuck I can't sleep

>> No.68761924


>> No.68761930
File: 248 KB, 640x312, 1472678192546.png [View same] [iqdb] [saucenao] [google] [report]

sleep time for me

>> No.68761957

I really need to lrn2regex

>> No.68761960
File: 72 KB, 398x294, bocchi shock.png [View same] [iqdb] [saucenao] [google] [report]

>Because you have guessed incorrectly 4 times on this puzzle, please wait 5 minutes before trying again.

>> No.68761966

Doesn't look that bad, he's a jerk for making part of the problem just parsing the input. Unnecessary.

>> No.68761975

rank 219 and 103, no points :(

>> No.68761976

I figured out how to do it, but I don't know how to parse the sting. Can somebody link me to something on how to do regular expressions in python for this case without giving me the answer?

>> No.68761981

Is Peter Tseng God's gift to programming?

>> No.68761983

this just count overlaps in an nxn array

>> No.68761987

Here anon, take this

import re

def do_scrub(scrub, s):
'''Remove characters designated by `scrub` from `s`.'''
# If it starts with '[' then it's probably a regex character class.
# Otherwise, assume it's a normal list of characters.
if scrub.startswith('['):
s = re.sub(scrub, ' ', s)
for c in scrub:
s = s.replace(c, ' ')
return s

def get0(scrub=None):
'''Get the entire input from stdin. Input is scrubbed using
`do_scrub(scrub, _)`.'''
s = sys.stdin.read().strip()
if scrub is not None:
s = do_scrub(scrub, s)
return s

def get1(cvt=str, scrub=None):
'''Get 1-dimensional input from stdin, one entry per line. Each line is
scrubbed, stripped, and converted using `cvt`.'''
xs = []
for line in sys.stdin:
if scrub:
line = do_scrub(scrub, line)
line = line.strip()
if line:
return xs

def get2(cvt=str, scrub=None):
'''Get 2-dimensional input from stdin. `cvt` and `scrub` work as in
xs = []
for line in get1(scrub=scrub):
xs.append([cvt(part) for part in line.split()])
return xs

Then `get2(int, '[^0-9]')` gets you the input as a list of 5-tuples of ints, so you can do `for n, x, y, w, h in claims: ...`. (Specifically, it reads each line of stdin, replaces non-numeric characters with whitespace, strips and splits the line, and converts each substring from the split to an int.)

>> No.68762006

don't over-engineer .just do it manually (i.e. use the "search and replace" of your IDE)

>> No.68762013

Not them, but I'm a fucking idiot for not doing that

>> No.68762019

that 2000x2000 array.

import numpy as np

for x,y,dx,dy in A:


for i in range(len(A)):
if (M[x:x+dx,y:y+dy]==1).all():

>> No.68762020

Well now I have motivation to install Pygame.
I'll see If I can't produce a graphic when this is all said and done.

>> No.68762022

Done with both parts. My solution is shit and just involves stuffing every used cell into a dictionary keyed by its x/y position, but it worked.

Now I'm going to bed.

>> No.68762027
File: 102 KB, 673x888, advent3.png [View same] [iqdb] [saucenao] [google] [report]

Rank 107. I am not proud.
(screenshot is of part 2)

>> No.68762028
File: 347 KB, 500x373, 1538084048224.gif [View same] [iqdb] [saucenao] [google] [report]

>program passes test input
>fails actual input

>> No.68762029

I bet it's an actual picture of something

>> No.68762034

>tfw 250th in total, but 2nd on /g/ leaderboard for this day in getting both stars
it's someting
import re
from collections import defaultdict

pattern = re.compile(r"#(\d+) @ (\d+),(\d+): (\d+)x(\d+)")
areas = defaultdict(list)
for line in open('input.txt').readlines():
i, x, y, w, h = pattern.match(line).groups()
for dx in range(int(x), int(w) + int(x)):
for dy in range(int(y), int(h) + int(y)):
areas[(dx, dy)].append(i)
count = 0
candidates = set()
disabled = set()
for k, v in areas.items():
if len(v) == 1:
count += 1
for c in v:
for d in disabled:
if d in candidates:
print(count) # part 1
print(candidates) # part 2

>> No.68762038
File: 17 KB, 495x477, Capture.png [View same] [iqdb] [saucenao] [google] [report]

-------Part 1-------- -------Part 2--------
Day Time Rank Score Time Rank Score
3 00:07:56 165 0 00:16:26 333 0


Piss poor ranking with piss poor code

>> No.68762046

I have it, I'll do it when done

>> No.68762048

Pretty sure at least one other /g/entooman got global points today (I think we only had 9 people with global points yesterday), who was it?

>> No.68762055
File: 111 KB, 740x533, robertcop.jpg [View same] [iqdb] [saucenao] [google] [report]

Fuck I swapped X with Y

>> No.68762056

I applaud you pythonbros for getting this shit done so quickly. I'm learning Haskell and took damn near the whole 24 hours for yesterday. Hoping to get this one within a few.

>> No.68762058

>more string manip
fuck you

>> No.68762059

>part 2 needs me to swap around my data structures entirely

>> No.68762070

Oh wait, I don't. I'm still an idiot though.

>> No.68762074
File: 8 KB, 614x78, score.png [View same] [iqdb] [saucenao] [google] [report]


>> No.68762078

data class Claim(
val id: Int, val x: Int, val y: Int, val w: Int, val h: Int)

fun part1() {
val parsed = parse(data)

val regex = """^#([0-9]*) @ ([0-9]*),([0-9]*): ([0-9]*)x([0-9]*)${'$'}""".toRegex()
fun parse(lines: List<String> ) : List<Claim> {
return lines.mapNotNull {
regex.matchEntire(it)?.run {
Claim(groupValues[1].toInt(), groupValues[2].toInt(), groupValues[3].toInt(), groupValues[4].toInt(), groupValues[5].toInt())

fun overlappingClaims(claims: List<Claim>) : Int {
val maxX = claims.asSequence().map { it.x + it.w }.max() ?: 0
val maxY = claims.asSequence().map { it.y + it.h }.max() ?: 0
val map = MutableList(maxX) { MutableList<Int?>(maxY) {null}}
val donemap = MutableList(maxX) { MutableList(maxY) {false}}
val nonoverlapping = claims.map { it.id }.toMutableSet()
var overlap = 0

claims.forEach {
for (x in it.x until it.x+it.w) {
for( y in it.y until it.y + it.h) {
val existing = map[x][y]
if(existing != null && !donemap[x][y]) {
donemap[x][y] = true
map[x][y] = it.id

println("Part 2: ${nonoverlapping.first()}")

return overlap

Misread the first part, thought it was asking for how many overlapped. That set me back a bit. Second part was already 99% done by the first so I didn't bother changing the code.

>> No.68762080

>r'#(\d+) @ (\d+),(\d+): (\d)+x(\d+)' instead of r'#(\d+) @ (\d+),(\d+): (\d+)x(\d+)'


>> No.68762081
File: 8 KB, 834x132, 3.png [View same] [iqdb] [saucenao] [google] [report]

pretty ok

>> No.68762084

>11 seconds off
Damn, that's rough

>> No.68762091

Meanwhile I'll go to work and then take my time doing it in Rust.

>> No.68762092
File: 47 KB, 1634x233, day03.png [View same] [iqdb] [saucenao] [google] [report]

Can any Haskellers beat 490?

>> No.68762099

got the first star using ruby :)

>> No.68762105
File: 45 KB, 464x801, aoc18day03.png [View same] [iqdb] [saucenao] [google] [report]

Oh yeah, guess I should post my code

>> No.68762106

I don't get it...
It wants me to draw a rectangle starting at 971 and ending with 29, but the field only is 1000 times 1000, so that can't work...

>> No.68762114

Sure it can, the rectangle run right up to the right border of the field

>> No.68762120

971 + 29 = 1000 bruh

>> No.68762132

How so?
The max index is 999...

Yes, and index 1000 is not available for a 1000 times 1000 matrix...

>> No.68762134

moved up the /g/ leaderboard but horrible stats globally

I went full brainlet today

>> No.68762139

yeah anon that's indeed r"#\d @ (\d+),(\d+): (\d+)x(\d+)"

>> No.68762158
File: 13 KB, 581x117, score.png [View same] [iqdb] [saucenao] [google] [report]

fuck iostreams, next time im using scanf from the start.

are you sure you have the numbers matched properly. my input has
#127 @ 971,620: 21x29
971 is paired with 21, not 29

its 0 index though

>> No.68762159

-------Part 1-------- -------Part 2--------
Day Time Rank Score Time Rank Score
3 00:17:40 784 0 00:25:20 773 0

Not my proudest, but I'll start on a visualization now. Will only take a couple mins.

>> No.68762160
File: 239 KB, 1069x829, やった.jpg [View same] [iqdb] [saucenao] [google] [report]

>Went from rank 11 to rank 8 in private leaderboard
Feels good man

>> No.68762164
File: 27 KB, 586x578, infinite_brainlet.png [View same] [iqdb] [saucenao] [google] [report]

>You got rank 840
Why do I even bother?

>> No.68762165

Suppose you got x = 995 and w = 5. Then your five indices are 995, 996, 997, 998, 999. No overflow.

>> No.68762167


>> No.68762170

Also this day's challenge reminded me that my Rectangle Packing algorithm stopped working. So that sucks. I guess I should fix that at some point.

>> No.68762177

p.s. here's my code fuck efficiency lmao
def p1(data):
d = defaultdict(int)
for rect in data:
offset_x, offset_y, width, height = rect[0], rect[1], rect[2], rect[3]
for x in islice(count(offset_x), width):
for y in islice(count(offset_y), height):
d[(x, y)] = d[(x, y)] + 1
return sum(k > 1 for k in d.values())

def found(rect, d):
offset_x, offset_y, width, height = rect[0], rect[1], rect[2], rect[3]
for x in islice(count(offset_x), width):
for y in islice(count(offset_y), height):
if len(d[(x, y)]) > 1:
return False
return True

def p2(data):
d = defaultdict(list)
for rect in data:
offset_x, offset_y, width, height = rect[0], rect[1], rect[2], rect[3]
for x in islice(count(offset_x), width):
for y in islice(count(offset_y), height):
d[(x, y)].append(rect)
c = []
for i, rect in enumerate(data):
if found(rect, d): return c+1

>> No.68762181
File: 20 KB, 585x397, ao3.png [View same] [iqdb] [saucenao] [google] [report]

what a mess
i should have done rectangle stuff while i could

>> No.68762186

>moved up 5 spaces to 14
Feels fucking great. Would be better it I wasn't already at 8 up until yesterday's idiocy on my part.

>> No.68762188

that goose or is it the leaderboard that's already fucking full

>> No.68762194

>wasted a shitload of time because i was doing > instead of >=
fucking epic

>> No.68762199

Yeah, right, I am retarded.
I couldn't to the conversion from his arrays to a good data format, where indices start from the correct point, 1.

>> No.68762206
File: 204 KB, 502x374, bocchi tough place.png [View same] [iqdb] [saucenao] [google] [report]

Brainlet filter in action
-------Part 1-------- -------Part 2--------
Day Time Rank Score Time Rank Score
3 00:16:48 730 0 00:27:34 851 0
2 00:04:00 150 0 00:09:10 149 0
1 00:00:42 11 90 00:04:04 42 59

>> No.68762208
File: 11 KB, 249x189, 1539847316201.jpg [View same] [iqdb] [saucenao] [google] [report]

~150 on the first star, but ~650 on the second. Took me like 10 minutes to realize I could use almost the exact same algo I used on the first half.

>> No.68762209

I did the first day 8 hours too late. I don't think I'll ever recover from that.

>> No.68762213
File: 65 KB, 960x638, 1535047826634.jpg [View same] [iqdb] [saucenao] [google] [report]

I was praying to god part 2 wasn't
>Find the largest subset of fabric patches that can be cut out without overlap
I was sure that this was the brainlet filter

>> No.68762215
File: 5 KB, 655x71, firefox_2018-12-02_23-32-01.png [View same] [iqdb] [saucenao] [google] [report]

>> No.68762220

refactored version (which is actually a bit slower, probably because of the set differences lol
def fabric(part2=False):
pattern = re.compile(r"#(\d+) @ (\d+),(\d+): (\d+)x(\d+)")
all_ids, coords = set(), defaultdict(set)
for line in open('input.txt').readlines():
claim_id, x0, y0, width, height = map(int, pattern.match(line).groups())
for x in range(x0, x0 + width):
for y in range(y0, y0 + height):
coords[(x, y)].add(claim_id)

overlapping = 0
for claim_ids in coords.values():
if len(claim_ids) > 1:
overlapping += 1
all_ids -= claim_ids

return all_ids.pop() if part2 else overlapping

>> No.68762225

Most of the part twos, or at least the earlier, simpler puzzles, you can reuse most of your part one.

>> No.68762228

>finished part 1
>see part 2


>> No.68762234
File: 24 KB, 500x375, d5b.jpg [View same] [iqdb] [saucenao] [google] [report]

>wasted a minute because of an off-by-one error

>> No.68762235

that was lefthanded

>> No.68762244

this has to be generated

>> No.68762245


did you fucking regex replace the data set you madman

>> No.68762247
File: 29 KB, 600x597, figure_1.png [View same] [iqdb] [saucenao] [google] [report]

arg = get_input(1)
L = [[0 for i in range(1000)] for j in range(1000)]
for line in arg:
l = line.split(" ")
ll = l[2].split(",")
x = int(ll[0])
y = int(ll[1][:-1])
ll = l[-1].split("x")
XX = int(ll[0])
YY = int(ll[1])
for i in range(XX):
for j in range(YY):
L[x + i][y + j] += 1


>> No.68762250
File: 16 KB, 1000x1000, visual.png [View same] [iqdb] [saucenao] [google] [report]

lacking a bit of color

>> No.68762253

Kotlin meme solution
fun main(args: Array<String>) {
val claims = MutableList(1000) { MutableList(1000) { mutableSetOf<Int>() } }
val unmolested = MutableList(input.size) { true }
input.forEachIndexed { i, it ->
val tokens = it.split(' ')
val (left, top) = tokens[2].removeSuffix(":").split(',').map{ it.toInt() }
val (width, height) = tokens[3].split('x').map{ it.toInt() }
for(y in top..top+height-1) {
for(x in left..left+width-1) {
if(claims[y][x].size > 1) {
claims[y][x].forEach{ unmolested[it] = false }
println(claims.flatten().filter{ it.size > 1 }.count())
unmolested.forEachIndexed { index, b -> if(b) println(index+1) }

Won't run on Try Kotlin because too much memory needed

>> No.68762254

>Took me like 10 minutes to realize I could use almost the exact same algo I used on the first half.
Oh. Huh. I should have thought of that.

>> No.68762264

>Wasted like 10 minutes figuring out what I needed to import to use regex and capture groups in Python
Rip rank

>> No.68762269

Good stuff. Make the non-overlapped one red so I can find it.

>> No.68762270
File: 27 KB, 708x563, d3.png [View same] [iqdb] [saucenao] [google] [report]

4channel keeps giving me a """"Connection error."""" when I try to use code blocks, so here: https://ghostbin.com/paste/berd9

>> No.68762271

just a quick vim macro

>> No.68762272
File: 56 KB, 328x307, 1415266457551.jpg [View same] [iqdb] [saucenao] [google] [report]


not proud of it tho

real 0m2.990s
user 0m2.746s
sys 0m0.236s

>> No.68762275
File: 6 KB, 250x249, 1513643321885.jpg [View same] [iqdb] [saucenao] [google] [report]


>> No.68762277

So much empty space and yet there was only one contract that didn't overlap? These elves are fucking with us.

>> No.68762284
File: 47 KB, 719x133, buttplug.png [View same] [iqdb] [saucenao] [google] [report]

i wonder if this guy came?

>> No.68762286

I just did a ctrl + replace and eliminated all of the shit that wasn't the numbers, tokenizing on whitespace.
input = '''
952 280 19 26
425 57 26 14
data = []
for i in input:
data.append([int(j) for j in i.split() if j])

>> No.68762293
File: 19 KB, 1000x1000, asdf.png [View same] [iqdb] [saucenao] [google] [report]

Yeah, nothing to see.

>> No.68762296
File: 92 KB, 500x667, time to die.jpg [View same] [iqdb] [saucenao] [google] [report]

>counter gets down to 0
>gateway decides to stop emitting wifi at that exact moment

>> No.68762303

That wouldn't be that hard actually, since you already have a reference to all of the patches, you could just make a recursive check for "get me the size of my patch and anything touching my patch" and check every single patch. You'd be recounting the same things over and over, but there's only a ~1400 inputs so you'd only be running it 1400 times.

This is assuming your solution involved putting everything into a map that you could check through.

>> No.68762306

why are you guys arguing about array dimensions when you could have just used a dictionary on a tuple count pair and not given a shit?

>> No.68762307

I did it, lads. Honestly ugly solution written in perl takes 170ms for both parts. I'm curious to read clever solutions by smart anons later. I'm going to sleep now.

>> No.68762314

Sadly I'm a file read virgin instead of a copy past chad

>> No.68762315
File: 8 KB, 590x81, Screenshot_2018-12-03_06-40-19.png [View same] [iqdb] [saucenao] [google] [report]


I made so many bullshit mistake FUCK

>> No.68762321

Even more perfect timing with FUCKposting.

>> No.68762327
File: 17 KB, 1307x560, MATLAB.png [View same] [iqdb] [saucenao] [google] [report]

Here is my MATLAB code, would have been ALOT faster if I wasn't retarded, thankfully part 2 was extremely easy.

>> No.68762337

That part at least I got right. I had written a code snippet while I was waiting beforehand that extracted every number from each line and put it in a list. It was kinda dumb because I couldn't figure out if I wanted separate functions or parameters to choose how to split:
import re

def extract_nums(string):
return [int(x) for x in re.findall(r"(-?\d+\.?\d*)", string)]
def open_lines(filename, split_nums = False, split_char = None):
lines = open(filename).read().strip().splitlines()
if split_nums:
lines = [extract_nums(x) for x in lines]
elif split_char is not None:
lines = [x.split(split_char) for x in lines]
if len(lines) == 1:
return lines[0]
return lines
def open_split(filename, split_char):
return open_lines(filename, False, split_char)
def open_nums(filename):
return open_lines(filename, True)

>> No.68762338

>tfw you're not a brainlet

>> No.68762343
File: 185 KB, 720x540, 1538826548196.jpg [View same] [iqdb] [saucenao] [google] [report]

-------Part 1-------- -------Part 2--------
Day Time Rank Score Time Rank Score
3 00:12:21 434 0 00:20:54 551 0

i blame my keyboard

>> No.68762347

Can't into regex in Python.

Part 2:
fp = open("../inputs/day3.txt", "r")
inputs = fp.readlines()

import numpy as np

fabric = np.asmatrix(np.array([[0 for _ in range(1000)] for _ in range(1000)]))

for ip in inputs:
id, _, gap, dim = ip.split()
id = id[1:]
gap_h = int(gap.split(',')[0])
gap_w = int(gap.split(',')[1][:-1])
dim_h = int(dim.split('x')[0])
dim_w = int(dim.split('x')[1])

for i in range(gap_h, gap_h+dim_h):
for j in range(gap_w, gap_w+dim_w):
fabric[i, j] += 1

for ip in inputs:
id, _, gap, dim = ip.split()
id = id[1:]
gap_h = int(gap.split(',')[0])
gap_w = int(gap.split(',')[1][:-1])
dim_h = int(dim.split('x')[0])
dim_w = int(dim.split('x')[1])

for i in range(gap_h, gap_h+dim_h):
for j in range(gap_w, gap_w+dim_w):
if fabric[i, j] == 1:
of = 0
of = 1
if of == 1:

if of == 0:

>> No.68762350

>He doesn't use a language with a built in function to import formatted text

>> No.68762352
File: 25 KB, 1000x1000, wheres_waldo.png [View same] [iqdb] [saucenao] [google] [report]

found him!

>> No.68762357

wtf guys you don't even need regex

>> No.68762363

RE_CLAIM = re.compile(r'#(\d+)\[email protected]+),(\d+):\s(\d+)x(\d+)')

>> No.68762366
File: 29 KB, 699x699, greenlink.jpg [View same] [iqdb] [saucenao] [google] [report]

i was going to upload my answers to github, but i've already resorted to using "poop", "pee", and "boobs" for variable names, so i guess not

>> No.68762367

[email protected] /m/D/t/s/0/2/03> time -p python3 ./prog.py
real 0.96
user 0.92
sys 0.03


grid = [[0 for _ in range(1000)] for _ in range(1000)]
claims = [[[] for _ in range(1000)] for _ in range(1000)]

text = [x.strip().split('@')[1][1:].split(': ') for x in open('input.txt').readlines()]

def draw(k,d):
t = 0
x,y = map(int, d[0].split(','))
w,h = map(int, d[1].split('x'))
for j in range(y,y+h):
for i in range(x,x+w):
grid[j][i] += 1
if grid[j][i] == 2:
return t

t = 0
for k,l in enumerate(text):
t += draw(k+1,l)

def check(d):
x,y = map(int, d[0].split(','))
w,h = map(int, d[1].split('x'))
for j in range(y,y+h):
for i in range(x,x+w):
if len(claims[j][i]) > 1:
return False
return True

for l in text:
if check(l):

I spent like 5 minutes searching for to make ranges because I hardly ever use python.

>> No.68762370

>>68762347 (me)

>had to figure out how to create a matrix
>took 5 minutes to realize matrices aren't indexed as [j]

>> No.68762374
File: 23 KB, 392x591, AoCd32018.png [View same] [iqdb] [saucenao] [google] [report]

Still took less time that all the damned time I wasted on day 2.

>> No.68762378

>this private leaderboard is full

>> No.68762381
File: 217 KB, 439x466, bocchi cry.png [View same] [iqdb] [saucenao] [google] [report]

>17 to 48 to 71 on global leaderboard

Well, I guess three days on the global leaderboard isn't too bad, right?

>> No.68762383

4chan formatting seems to remove some backslashes

>> No.68762385

You don't use regex because you need regex you use regex because regex is piss-easy to use as a quick ad hoc solution.

Regex is like duck tape. Just stick this part onto that part and you're good to go.

>> No.68762390

why this no work p1
fabric = set()
answer = 0

for line in open(filename):
form = line.strip().split(' ')
coords = form[2].rstrip(':').split(',')
size = form[3].split('x')

for x in range(1, 1 + int(size[0])):
for y in range(1, 1 + int(size[1])):

newvalue = (int(coords[0]) + x, int(coords[1]) + y)

if newvalue in fabric:
answer += 1

print('part1:', answer)

>> No.68762396

It's okay anon, we're going to be better next time, r-right?

>> No.68762401

This code makes me want to kill myself. Part 2:
data = open("Day 03 input.txt", "r").read().split("\n") #any line-split data
temp = []
for i in data:
a = i.find("@")
c = i.find(",")
d = i.find(":")
x = i.find("x")
temp.append([int(i[a+2:c]), int(i[c+1:d]), int(i[d+2:x]), int(i[x+1:]), int(i[1:a])])
data = temp

grid = []
for i in range(1000):
for j in range(1000):

for rect in data:
for y in range(rect[3]):
for x in range(rect[2]):
grid[y+rect[1]][x+rect[0]] += 1

for rect in data:
fail = False
for y in range(rect[3]):
for x in range(rect[2]):
if grid[y+rect[1]][x+rect[0]] != 1: fail = True
if not fail: raw_input(rect[4])

>> No.68762403

I'm just going to go ahead and assume you're double-counting spaces where more than two contracts overlap.

>> No.68762412
File: 90 KB, 660x714, junior.png [View same] [iqdb] [saucenao] [google] [report]

brainlet here, how do you use regex to solve this? in plain english pls

>> No.68762421

[[0 for x in range(1000)] for x in range(1000)]]

>> No.68762423

its used to parse the input

>> No.68762428

That was fun

>> No.68762429

It's just the parsing
regex = re.compile("^#(\d+) @ (\d+),(\d+): (\d+)x(\d+)$")
match = regex.match(inputString)
self.id = int(match.group(1))
self.x = int(match.group(2))
self.y = int(match.group(3))
self.width = int(match.group(4))
self.height = int(match.group(5))

>> No.68762434

reasonable efficiency is for pussies
>mfw lucky as fuck this even worked
>if my answer was too high I would have just gotten a RecursionError

>> No.68762437

Or if you don't use a retarded language:

>> No.68762440
File: 16 KB, 240x240, 1402446639003.jpg [View same] [iqdb] [saucenao] [google] [report]


>> No.68762443

Just use split man

>> No.68762445

ah that makes sense. i was wondering what kind of fucking wizardry people were using for the rest of it using regex

>> No.68762453

how many years will it take me to be like you man I can only do Day1 in C++

>> No.68762456

How would some function likePatch => Patch[] solve the maximal subset problem?

>> No.68762459

>how do you use regex to solve this?
You don't.
I don't even know what a regex is, I just told my program to read the formatted Textfile like a normal human being.

>> No.68762461

my php code lol

>> No.68762464

Oh, you do that too when you get frustrated?

>> No.68762475

forgot code but 4chan is being retarded so i can't post it for some reason so here's this: https://pastebin.com/3cn2qWQZ

>> No.68762479

why am i retarded? 3/3 i misread and spend 30 min fucked

>> No.68762481

Goddamnit, my rank dropped post-solving as well. RIP my top 15 place, stuck at 16.

>> No.68762507
File: 47 KB, 651x738, A18046F980D84420A6256331752DC8BB.jpg [View same] [iqdb] [saucenao] [google] [report]


>> No.68762509

>1 to 2 to 4
It hurts

>> No.68762526

Maybe a year if you apply yourself.
Tbh the skills that take time in software development are about architecture, readibility, documentation, comunication, management, etc. Coding is just practicing for a while and reading some books. The hard part is knowing what to learn, but that's what these kind of challenges are useful for.

>> No.68762530

>tfw steadily rose in the leaderboards for the last couple of days
The harder it gets, the faster I go, at least for now.

>> No.68762533

>fug = {}
>ids = []
>things = []

>> No.68762535
File: 258 KB, 2492x3000, 1535398188603.png [View same] [iqdb] [saucenao] [google] [report]

>slid from 15 to 18
>only been programming seriously for about 6 months
>using python which I neither know nor enjoy
The only other time I feel this sub-standard is around my parents

>> No.68762539

Who's making the visualisations for the leaderboards? Just a very basic graph would be cool.

>> No.68762540

Here's my day 2 after cleanup. Disgusting.

import re
with open("input") as f:
input = f.readlines()

patch = list()
for line in input:
num = re.split(',|:|@|x', line.replace('#',''))
patch.append([int(n) for n in num])

fabric = [[0 for _ in range(1000)] for _ in range(1000)]
for p in patch:
for x in range(p[1], p[1]+p[3]):
for y in range(p[2], p[2]+p[4]):
fabric[x][y] += p[0]
for p in patch:
fail = False
for x in range(p[1], p[1]+p[3]):
for y in range(p[2], p[2]+p[4]):
if fabric[x][y] != p[0]:
fail = True
if not fail:

>> No.68762545
File: 16 KB, 1514x136, Capture.png [View same] [iqdb] [saucenao] [google] [report]

It's another one of those days again.
Throwback to the old calendar

>> No.68762546

aaaaaaaahhhhhhhhh part 2

i cleansed my input lol

>> No.68762550

Fucking grid shit. Every goddamn year.

>> No.68762551

funny thing is ids and things contains the exact same thing, and ids doesn't actually contain IDs. I forgot it was there so I added things.

>> No.68762569
File: 13 KB, 583x138, Screenshot_20181203_155143.png [View same] [iqdb] [saucenao] [google] [report]

I had a delivery from FedEx during the first part.

>> No.68762570

I have PTSD from the knothashes of 2017

>> No.68762581

Literally the best part of it, the only good data structure is a matrix.

>> No.68762583

second that. especially since it doesn't seem to be possible to view scores of previous days of private leaderboards.

>> No.68762590
File: 45 KB, 960x720, 1532132927414.jpg [View same] [iqdb] [saucenao] [google] [report]

>mfw we haven't even hit the non-euclidean geometry brainlet filter grid problem yet

>> No.68762591

Amusingly enough, that's the exact puzzle I thought of on seeing the grid diagrams here.

>> No.68762594
File: 38 KB, 1015x201, Screenshot from 2018-12-03 07-00-17.png [View same] [iqdb] [saucenao] [google] [report]

rewritten part one

>> No.68762595

LMAO if you think today is a brainlet filter then there is truly no point in even trying.

The problem is incredibly trivial. If you put this in a dense matrix you are truly braindead.

Very very easy to solve with sparse data structure.

>> No.68762597

Honestly this year is a hell of a lot easier than last year

>> No.68762605
File: 85 KB, 680x680, 1518940362715.jpg [View same] [iqdb] [saucenao] [google] [report]

Don't remind me

>> No.68762607
File: 1.51 MB, 3282x2475, 1543668392691[1].png [View same] [iqdb] [saucenao] [google] [report]

Those made for some of the best days on the calendar though

>> No.68762613

not frustrated so much as just trying to do shit as quickly as possible

>> No.68762616

>If you put this in a dense matrix you are truly braindead.
In non brainlet languages, sparse and dense matrices can be swapped in a few seconds, so that really doesn't matter.

>Very very easy to solve with sparse data structure.
Just as easy with a dense.

>> No.68762618

hey if it works, it works. And if it was intended, the task could easily have been modified to prevent such "braindead" solutions.

>> No.68762623

It definitely is as of now, can't really compare day 3 to day 21. FUCKposting has just gotten memed to all hell now.

>> No.68762625

>CPU times: user 563 ms, sys: 0 ns, total: 563 ms
>Wall time: 562 ms
Python. Reasonably fast considering I have no idea how to program

>> No.68762632

>Very very easy to solve with sparse data structure
Explain how if you're so great

>> No.68762638

Been going back and doing 2017 for practice and just did that one last week. Did first half fine. Kept fucking around and getting it wrong on the second haff; finally turned out I had just been slicing my hashes into groups of 15 not 16 on my reduction stage. argh.

>> No.68762640

> Coding problem 1
> run finished code
> Input number
> its wrong
> change the code a bit.
> number is slightly different
> its wrong
> turns out the number is actually changing every time i run it without changing any code.

What the fuck C++?

>> No.68762646

>turns out the number is actually changing every time i run it without changing any code.
Uninitialized variable?

>> No.68762651
File: 316 KB, 932x2422, aoc.png [View same] [iqdb] [saucenao] [google] [report]

This is the alt leaderboard, pls post legit leaderboard so us plebs can see the scores of the AoC elite.

>> No.68762670

The exact same way only with a SparseRectangularArray type of data structure instead of a Vector of Vectors that will delegate getContents(x,y) to region logic rather than backing arrays. Which, if you happen to have one lying around, great, but it is completely and utterly irrelevant to the particular responsibility of this task's code and definitely not something you're going to make if you're competing for time.

Ignore the butthurt guy, he's just trying to get attention.

>> No.68762687
File: 709 KB, 1928x4935, lsdklsdkjflsdkfjsf.png [View same] [iqdb] [saucenao] [google] [report]

>taskbar in the middle

>> No.68762688
File: 716 KB, 707x5247, g's private leaderboard day 3.png [View same] [iqdb] [saucenao] [google] [report]


>> No.68762691

I'm not that sperg but the easiest sparse dataset you can make is
def compute_rects(data):
d = defaultdict(list)
for rect in data:
i, x_dimensions, y_dimensions = rect
for x in range(*x_dimensions):
for y in range(*y_dimensions):
d[(x, y)].append(i)
return d

>> No.68762695
File: 16 KB, 577x120, file.png [View same] [iqdb] [saucenao] [google] [report]

>everyday i do worse and worse

>> No.68762698
File: 118 KB, 1015x494, aoc3.png [View same] [iqdb] [saucenao] [google] [report]

Shortened part 1 and part 2 solution
These are the times

>> No.68762702

>can't actually see times of competitors
>can't see ranks on a per-day basis
Well this is completely useless.

>> No.68762709

I am a screenlet, had to stretch the browser across two monitors.

>> No.68762711
File: 36 KB, 655x527, glasses paper helper.jpg [View same] [iqdb] [saucenao] [google] [report]

I'm still doing good somewhere it seems

>> No.68762713

Am I done for? I didn't initialize my tensor properly to 1001x1001 and to makes matters worse, It's taking forever to run.

>> No.68762714

Initialize your variable

>> No.68762716


Or the firefox equivalent in your case.

>> No.68762717

The what?

Oh, so just use a dictionary for each (x,y) ? Yeah I guess that works

>> No.68762719

Well I guess it's "sparse" in that the negative space is sparse, but considering (a) what percentage of space is filled, (b) the fact that the dictionary will be full of references/pointers whereas the arrays aren't, and (c) the fact that this will have extra memory for the overlap, this would actually take up more memory than a 1000x1000 array.

>> No.68762722

>I didn't initialize my tensor properly to 1001x1001
It's of 1000x1000 m8.

>> No.68762724

Just use a defaultdict

>> No.68762725

So... codeshare for chat, code, and shitposting?

>> No.68762732

Not him but firefox has a native screencapping utility.

>> No.68762737

Sorry, gotta go to work in 10 minutes

>> No.68762739

I thought the scores were global, are they relative to whichever private leaderboard you're in?

>> No.68762740

>The what?
A class which doesn't yet exist but whose name implies how it would work.

Basically you have
class SparseRectangularArray<T>{
fun putThingInArray( thing: T, area: Rectangle);
fun checkWhatThingIsInArrayAtPoint(x: Int, y: Int) : Set<T>

>> No.68762760

Your times are the same, but the score is relative to the leaderboard.

>> No.68762768

Pajeets talk in interfaces, we're here for implementation.
What the fuck is it?
Are you using a bounded volume hierarchy like they do in video games?

>> No.68762770

tfw O(N2) algorithm, only take 100ms to complete both parts tho

>> No.68762771

What's defaultdict?

Also WTF PySHIT is this?
t = [[-1]*5]*5
t[0][0] = 0

the result is
[[-1, -1, -1, -1, -1], [-1, -1, -1, -1, -1], [-1, -1, -1, -1, -1], [-1, -1, -1, -1, -1], [-1, -1, -1, -1, -1]]
[[0, -1, -1, -1, -1], [0, -1, -1, -1, -1], [0, -1, -1, -1, -1], [0, -1, -1, -1, -1], [0, -1, -1, -1, -1]]

>> No.68762774

>mfw I skipped the 1000x1000 line
I just took the max x and max y

>> No.68762778

In Python, you can multiply a list to cycle that list N times.

>> No.68762782


>> No.68762787

Welcome to python

>> No.68762792

It's just an operator with syntactics sugar to itertools.chain(). Don't think too hard about it.

>> No.68762793

>Pajeets talk in interfaces, we're here for implementation.
If you can't implement this thing in a number of different ways based on the implementation then you may not be a Pajeet, but what you are is unemployable.

Yes, you could implement it with a hierarchical space. You could implement it a hundred ways.

>> No.68762802

2D list in python is fucking me up. This piece of shit language is unbearable. Spent the last 30 minutes wrestling with python instead of solving the problem.

>> No.68762803


>> No.68762810

Yeah, my problem is why is there five 0s in the second matrix? Shouldn't there only be one 0 at index (0,0).

>> No.68762811

Not me. I made the mistake of trying to use Array instead of Map. Never again.

>> No.68762812

t=[-1]*5 fills t with 5 reference to the same object

>> No.68762814

So you're here to sound pompous while saying nothing of value.
You could just say that instead of trying to put on airs, we're all anonymous here.

>> No.68762815

this was a lot easier than last year's spirals

>> No.68762823

>Data structure
>A class with these methods!
I was hoping you would actually explain a data structure

>> No.68762824

Define an algebra which encodes the rules of overlapping fabric, so e/f/o.

f + e = f
o + e = o
o + o = o
f + f = o

You then create a map like data structure which takes an index to a value e/f/o and then adjust the contents as you read in the input.

You just keep track of the number of o's as you parse the input.

>> No.68762825
File: 15 KB, 276x252, day3.png [View same] [iqdb] [saucenao] [google] [report]

looks funky

>> No.68762830

more like you're a fucking brainlet lmao >>68762691

>> No.68762833

I guess I knew what was happening. I'm just a little annoyed that it works that way.

>> No.68762835

is day 3 the great brainlet filter?

>> No.68762840

That is why you use list comprehension

>> No.68762843

Nah, this is fairly easy.

>> No.68762850

>capture groups
Just regex-replace all nondigits with space, and split on whitespace like normal. Way easier than writing down a regex that exactly matches this stupid input format.

>> No.68762853

No, this shit is super easy.

>> No.68762855

Yeah, you're calling people Pajeets, smashing "OOP BAD" in the keyboard, and referencing irrelevant niche industry-specific data structures in a discussion about sparse data sets, but I'M the one who's here to start shit, try and signal shit, and not actually say anything. Go back to your cave and don't bother replying the channel's not open.

>> No.68762864

lmao good job extrapolating all that shit from "pajeet"
sure got rump roused over one word

>> No.68762871


>> No.68762874

Took me like 30 seconds to write the regex with captures. Git gud.

>> No.68762876

Where is today pic? Get drawing you faggits

>> No.68762879

this question is a matlab cucks wet dream

>> No.68762880

In python range(a,b) returns indexes [a,b). I didn't offset the start, a by -1.

Anyone mind explaining what defaultdict is? From documentation it looks like it's a dictionary grouping.

>> No.68762885
File: 21 KB, 236x299, d4ebd70ed806923e7db401802a8c1498--my-grandmother-grandmothers[1].jpg [View same] [iqdb] [saucenao] [google] [report]

Maybe today's image could have a shitty quilt on it.

>> No.68762890
File: 1.03 MB, 845x794, aoc3.png [View same] [iqdb] [saucenao] [google] [report]

lazy ms paint calendar candidate

>> No.68762893

>complex numbers
the fuck? What does python even use this for?

>> No.68762898

int problem1(vector<string> inputList){

int coordMap[1000][1000];
for(string item: inputList){
int posFirstCoord;
int posSecCoord;
int posThirdCoord;
int posFourthCoord;

posFirstCoord =item.find("@");
posSecCoord =item.find(",");
posThirdCoord =item.find(":");

string firstCoord;
string secCoord;
string thirdCoord;
string fourthCoord;

int firstCoordInt;
int secCoordInt;
int thirdCoordInt;
int fourthCoordInt;

for(int i = posFirstCoord+1; i<=posSecCoord; i++){
for(int i = posSecCoord+1; i<=posThirdCoord; i++){
for(int i = posThirdCoord+1; i<=posFourthCoord; i++){
for(int i = posFourthCoord+1; i<item.size(); i++){
firstCoordInt = stoi(firstCoord);

cout << firstCoordInt << ":" << secCoordInt << "," << thirdCoordInt << "x" << fourthCoordInt << endl;

for(int i = firstCoordInt; i < firstCoordInt + thirdCoordInt; i++){
for(int j = secCoordInt; j < secCoordInt + fourthCoordInt; j++){

int inchTally = 0;
for (int i = 0; i<1000; i++){
for (int j=0; j<1000; j++){
return inchTally;


>> No.68762899

Maybe a PTSD image with last year's day 3 in the background.

>> No.68762903

What's the advantage of using complex numbers instead of plain pairs?

>> No.68762905

defaultdict is just a dict where every key has a default value determined by the function passed into its constructor.
So defaultdict(int) will call the default constructor of int, resulting in an initial value of 0 for all keys.
guaranteed no errors.

>> No.68762910


>> No.68762913

Easier to rotate quarter turns by multiplying by positive or negative 1j

>> No.68762916

scanf is superior
scanf("#%d @ %d,%d: %dx%d", &o.n, &o.x, &o.y, &o.w, &o.h);

>> No.68762928

I was looking for this in python but decided doing a ctrl + replace was faster than google

>> No.68762930

aaaand... why are we rotating quarter turns in this question?

>> No.68762933

>bump limit already

>> No.68762943

What are your parsing times? Or are you just parting as you go?

>> No.68762949

Well if you want me to explain it (and not be an asshat about it like the other guy), I can. But I was honestly really hoping you would think it out for yourself. That's why I typed very explicitly each function what they would do.

data class Rect(val x: Int, val y: Int, val w: Int, val h: Int) {
fun contains(x2: Int, y2: Int) : Boolean{
return if (w <= 0 || w <= 0) false else !(x2 < x || y2 < y || x2 > x + w || y2 > y + h)

class SparseRect<T> {
val spaces = mutableListOf<Pair<T,Rect>>()

fun add( t: T, rect: Rect) {
spaces.add(Pair(t, rect))

fun get( x: Int, y: Int) : Set<T> {
return spaces.asSequence()
.filter { it.second.contains(x,y) }
.map { it.first }

Now obviously this is not a very efficient example as the Rectangles are not hashed to a region in any particular way, but the point is to demonstrate that the interface between your code and whatever underlying data structure you use is pretty much the same whether it's being backed by a sparse collection of more abstract things defining the space or it's being backed by a dense array, the algorithm we're writing today would pretty much look the same.

>> No.68762952

Eric is too much of a glycine-prepubescent-male to put the brainlet filter on a monday.

>> No.68762966

Welp, here's my gross solution. Runs in 15 ms though.

mod util;
use util::foreach_line;
use std::fs::File;

struct Fabric {
inches: [[u16; 1000]; 1000],

struct Claim {
x: usize,
y: usize,
w: usize,
h: usize,

impl Claim {
fn new(line: &str) -> Claim {
let mut iter = line.split(|c| !char::is_digit(c, 10)).skip(4);

let x : usize = iter.next().unwrap().parse::<usize>().unwrap();
let y : usize = iter.next().unwrap().parse::<usize>().unwrap();
let _ = iter.next();
let w : usize = iter.next().unwrap().parse::<usize>().unwrap();
let h : usize = iter.next().unwrap().parse::<usize>().unwrap();

Claim { x: x, y: y, w: w, h: h }

impl Fabric {
fn new() -> Fabric {
Fabric { inches: [[0u16; 1000]; 1000] }

fn accept_claim(&mut self, c: &Claim) {
let (xs, xe, ys, ye) = (c.x, c.x+c.w, c.y, c.y+c.h);
for outer in self.inches[xs..xe].iter_mut() {
for inner in outer[ys..ye].iter_mut() {
*inner += 1;

fn count_overlaps(&self) -> usize {
self.inches.iter().fold(0usize, |acc, ary| {
acc + ary.iter().filter(|c| *c > &1).count()

fn overlapping_claim(&self, c: &Claim) -> bool {
let (xs, xe, ys, ye) = (c.x, c.x+c.w, c.y, c.y+c.h);
self.inches[xs..xe].iter().any(|ary| {
ary[ys..ye].iter().any(|inch| *inch > 1)

fn main() {
let file = File::open("inputs/3.txt").unwrap();
let mut fabric = Fabric::new();
let mut claims = Vec::<Claim>::new();

foreach_line(&file, |s: &String| {
let claim = Claim::new(s.as_str());

println!("{}", fabric.count_overlaps());
for (id, claim) in claims.iter().enumerate() {
if !fabric.overlapping_claim(claim) {
println!("ID: {}", id+1);

The foreach_line thing is something I wrote the other day to iterate over a file with a single buffer.

>> No.68762972

Not in this question, but it has been useful in the past.

>> No.68762981


>> No.68762986

Use numpy, it's not MATLAB levels of Matrix awesomeness, but as good as it gets with python.

>> No.68762992
File: 96 KB, 234x233, getouttamyoffice.png [View same] [iqdb] [saucenao] [google] [report]

>everyone posting their long ass solution that nobody will read

nice thread

>> No.68762994

Anonymous user #390161 here. As of now, I was ranked #28.
I was 1 hour late in the first day and 5 minutes late today.
I live in Asia and the time when a new problem unlocks is 1 PM.
And I'm not a NEET so I won't be able to defeat you NEET autists.

>> No.68762998

I wrote mine beforehand. It just captures all the numbers on the line, converts them to ints and throws them in a list. Works the same in practice but less fiddly. Probably handles negatives correctly too.

>> No.68763002

I somehow managed to make this *exact same* typo and spent 15 of 25 minutes trying to figure out why it was fucked up.

>> No.68763004


>> No.68763007

see >>687602019
with numpy this is a breeze

>> No.68763008
File: 10 KB, 580x76, day3.png [View same] [iqdb] [saucenao] [google] [report]

>beefed it on part two
>rewrote it twice
>still gained a rank


>> No.68763017

So your sparse data structure is a list of coordinates that you have to traverse to find a pair. Awful.
We all know about abstraction, it's not relevant for these challenges.

>> No.68763035

the worst part is that it's just an abstraction over doing the two for loops we would have had to write anyway.

>> No.68763045

>he bothered with regex


def get_data(line):
split = line.split()
newDict = {}
newDict["id"] = int(split[0][1:])
newDict["x"] = int(split[2].split(',')[0])
newDict["y"] = int(split[2].split(',')[1][:-1])
newDict["width"] = int(split[3].split('x')[0]) - 1
newDict["height"] = int(split[3].split('x')[1]) - 1
return newDict

>> No.68763046
File: 41 KB, 800x450, fuckmylife.jpg [View same] [iqdb] [saucenao] [google] [report]

Turns out the array referenced things bigger than a thousand. Not much though. Thats what was causing the problem. I just added 100 to both the width and height and it worked.

>> No.68763052

that's what you get for using a fixed-sized data structure on a problem that specifically mentioned that the dimensions of the fabric were AT LEAST 1000.

>> No.68763055

seriously, parsing the input is baby-tier with split, not sure why everyone is suddenly googling "how to regex" for something that's so straightforward

>> No.68763056

this is by far the worst thing i've written, I was fully aware of it being rushed garbage and i was considering not posting this but i got top 600 with this piece of shit https://pastebin.com/26FBea3L

i'll go rewrite this from scratch now

>> No.68763063
File: 5 KB, 641x33, Screenshot_2018-12-03_07-43-54.png [View same] [iqdb] [saucenao] [google] [report]

look at this, that's how I have to do it in C++
I even had to define my own hash function for a pair of int
next year I'm using python

>> No.68763066

virgin regex chad split, that's the image today

>> No.68763069

You can make a list of lists, a matrix. Basically matrix[y][x].
But I agree, I wasted 90% of the time on string parsing. The math is what's easy here.

>> No.68763072
File: 13 KB, 480x360, huh.jpg [View same] [iqdb] [saucenao] [google] [report]

how to write better parser?
yes i made a class as a wrapper fuck u

from numpy import *
from time import *
class Cut:

def __init__(self, x, y, w, h, c):
self.x1 = x
self.y1 = y
self.x2 = x + w
self.y2 = y + h
self.check = w * h * c
self.c = c

start = time()
file = open("day3input.txt", "r")
claims = []
for line in file:
line = line.rstrip("\n")
line = line.split(" ")
claim_num = int(line[0][1:])
coords = line[2].split(" ")
coords = coords[0].split(",")
coords[1] = coords[1].rstrip(":")
size = line[3].split("x")
new_cut = Cut(int(coords[0]), int(coords[1])
, int(size[0]), int(size[1]), claim_num)

fabric = zeros((1001,1001), dtype=int)
for claim in claims:
for y in range(claim.y1, claim.y2):
for x in range(claim.x1, claim.x2):
fabric[x][y] += claim.c

for claim in claims:
checker = 0
for y in range(claim.y1, claim.y2):
for x in range(claim.x1, claim.x2):
if claim.c != fabric[x][y]:
checker += fabric[x][y]
if checker == claim.check:

print(time() - start)

>> No.68763076

pushing out something extremely sloppy just so i can get the answer makes me feel pretty shitty

>> No.68763078
File: 60 KB, 1068x278, Annotation 2018-12-03 014547.png [View same] [iqdb] [saucenao] [google] [report]

Thread theme

>> No.68763079

int claims[1000][1000];

>> No.68763080

>boy i sure hope the next one isn't about who can throw together the fastest string manipulation as i'm not going too high level!

fuck you

>> No.68763083

Yeah, I too lazy to check the documentation on how to use the regex library

>> No.68763085

map<int, map<int, int>>

>> No.68763086
File: 6 KB, 607x63, day3.png [View same] [iqdb] [saucenao] [google] [report]

>wasted exactly 1 hour trying to initialize 2D array in Python
>the problems aren't even hard

>> No.68763091

Every one get a rank.

>> No.68763101

not being able to do day 1 with everyone really fucked over my score reeee

>> No.68763102

dude you're using C++
Just shift the fucking integers
(0100 0010 << 8) & (0111 1111)
your "hash function" 0100 0010 0111 1111

>> No.68763108

well considering it's a practice :)
regex skill is always useful

>> No.68763110

Wait what?
Pretty sure it works with a 1000x1000 matrix though.

>> No.68763112
File: 41 KB, 324x322, 1422245290263.jpg [View same] [iqdb] [saucenao] [google] [report]

>everyone guessing the matrix size at a fixed size
>mfw I spent 20 minutes string parsing to get the max_x and max_y and get a exact dimensions for the dataset

>> No.68763113

Just reformat the input the way you need it with your editor brah
See >>68762235

>> No.68763116


>> No.68763117

Some people got unlucky. >>68763046

>> No.68763121


>passing vector by value

>> No.68763125

If you actually know regex, doing it in one line with an exceedingly simple pettern is better than the 8 lines of bullshit in >>68763045

>> No.68763128
File: 1 KB, 630x28, FUCK.png [View same] [iqdb] [saucenao] [google] [report]

i joined in THIS late and then after that i fucked up the instructions for part 2 ; _;

>> No.68763129

i just started small and had my thing add a new row or column if the coordinate was out of range, wasn't as much of a pain in the ass as i expected

>> No.68763133

pleb >>68762286
or my current iteration
input = '''
1 604 100 17 27
1340 952 280 19 26
1341 425 57 26 14
data = []
for i in input:
rect = [int(j) for j in i.split() if j]
data.append((rect[0], (rect[1], rect[1] + rect[3]), (rect[2], rect[2] + rect[4])))

>> No.68763135

after 2 hours my Haskell solution is finally down to 0.477s

>> No.68763136

Why do you need to care about the size of it at all? With a defaultdict, just iterate over d.values() and bob's your uncle

>> No.68763137

but its given as a fixed size anon

>> No.68763141

>at least

>> No.68763144

My c solution is at 5ms.

>> No.68763147


>everyone guessing the matrix size at a fixed size
I just looked through my file, noticed that dimensions of any claim were never more than 2 digits in size, and the largest x or y coordinate was 3 digits in size and started with an 8. I then just said fuck it and made a 1000x1000 array.

>mfw I spent 20 minutes string parsing to get the max_x and max_y and get a exact dimensions for the dataset
Yeah, I spent a similar amount of time parsing in Rust.

>> No.68763151

>all that to parse input
wew, i did it this way
for (string line: getline(cin, line); ) {
object o;

>> No.68763153

That was shitty wording, considering that it's exactly 1000x1000

>> No.68763156

Someone create a BIG BOY INPUT please

>> No.68763159

Oh, and I got the math and/or string parsing wrong, too, because I can decrease the dimensions. Fuck me.

>> No.68763162
File: 76 KB, 550x550, 6yw51zhxm5a11[1].jpg [View same] [iqdb] [saucenao] [google] [report]


>> No.68763163

Please don't, I'll be sitting here waiting for it to complete for a few years

>> No.68763171

This problem scales extremely poorly with big boy inputs.

>> No.68763173
File: 41 KB, 645x729, bottomless-pit-wojak.jpg [View same] [iqdb] [saucenao] [google] [report]

>today is the day you realise you're a brainlet


>> No.68763179

>not copy pasting from the output


>> No.68763190

eric the creator in chat here

>> No.68763192

>i was adding up dimensions statically over every iteration of the boxes
>didn't realize why my answer was wrong or that this is why I was getting index errors, so I just increased the size of my numpy matrix
I'm such a fucking brainlet idk how i got a job

>> No.68763218

Your local internet brainlet here. Any programming review/advice/input would be appreciated.
import re

c = 0
t = [[-1 for i in range(1000)] for j in range(1000)]
for l in ls:
id, x, y, w, h = list(map(int, re.findall(r'[\d]+', l)))
for i in range(y, y+h):
for j in range(x, x+w):
if t[i][j] != -1:
if t[i][j] != 0:
t[i][j] = 0
c += 1
t[i][j] = id

>> No.68763237

Have we enumerated all of the styles of solution?

I produced a mapping of coordinates to a rect list like so:
{(x,y): [foo, bar, baz]} # foo=1, bar=12, baz=123
This means that I can get the length of the list to determine the number of indices with overlapping rects, and I can also get the actual rects occupying a coordinate.

Shamefully, the algorithm determining the number of coordinates with overlapping rects becomes highly dimensional.

>> No.68763239

who here /still under one second for all three days/?

>> No.68763243

sexy as fuck desu

>> No.68763246

Suddenly I don't want to participate. No wonder it's just string parsing retardation.

>> No.68763258

he's not the streamer you dummy, why would he be streaming himself taking two hours to solve his own puzzle? he's just in chat

>> No.68763260

the creator isnt the streamer, the creator is in chat. just to clear it up

>> No.68763262
File: 44 KB, 601x625, point.jpg [View same] [iqdb] [saucenao] [google] [report]

yeah right

>> No.68763264

who is this guy?

>> No.68763265

>live coding
>live coding advent of code
>live coding advent of code with python
At least do it in some interesting language.

Oh nevermind, that guy's a retard.

>> No.68763281

Nonetheless, the streamer is retarded and has animated flames coming out of his text cursor. Never seen anything like it.

>> No.68763283

Nah, pretty much all the solutions are optimal big-O processor efficiency. And the memory thing is kind of an awkward ask because there are dozens of different ways to optimize that would work best depending on how it grows (is it going to be same-sized rectangles in a much larger field, just more rectangles in the same field, just scale the rectangles size up by a factor of 10,000, etc). I don't think it'd prove anything.

>> No.68763295

that helps you solve problem one but you may find trouble in problem 2 since you're not actually tracking where rects are.

>> No.68763298

He probably did something wrong causing it to be 999x999 is my guess

>> No.68763299

.---_ 8
/ /\| 7
/ | \ 6
/ / \ 5
/ \ 4
./ ~~~ ~~~~ ~\. 3 **
( " - . ) 2 **
_'~ ~ ~ ~~ ~ '_________ ___ __ _ _ _ _ 1 **

What did they mean by this?

>> No.68763300
File: 53 KB, 420x672, mfw.png [View same] [iqdb] [saucenao] [google] [report]

this is in Haskell too...

>> No.68763315

I mean I was thinking that the guy was making a joke about solving it in under a second, if we're talking performance then yeah none reached 100ms.

>> No.68763320


>> No.68763335

santa hat obviously

>> No.68763337
File: 109 KB, 219x268, gwen_disbelief.png [View same] [iqdb] [saucenao] [google] [report]

Holy SHIT, what a brainlet. I seriously hope you guys are smarter than this.

>> No.68763344


>> No.68763353

very basic solver with c++,
real 0m0.021s
user 0m0.013s
sys 0m0.007s

>> No.68763364

i couldnt find it in the about
how are these scored exacly?

>> No.68763365

Big boy input is brewing...

>> No.68763366
File: 226 KB, 792x698, part2.png [View same] [iqdb] [saucenao] [google] [report]

I know he's not the streamer. I'm saying the streamer is a brainlet.

What is he even trying to do? He's just getting more and more confused every minute.

>> No.68763385

>list_STUFFFFFF = []
>shadows id
>that input parsing
>fucking numpy

At least, it's making me feel better about my own code

>> No.68763395

i think he's trying to do it in one go without iterating through the instructions once to make the array and then again to check if there is a collision.

>> No.68763401
File: 23 KB, 403x188, autism.png [View same] [iqdb] [saucenao] [google] [report]


>> No.68763406

i hope he's not one of us.

>> No.68763415

aw heck yeah!

>> No.68763422

the fuck

>> No.68763432


>i am a twitch streamer that is learning to program

fuck, i was hoping he was some dude from silicon valley, was going to feel a lot better about my programming

>twitter and discord in binary
fucking disgusting

>> No.68763434

>using that many lines for a simple puzzle

>> No.68763439

based seppler
$ time bin/day_03.out < data/day_03.txt

Cnt: 115304
Line: 275

real 0m0.031s
user 0m0.016s
sys 0m0.016s

>> No.68763445

Got my big boy input, where do I upload it? Anonymous file hosters only go up to like 100mb.

>> No.68763449

>creator trying to educate streamer on big o notation


>> No.68763452

Did you build a Map by folding claims? I'm stuck at around 520ms, but I am running this on a surface tbf.

>> No.68763474
File: 508 KB, 944x1024, 1497723823483.png [View same] [iqdb] [saucenao] [google] [report]

that's pretty big

>> No.68763475

so did everybody just do this then check for 1's?

while (ss >> x >> y >> w >> h) {
for (int i = x; i < x + w; i++) {
for (int j = y; j < y + h; j++) {

>> No.68763482

small boy

>> No.68763484


>> No.68763502

Anons, is this okay?
real 0m0.033s
user 0m0.000s
sys 0m0.000s

>> No.68763514

i5-7300HQ if that says anything

>> No.68763523


>> No.68763528

i hope you fuckers have enough ram for big input

>> No.68763530

>fuck iostreams
lol i had to switch to stringstream for part 2 so I could restream the input again. fucked my time good.

>> No.68763531

for you UwU

>> No.68763534

~22 Bytes per line
filesize >100 mB
-> more than 4.5 million patches.
that is quite a quilt

>> No.68763545
File: 2.77 MB, 512x512, 1524025179052.gif [View same] [iqdb] [saucenao] [google] [report]

>tfw I completed the first brainlet filter

>> No.68763556
File: 6 KB, 651x63, ConEmu64_2018-12-03_18-35-28.png [View same] [iqdb] [saucenao] [google] [report]

fn part_one(fabric: &Fabric) -> i32 {

fn part_two(claim_list: &Vec<Claim>, fabric: &Fabric) -> Result<i32, String> {
if let Some(result) = claim_list
.find(|claim| !fabric.is_overlapping_claim(claim))
} else {
Err("no non-overlapping claims found".to_string())

impl Fabric {
fn count_overlap(&self) -> i32 {
.map(|row| row.iter().filter(|cell| **cell > 1).count())
.sum::<usize>() as i32

fn is_overlapping_claim(&self, claim: &Claim) -> bool {
let x_loc = claim.l.x as usize;
let y_loc = claim.l.y as usize;
let x_dim = claim.d.x as usize;
let y_dim = claim.d.y as usize;

self.cloth[x_loc..x_loc + x_dim]
.flat_map(|row| &row[y_loc..y_loc + y_dim])
.any(|cell| *cell > 1)

i'm really enjoying rust

>> No.68763557

the only hard part is string parsing unless youre trying to fucking O(n) this

>> No.68763572

>New Thread

>> No.68763581

>Thread is 50 minutes old because OP is a fag and didn't link it despite being reminded twice

>> No.68763603


>> No.68763620

>New(ish) Thread

>> No.68763639

Any programming review/advice/input would be appreciated.
This is my part 2
import re

ls = open('input', 'r').read().strip().split('\n')
s = set(range(1,len(ls)+1))
d = {}
for l in ls:
id, x, y, w, h = list(map(int, re.findall(r'[\d]+', l)))
for i in range(y, y+h):
for j in range(x, x+w):
if (i,j) in d:
if id in s:
if d[(i,j)] in s:
d[(i,j)] = id

Is there a way for me to not look in the set at every collision index?
if id in s:
if d[(i,j)] in s:

>> No.68763898


claim GetClaimData(string claimLine)
int ID, x, y, w, h;
char pnd, at, comm, col, ex;

stringstream ss(claimLine);
ss >> pnd >> ID >> at >> x >> comm >> y >> col >> w >> ex >> h;

claim thisClaim = {ID, x, y, w, h};
return thisClaim;

>> No.68764031

la-z-boy style

val rects = io.Source.stdin.getLines
.map { "(\\d+)".r.findAllIn(_).map{_.toInt}.toArray }

val a = Array.ofDim[Int](1000, 1000)
for {
Array(_, x, y, w, h) <- rects
r <- x until x+w
c <- y until y+h
a(r)(c) += 1

println (a .map {_ count {_>1}} .sum)

>> No.68764064

val rects = io.Source.stdin.getLines
.map { "(\\d+)".r.findAllIn(_).map{_.toInt}.toArray }

val a = Array.ofDim[Int](1000, 1000)
for {
Array(_, x, y, w, h) <- rects
r <- x until x+w
c <- y until y+h
a(r)(c) += 1

for (Array(id, x, y, w, h) <- rects) {
var overlapping = false
for {
r <- x until x+w
c <- y until y+h
if(a(r)(c) > 1)
overlapping = true

if (!overlapping)

>> No.68764079


I see you have chosen a similar naming scheme to me. >>68762966

>> No.68764325

>the only hard part is string parsing
No, it isn't. At least not in a good language like MATLAB where this is really easy.

>> No.68764337

a little late but big boy input
P1 ANSWER: 106501
P2 ANSWER: 632

>> No.68764823

doesn't seem to be bigger than the normal input

>> No.68764850

NEW THREAD for those that missed it

>>68763109 >>68763109
>>68763109 >>68763109 >>68763109
>>68763109 >>68763109

Name (leave empty)
Comment (leave empty)
Password [?]Password used for file deletion.