PrimeIntellect/SWE-rebench-V2 huggingface dataset:
Repository: vaskoz/dailycodingproblem-go (go)

Issue:
Day 185
Good morning! Here's your coding interview problem for today.

This problem was asked by Google.

Given two rectangles on a 2D graph, return the area of their intersection. If the rectangles don't intersect, return 0.

For example, given the following rectangles:
```
{
    "top_left": (1, 4),
    "dimensions": (3, 3) # width, height
}
```
and
```
{
    "top_left": (0, 5),
    "dimensions" (4, 3) # width, height
}
```
return 6.

Pull request:
Day185
Resolves #381.

Patch:
diff --git a/README.md b/README.md
index b4413fb..b2a2680 100644
--- a/README.md
+++ b/README.md
@@ -194,3 +194,4 @@ problems from
 * [Day 181](https://github.com/vaskoz/dailycodingproblem-go/issues/375)
 * [Day 182](https://github.com/vaskoz/dailycodingproblem-go/issues/376)
 * [Day 184](https://github.com/vaskoz/dailycodingproblem-go/issues/378)
+* [Day 185](https://github.com/vaskoz/dailycodingproblem-go/issues/381)
diff --git a/day185/problem.go b/day185/problem.go
new file mode 100644
index 0000000..5e38191
--- /dev/null
+++ b/day185/problem.go
@@ -0,0 +1,39 @@
+package day185
+
+// Rectangle with a top-left coordinate plus width and height.
+type Rectangle struct {
+	topLeftX, topLeftY int
+	width, height      int
+}
+
+// AreaOfIntersection returns the area of intersection of two
+// rectangles.
+func AreaOfIntersection(r1, r2 Rectangle) int {
+	leftMostR := r1
+	rightMostR := r2
+	if r2.topLeftX < r1.topLeftX {
+		leftMostR = r2
+		rightMostR = r1
+	}
+	deltaX := 0
+	if leftMostRR := leftMostR.topLeftX + leftMostR.width; leftMostRR > rightMostR.topLeftX {
+		deltaX = leftMostRR - rightMostR.topLeftX
+	}
+	if deltaX == 0 {
+		return 0
+	}
+	topMostR := r1
+	bottomMostR := r2
+	if r2.topLeftY < r1.topLeftY {
+		topMostR = r2
+		bottomMostR = r1
+	}
+	deltaY := 0
+	if topMostRR := topMostR.topLeftY + topMostR.height; topMostRR > bottomMostR.topLeftY {
+		deltaY = topMostRR - bottomMostR.topLeftY
+	}
+	if deltaY == 0 {
+		return 0
+	}
+	return deltaX * deltaY
+}


Test patch:
diff --git a/day185/problem_test.go b/day185/problem_test.go
new file mode 100644
index 0000000..c32c101
--- /dev/null
+++ b/day185/problem_test.go
@@ -0,0 +1,29 @@
+package day185
+
+import "testing"
+
+var testcases = []struct {
+	r1, r2 Rectangle
+	area   int
+}{
+	{Rectangle{1, 4, 3, 3}, Rectangle{0, 5, 4, 3}, 6},
+	{Rectangle{10, 10, 3, 3}, Rectangle{0, 0, 3, 3}, 0},
+	{Rectangle{10, 10, 3, 3}, Rectangle{10, 0, 3, 3}, 0},
+}
+
+func TestAreaOfIntersection(t *testing.T) {
+	t.Parallel()
+	for _, tc := range testcases {
+		if area := AreaOfIntersection(tc.r1, tc.r2); area != tc.area {
+			t.Errorf("Expected %v, got %v", tc.area, area)
+		}
+	}
+}
+
+func BenchmarkAreaOfIntersection(b *testing.B) {
+	for i := 0; i < b.N; i++ {
+		for _, tc := range testcases {
+			AreaOfIntersection(tc.r1, tc.r2)
+		}
+	}
+}
Repository: algorand/indexer (go)

Issue:
Requesting an account at a round in the future should return an error.
## Summary
Currently it is silently ignored:
https://github.com/algorand/indexer/pull/373#discussion_r588331654

## Scope/Requirements
Check for error in `fetchAccounts`

## Urgency/Relative Priority
Low priority but would be nice to add in.

Pull request:
Return an error when rewinding to a future round
## Summary
Closes #380.

## Test Plan
Added a unit test.

Patch:
diff --git a/api/handlers.go b/api/handlers.go
index 66a9509..0c5079b 100644
--- a/api/handlers.go
+++ b/api/handlers.go
@@ -627,6 +627,11 @@ func (si *ServerImplementation) fetchBlock(ctx context.Context, round uint64) (g
 func (si *ServerImplementation) fetchAccounts(ctx context.Context, options idb.AccountQueryOptions, atRound *uint64) ([]generated.Account, uint64 /*round*/, error) {
 	accountchan, round := si.db.GetAccounts(ctx, options)
 
+	if (atRound != nil) && (*atRound > round) {
+		return nil, round, fmt.Errorf(
+			"%s: the requested round %d > the current round %d", errRewindingAccount, *atRound, round)
+	}
+
 	accounts := make([]generated.Account, 0)
 	for row := range accountchan {
 		if row.Error != nil {
@@ -645,7 +650,7 @@ func (si *ServerImplementation) fetchAccounts(ctx context.Context, options idb.A
 
 		// Compute for a given round if requested.
 		var account generated.Account
-		if (atRound != nil) && (*atRound < row.Account.Round) {
+		if atRound != nil {
 			acct, err := accounting.AccountAtRound(row.Account, *atRound, si.db)
 			if err != nil {
 				// Ignore the error if this is an account search rewind error


Test patch:
diff --git a/api/handlers_test.go b/api/handlers_test.go
index dbc3f06..c03d6c5 100644
--- a/api/handlers_test.go
+++ b/api/handlers_test.go
@@ -6,6 +6,7 @@ import (
 	"encoding/json"
 	"fmt"
 	"io/ioutil"
+	"strings"
 	"testing"
 	"time"
 
@@ -483,3 +484,21 @@ func TestFetchTransactions(t *testing.T) {
 		})
 	}
 }
+
+func TestFetchAccountsRewindRoundTooLarge(t *testing.T) {
+	ch := make(chan idb.AccountRow)
+	close(ch)
+	var outCh <-chan idb.AccountRow = ch
+
+	db := &mocks.IndexerDb{}
+	db.On("GetAccounts", mock.Anything, mock.Anything).Return(outCh, uint64(7)).Once()
+
+	si := ServerImplementation{
+		EnableAddressSearchRoundRewind: true,
+		db:                             db,
+	}
+	atRound := uint64(8)
+	_, _, err := si.fetchAccounts(context.Background(), idb.AccountQueryOptions{}, &atRound)
+	assert.Error(t, err)
+	assert.True(t, strings.HasPrefix(err.Error(), errRewindingAccount), err.Error())
+}