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

Issue:
Day 363
Good morning! Here's your coding interview problem for today.

This problem was asked by Squarespace.

Write a function, `add_subtract`, which alternately adds and subtracts curried arguments. Here are some sample operations:

```
add_subtract(7) -> 7

add_subtract(1)(2)(3) -> 1 + 2 - 3 -> 0

add_subtract(-5)(10)(3)(9) -> -5 + 10 - 3 + 9 -> 11
```

Pull request:
Day363
Resolves #716.

Patch:
diff --git a/README.md b/README.md
index 953af36..80c4b16 100644
--- a/README.md
+++ b/README.md
@@ -344,3 +344,4 @@ problems from
 * [Day 360](https://github.com/vaskoz/dailycodingproblem-go/issues/709)
 * [Day 361](https://github.com/vaskoz/dailycodingproblem-go/issues/712)
 * [Day 362](https://github.com/vaskoz/dailycodingproblem-go/issues/714)
+* [Day 363](https://github.com/vaskoz/dailycodingproblem-go/issues/716)
diff --git a/day363/problem.go b/day363/problem.go
new file mode 100644
index 0000000..b0fc94b
--- /dev/null
+++ b/day363/problem.go
@@ -0,0 +1,24 @@
+package day363
+
+type curry struct {
+	total int
+	add   bool
+}
+
+func (c *curry) __(n int) *curry {
+	if c.add {
+		c.total += n
+	} else {
+		c.total -= n
+	}
+	c.add = !c.add
+	return c
+}
+
+func (c *curry) Execute() int {
+	return c.total
+}
+
+func AddSubtract(n int) *curry {
+	return &curry{n, true}
+}


Test patch:
diff --git a/day363/problem_test.go b/day363/problem_test.go
new file mode 100644
index 0000000..4fb437d
--- /dev/null
+++ b/day363/problem_test.go
@@ -0,0 +1,48 @@
+package day363
+
+import "testing"
+
+// nolint
+var testcases = []struct {
+	input    []int
+	expected int
+}{
+	{[]int{7}, 7},
+	{[]int{1, 2, 3}, 0},
+	{[]int{-5, 10, 3, 9}, 11},
+}
+
+func TestAddSubtract(t *testing.T) {
+	t.Parallel()
+	for _, tc := range testcases {
+		as := AddSubtract(tc.input[0])
+		for i := 1; i < len(tc.input); i++ {
+			as = as.__(tc.input[i])
+		}
+		if result := as.Execute(); result != tc.expected {
+			t.Errorf("Expected %v, got %v", tc.expected, result)
+		}
+	}
+}
+
+func TestAddSubtractChained(t *testing.T) {
+	t.Parallel()
+	result := AddSubtract(5).__(6).__(12).__(20).__(30)
+	result = result.__(10).__(-50)
+	expected := 49
+	if result.Execute() != expected {
+		t.Errorf("Expected %v, got %v", expected, result.Execute())
+	}
+}
+
+func BenchmarkAddSubtract(b *testing.B) {
+	for i := 0; i < b.N; i++ {
+		for _, tc := range testcases {
+			as := AddSubtract(tc.input[0])
+			for i := 1; i < len(tc.input); i++ {
+				as = as.__(tc.input[i])
+			}
+			as.Execute()
+		}
+	}
+}
Repository: vaskoz/dailycodingproblem-go (go)

Issue:
Day 7
Good morning! Here's your coding interview problem for today.

This problem was asked by Facebook.

Given the mapping a = 1, b = 2, ... z = 26, and an encoded message, count the number of ways it can be decoded.

For example, the message '111' would give 3, since it could be decoded as 'aaa', 'ka', and 'ak'.

You can assume that the messages are decodable. For example, '001' is not allowed.

Pull request:
Day7
Resolves #15 

Patch:
diff --git a/README.md b/README.md
index 764ff76..200854f 100644
--- a/README.md
+++ b/README.md
@@ -15,4 +15,5 @@ problems from
 * [Day 4](https://github.com/vaskoz/dailycodingproblem-go/issues/5)
 * [Day 5](https://github.com/vaskoz/dailycodingproblem-go/issues/9)
 * [Day 5 merge k sorted lists](https://github.com/vaskoz/dailycodingproblem-go/issues/11)
-
+* [Day 6](https://github.com/vaskoz/dailycodingproblem-go/issues/13)
+* [Day 7](https://github.com/vaskoz/dailycodingproblem-go/issues/15)
diff --git a/day7/problem.go b/day7/problem.go
new file mode 100644
index 0000000..4708f57
--- /dev/null
+++ b/day7/problem.go
@@ -0,0 +1,17 @@
+package day7
+
+// NumberOfDecodings calculates the number of possible decodings where
+// letters are encoding as a=1, b=2 ... z=26
+func NumberOfDecodings(str string) int {
+	if length := len(str); length == 0 || length == 1 {
+		return 1
+	}
+	var count int
+	if last := str[len(str)-1]; last > '0' && last <= '9' {
+		count = NumberOfDecodings(str[:len(str)-1])
+	}
+	if second := str[len(str)-2]; second == '1' || second == '2' && str[len(str)-1] < '7' {
+		count += NumberOfDecodings(str[:len(str)-2])
+	}
+	return count
+}


Test patch:
diff --git a/day7/problem_test.go b/day7/problem_test.go
new file mode 100644
index 0000000..472f85d
--- /dev/null
+++ b/day7/problem_test.go
@@ -0,0 +1,29 @@
+package day7
+
+import "testing"
+
+var testcases = []struct {
+	input    string
+	expected int
+}{
+	{"111", 3},
+	{"1111", 5},
+	{"2626", 4},
+	{"1234", 3},
+}
+
+func TestNumberOfDecodings(t *testing.T) {
+	for _, tc := range testcases {
+		if result := NumberOfDecodings(tc.input); result != tc.expected {
+			t.Errorf("For input %v, expected %v but got %v", tc.input, tc.expected, result)
+		}
+	}
+}
+
+func BenchmarkNumberOfDecodings(b *testing.B) {
+	for i := 0; i < b.N; i++ {
+		for _, tc := range testcases {
+			NumberOfDecodings(tc.input)
+		}
+	}
+}
Repository: vaskoz/dailycodingproblem-go (go)

Issue:
Day 188
Good morning! Here's your coding interview problem for today.

This problem was asked by Google.

What will this code print out?
```
def make_functions():
    flist = []

    for i in [1, 2, 3]:
        def print_i():
            print(i)
        flist.append(print_i)

    return flist

functions = make_functions()
for f in functions:
    f()
```
How can we make it print out what we apparently want?

Pull request:
Day188
Resolves #388.

Patch:
diff --git a/README.md b/README.md
index 53e3c0f..4c01982 100644
--- a/README.md
+++ b/README.md
@@ -197,3 +197,4 @@ problems from
 * [Day 184](https://github.com/vaskoz/dailycodingproblem-go/issues/378)
 * [Day 185](https://github.com/vaskoz/dailycodingproblem-go/issues/381)
 * [Day 186](https://github.com/vaskoz/dailycodingproblem-go/issues/382)
+* [Day 188](https://github.com/vaskoz/dailycodingproblem-go/issues/388)
diff --git a/day188/problem.go b/day188/problem.go
new file mode 100644
index 0000000..be43a93
--- /dev/null
+++ b/day188/problem.go
@@ -0,0 +1,25 @@
+package day188
+
+// MakeFunctionsOriginal is the problem version.
+func MakeFunctionsOriginal() []func() int {
+	var funcList []func() int
+	for _, i := range []int{1, 2, 3} {
+		funcList = append(funcList, func() int {
+			return i
+		})
+	}
+	return funcList
+}
+
+// MakeFunctionsCorrect is the corrected version.
+func MakeFunctionsCorrect() []func() int {
+	var funcList []func() int
+	for _, i := range []int{1, 2, 3} {
+		funcList = append(funcList, func(i int) func() int {
+			return func() int {
+				return i
+			}
+		}(i))
+	}
+	return funcList
+}
diff --git a/day188/problem.py b/day188/problem.py
new file mode 100644
index 0000000..21b50d4
--- /dev/null
+++ b/day188/problem.py
@@ -0,0 +1,13 @@
+def make_functions():
+    flist = []
+
+    for i in [1, 2, 3]:
+        def print_i():
+            print(i)
+        flist.append(print_i)
+
+    return flist
+
+functions = make_functions()
+for f in functions:
+    f()
diff --git a/day188/problem_correct.py b/day188/problem_correct.py
new file mode 100644
index 0000000..59b0407
--- /dev/null
+++ b/day188/problem_correct.py
@@ -0,0 +1,15 @@
+def make_functions():
+    flist = []
+
+    for i in [1, 2, 3]:
+        def build_print_i(i):
+            def print_i():
+                print(i)
+            return print_i
+        flist.append(build_print_i(i))
+
+    return flist
+
+functions = make_functions()
+for f in functions:
+    f()


Test patch:
diff --git a/day188/problem_test.go b/day188/problem_test.go
new file mode 100644
index 0000000..0b5dd58
--- /dev/null
+++ b/day188/problem_test.go
@@ -0,0 +1,23 @@
+package day188
+
+import "testing"
+
+func TestMakeFunctionsOriginal(t *testing.T) {
+	t.Parallel()
+	funcs := MakeFunctionsOriginal()
+	for _, f := range funcs {
+		if result := f(); result != 3 {
+			t.Errorf("Expected every response to be 3. Got %v", result)
+		}
+	}
+}
+
+func TestMakeFunctionsCorrect(t *testing.T) {
+	t.Parallel()
+	funcs := MakeFunctionsCorrect()
+	for i, f := range funcs {
+		if result := f(); result != i+1 {
+			t.Errorf("Expected %v, got %v", i+1, result)
+		}
+	}
+}
Repository: sindresorhus/mem (ts)

Issue:
Memoized methods of the same instance are mixed
If two functions are decorated of the same instance, their memoized values get mixed with the latest version (`v9.0.0`).

Take for example:

```typescript
class TestClass {
	@memDecorator()
	fn1() {
		return 1;
	}

	@memDecorator()
	counter2() {
		return 2;
	}
}

const instance = new TestClass();
console.log(instance.fn1()); // prints 1
console.log(instance.fn2()); // also prints 1 !!!
```

I would expect the second call to return 2, but it returns 1.

The memoized function in my understanding should be connected 1:1 to the _combination_ of _instance_ and _propterty_, whereas it is currently connected 1:1 to _instances_ (#74).

I guess a little bit more complicated internal data structure is needed instead of the current implementation of `decoratorInstanceMap`, will open a PR that adds a test and demonstrates a possible solution.

Pull request:
Fix using multiple decorators on the same instance
Fixes #77

Patch:
diff --git a/index.ts b/index.ts
index ade4c63..9bbc8ba 100644
--- a/index.ts
+++ b/index.ts
@@ -3,8 +3,6 @@ import mapAgeCleaner from 'map-age-cleaner';
 
 type AnyFunction = (...arguments_: any) => any;
 
-const decoratorInstanceMap = new WeakMap();
-
 const cacheStore = new WeakMap<AnyFunction, CacheStorage<any, any>>();
 
 interface CacheStorageContent<ValueType> {
@@ -169,6 +167,8 @@ export function memDecorator<
 >(
 	options: Options<FunctionToMemoize, CacheKeyType> = {},
 ) {
+	const instanceMap = new WeakMap();
+
 	return (
 		target: any,
 		propertyKey: string,
@@ -184,13 +184,13 @@ export function memDecorator<
 		delete descriptor.writable;
 
 		descriptor.get = function () {
-			if (!decoratorInstanceMap.has(this)) {
+			if (!instanceMap.has(this)) {
 				const value = mem(input, options) as FunctionToMemoize;
-				decoratorInstanceMap.set(this, value);
+				instanceMap.set(this, value);
 				return value;
 			}
 
-			return decoratorInstanceMap.get(this) as FunctionToMemoize;
+			return instanceMap.get(this) as FunctionToMemoize;
 		};
 	};
 }


Test patch:
diff --git a/test.ts b/test.ts
index 63deaa5..23c68a8 100644
--- a/test.ts
+++ b/test.ts
@@ -239,19 +239,24 @@ test('prototype support', t => {
 
 test('.decorator()', t => {
 	let returnValue = 1;
+	const returnValue2 = 101;
 
 	class TestClass {
 		@memDecorator()
 		counter() {
-			return returnValue;
+			return returnValue++;
+		}
+
+		@memDecorator()
+		counter2() {
+			return returnValue2;
 		}
 	}
 
 	const alpha = new TestClass();
 	t.is(alpha.counter(), 1);
 	t.is(alpha.counter(), 1, 'The method should be memoized');
-
-	returnValue++;
+	t.is(alpha.counter2(), 101, 'The method should be memoized separately from the other one');
 
 	const beta = new TestClass();
 	t.is(beta.counter(), 2, 'The method should not be memoized across instances');
Repository: gcanti/tcomb (js)

Issue:
t.maybe setting the value to null when missing
Is there a reason why [`t.maybe` sets the value to `null` when missing](https://github.com/gcanti/tcomb/blob/master/lib/maybe.js#L34)?

This behavior turns a missing value (e.g. `undefined`) into a value (`null`) and it looks like a potentially undesirable side-effect.

For instance this causes issues with [`tcomb-react`](https://github.com/gcanti/tcomb-react): since `null` is a valid value, React will not use the value provided by `defaultProps`.

```js
@props({
  foo: t.maybe(String)
})
class MyComponent extends React.Component {
  
  static defaultProps = {
    foo: 'bar'
  }

  ...
}

<MyComponent /> // Invalid value null supplied to foo
```

A more natural implementation would look like

```js
return Nil.is(value) ? value : create(type, value, path);
```

Do you think that's reasonable, @gcanti?

Pull request:
Prevent Maybe constructor from altering the value when Nil (fixes #183)
As discussed in #183, `maybe(MyType)(x)` currently returns `null` if `Nil.is(x)` returns `true`.

This may surprise users that would expect `maybe(MyType)(undefined)` to return `undefined`.

This PR changes the behavior of the `Maybe` constructor, so that `Nil` values are returned untouched by the constructor.

Patch:
diff --git a/lib/maybe.js b/lib/maybe.js
index 9813666..4d478d7 100644
--- a/lib/maybe.js
+++ b/lib/maybe.js
@@ -31,7 +31,7 @@ function maybe(type, name) {
     if (process.env.NODE_ENV !== 'production') {
       forbidNewOperator(this, Maybe);
     }
-    return Nil.is(value) ? null : create(type, value, path);
+    return Nil.is(value) ? value : create(type, value, path);
   }
 
   Maybe.meta = {


Test patch:
diff --git a/test/maybe.js b/test/maybe.js
index f332c43..2bc0e47 100644
--- a/test/maybe.js
+++ b/test/maybe.js
@@ -63,7 +63,7 @@ describe('t.maybe(type, [name])', function () {
     it('should hydrate the elements of the maybe in production', util.production(function () {
       var T = t.maybe(Point);
       assert.deepEqual(T(null), null);
-      assert.deepEqual(T(undefined), null);
+      assert.ok(typeof T(undefined) === 'undefined');
       assert.ok(Point.is(T({x: 0, y: 0})));
     }));
 
@@ -85,6 +85,12 @@ describe('t.maybe(type, [name])', function () {
       assert.equal(p1 === p2, true);
     }));
 
+    it('should be idempotent on Nil values', function () {
+      var T = t.maybe(t.String, 'T');
+      assert.deepEqual(T(null), null);
+      assert.ok(typeof T(undefined) === 'undefined');
+    });
+
   });
 
   describe('is(x)', function () {