Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DEFLNG A-Z
- DIM raw(1200) AS STRING
- DIM t AS INTEGER
- DIM m(32, 60) AS INTEGER
- DIM gid(32) AS INTEGER
- DIM w$(fake)
- OPEN "c:\aoc\2018\input04.txt" FOR INPUT AS #1
- WHILE NOT EOF(1)
- INPUT #1, r$: t = t + 1: raw(t) = r$
- WEND
- CLOSE #1
- FOR i = 1 TO t - 1
- FOR j = 1 TO t - i
- IF raw(j) > raw(j + 1) THEN r$ = raw(j): raw(j) = raw(j + 1): raw(j + 1) = r$
- NEXT
- NEXT
- FOR i = 1 TO t
- a$ = raw(i): GOSUB strsplit
- SELECT CASE w$(6)
- CASE "Guard": id = VAL(w$(7)): GOSUB hGuard
- CASE "falls": t0 = VAL(w$(5))
- CASE "wakes": t1 = VAL(w$(5)): FOR j = t0 TO t1 - 1: m(h, j) = m(h, j) + 1: NEXT
- END SELECT
- NEXT
- 'pt1
- FOR h = 1 TO gc
- sum = 0: FOR j = 0 TO 59: sum = sum + m(h, j): NEXT
- IF sum > bigsum THEN bigsum = sum: bigh = h
- NEXT
- FOR j = 0 TO 59
- mm = m(bigh, j): IF mm > bigmm THEN bigmm = mm: bigj = j
- NEXT
- PRINT "part 1:"; gid(bigh) * bigj; " ( guard"; gid(bigh); "x minute"; bigj; ")"
- 'pt2
- bigh = 0: bigsum = 0
- FOR h = 1 TO gc
- FOR j = 0 TO 59
- IF m(h, j) > bigsum THEN bigsum = m(h, j): bigh = h: bigj = j
- NEXT
- NEXT
- PRINT "part 2:"; gid(bigh) * bigj; " ( guard"; gid(bigh); "x minute"; bigj; ")"
- END
- '-------------------------------------------
- hGuard:
- h = 0
- FOR j = 1 TO gc
- IF gid(j) = id THEN h = j
- NEXT
- IF h = 0 THEN gc = gc + 1: gid(gc) = id: h = gc
- RETURN
- strsplit:
- REDIM w$(16)
- DL$ = "[]-:# ": ii = 1: ok = 0
- FOR jj = 1 TO LEN(a$)
- b$ = MID$(a$, jj, 1)
- splitme = 0
- FOR kk = 1 TO LEN(DL$)
- IF b$ = MID$(DL$, kk, 1) THEN splitme = 1
- NEXT
- IF splitme = 1 THEN
- IF ok = 1 THEN ii = ii + 1: ok = 0
- ELSE
- IF b$ > " " THEN w$(ii) = w$(ii) + b$: ok = 1
- END IF
- NEXT
- 'FOR i = 1 TO ii: PRINT i; ") "; w$(i): NEXT: SLEEP 'test
- RETURN
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement