Skip to content

Commit df680c2

Browse files
committed
day 22 cleanup
1 parent 8021d27 commit df680c2

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

2021/Day22/Solution.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,14 @@ record Section(int from, int to) {
7979
public bool IsEmpty => from > to;
8080
public long Length => IsEmpty ? 0 : to - from + 1;
8181

82-
public Section Intersect(Section that) =>
83-
this.from > that.from ? that.Intersect(this) : // switch order
84-
that.to < this.from ? new Section(0, -1) : // empty
85-
new Section(that.from, Math.Min(this.to, that.to));
82+
public Section Intersect(Section that) =>
83+
new Section(Math.Max(this.from, that.from), Math.Min(this.to, that.to));
8684
}
8785

8886
record Region(Section x, Section y, Section z) {
8987
public bool IsEmpty => x.IsEmpty || y.IsEmpty || z.IsEmpty;
9088
public long Volume => x.Length * y.Length * z.Length;
9189

92-
public Region Intersect(Region that) {
93-
return new Region(this.x.Intersect(that.x), this.y.Intersect(that.y), this.z.Intersect(that.z));
94-
}
90+
public Region Intersect(Region that) =>
91+
new Region(this.x.Intersect(that.x), this.y.Intersect(that.y), this.z.Intersect(that.z));
9592
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy