Skip to content

Commit

Permalink
Year 2022, Days 7+10
Browse files Browse the repository at this point in the history
Removed unused variables and on day 10 used an "OCR" utility to identify the string
  • Loading branch information
uvg committed Dec 2, 2023
1 parent eca1ffa commit 57dec9c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
10 changes: 4 additions & 6 deletions src/AOC2022/Day07.cls
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ ClassMethod Part1(verbose = 0) As %String [ Private ]
{
do ..GetInputToArray(..#InputFile,.recordsArr)
//Compute the sum of all dirs <=100000
set answer="",line="",state=0,currDir=""
set answer="",line="",currDir=""
for {
set line=$order(recordsArr(line)) quit:line=""
set record=recordsArr(line)
if $extract(record,1,4)="$ cd" {
set state=1,nextDir=$piece(record," ",3)
set nextDir=$piece(record," ",3)
if nextDir=".." {
set nextDir=$list(filesArr(currDir),1)
} else {
Expand All @@ -24,7 +24,6 @@ ClassMethod Part1(verbose = 0) As %String [ Private ]
continue
}
if $extract(record,1,4)="$ ls" {
set state=2
continue
}
set fileSize=$piece(record," ",1),fileName=$piece(record," ",2)
Expand Down Expand Up @@ -92,12 +91,12 @@ ClassMethod Part2(verbose = 0) As %String [ Private ]
{
do ..GetInputToArray(..#InputFile,.recordsArr)
//
set answer="",line="",state=0,currDir=""
set answer="",line="",currDir=""
for {
set line=$order(recordsArr(line)) quit:line=""
set record=recordsArr(line)
if $extract(record,1,4)="$ cd" {
set state=1,nextDir=$piece(record," ",3)
set nextDir=$piece(record," ",3)
if nextDir=".." {
set nextDir=$list(filesArr(currDir),1)
} else {
Expand All @@ -107,7 +106,6 @@ ClassMethod Part2(verbose = 0) As %String [ Private ]
continue
}
if $extract(record,1,4)="$ ls" {
set state=2
continue
}
set fileSize=$piece(record," ",1),fileName=$piece(record," ",2)
Expand Down
17 changes: 12 additions & 5 deletions src/AOC2022/Day10.cls
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,26 @@ ClassMethod Part2(verbose = 0) As %String [ Private ]
}
}
if verbose zwrite opps
set cycle="",pos=0
set cycle="",pos=0,y=0,string=""
for {
set cycle=$order(opps(cycle)) quit:cycle=""
if cycle#40=1 write !
if cycle#40=1 {
set y=y+1,string=""
}
if $zabs(pos-x)<2 {
write "#"
set string=string_"#"
} else {
write " "
set string=string_" "
}
set pos=pos+1
if pos#40=0 set pos=0
if pos#40=0 {
set pos=0
set grid(y)=string
}
set x=x+opps(cycle)
}
if verbose zwrite grid
set answer=##class(AOC.Utils).OCR(.grid,"#"," ")
quit answer
}

Expand Down

0 comments on commit 57dec9c

Please sign in to comment.