repo stringclasses 966
values | path stringlengths 5 283 | license stringclasses 13
values | stars int64 0 3.47k | default_branch stringclasses 15
values | commit_sha stringclasses 966
values | pushed_at stringdate 2015-04-17 10:56:12 2026-07-22 05:29:38 | size_bytes int64 0 1.91M | sha256 stringlengths 64 64 | content stringlengths 0 1.91M |
|---|---|---|---|---|---|---|---|---|---|
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_266.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 533 | e4105df49b2c5d950d405e5a50a7eae338872f3784ca5381f3ff931274efcd1b | method LateralSurfaceArea(size: int) returns (area: int)
requires size > 0
ensures area == 4 * size * size
{
area := 4 * size * size;
}
method LateralSurfaceAreaTest(){
var res1:=LateralSurfaceArea(5);
print(res1);print("\n");
//assert res1==100;
var res2:=LateralSurfaceArea(9);
... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_267.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 682 | a45ca5c9a4d367685d858c9af4c2078342c7b15315b786c2b306d48d04975478 | method SumOfSquaresOfFirstNOddNumbers(n: int) returns (sum: int)
requires n >= 0
ensures sum == (n * (2 * n - 1) * (2 * n + 1)) / 3
{
sum := 0;
var i := 1;
for k:=0 to n
invariant 0 <= k <= n
invariant sum == k * (2 * k - 1) * (2 * k + 1) / 3
invariant i == 2 * k + 1
{
sum := sum ... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_268.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 443 | 03f6460ac17c7cbfe98046e370af4ebe62c4e865f2b85467600cebac48284318 | method StarNumber(n: int) returns (star: int)
requires n >= 0
ensures star == 6 * n * (n - 1) + 1
{
star := 6 * n * (n - 1) + 1;
}
method StarNumberTest(){
var res1:=StarNumber(3);
print(res1);print("\n");
assert res1==37;
var res2:=StarNumber(4);
print(res2);print("\n");
assert res2==73... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_269.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 416 | 5d616a5acee8a1fd1fa40ddd388f6928de905cd7217eaa6c5f522dc2b159cfb8 | method AsciiValue(c: char) returns (ascii: int)
ensures ascii == c as int
{
ascii := c as int;
}
method AsciiValueTest(){
var res1:= AsciiValue('A');
print(res1);print("\n");
assert res1==65;
var res2:= AsciiValue('R');
print(res2);print("\n");
assert res2==82;
var res3:= AsciiValue('S')... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_273.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,077 | d0f1cfc2d90b97a4fc61b8295d678791c3b3a6e1bcf1735a27a8b1f5ab0f8559 | method SubtractSequences(a: seq<int>, b: seq<int>) returns (result: seq<int>)
requires |a| == |b|
ensures |result| == |a|
ensures forall i :: 0 <= i < |result| ==> result[i] == a[i] - b[i]
{
result := [];
var i := 0;
while i < |a|
invariant 0 <= i <= |a|
invariant |result| == i
invaria... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_276.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 676 | 5d3f9037ba8fb835af77973150ffe583af7debba956a898a3fd6f0a54c502311 | method CylinderVolume(radius: real, height: real) returns (volume: real)
requires radius > 0.0
requires height > 0.0
ensures volume == 3.14159265359 * radius * radius * height
{
volume := 3.14159265359 * radius * radius * height;
}
method CylinderVolumeTest(){
var res1:=CylinderVolume(10.0,5.0);
... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_279.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 506 | c7659f63224257d0566ae938078033432e86ba6b5659e3b38545e0c95b81157e | method NthDecagonalNumber(n: int) returns (decagonal: int)
requires n >= 0
ensures decagonal == 4 * n * n - 3 * n
{
decagonal := 4 * n * n - 3 * n;
}
method NthDecagonalNumberTest(){
var res1:=NthDecagonalNumber(3);
print(res1);print("\n");
assert res1==27;
var res2:=NthDecagonalNumber(7);
... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_282.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,415 | 1a6650ffef8626ca7601c0daab4593ea8de9c6bf326e65ca40722c4ad9ff88eb | method ElementWiseSubtraction(a: array<int>, b: array<int>) returns (result: array<int>)
requires a != null && b != null
requires a.Length == b.Length
ensures result != null
ensures result.Length == a.Length
ensures forall i :: 0 <= i < result.Length ==> result[i] == a[i] - b[i]
{
result := new int[a... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_284.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 969 | 148c1eaa37b266df4bdd23222f75c990674a332edb0f2cb67be6096092bec412 | method AllElementsEqual(a: array<int>, n: int) returns (result: bool)
requires a != null
ensures result ==> forall i :: 0 <= i < a.Length ==> a[i] == n
ensures !result ==> exists i :: 0 <= i < a.Length && a[i] != n
{
result := true;
for i := 0 to a.Length
invariant 0 <= i <= a.Length
invariant... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_290.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,125 | eb61c37dbc0f46d327cbd16b6831f263be9303f36597136726dbc5e478b9cd63 | method MaxLengthList(lists: seq<seq<int>>) returns (maxList: seq<int>)
requires |lists| > 0
ensures forall l :: l in lists ==> |l| <= |maxList|
ensures maxList in lists
{
maxList := lists[0];
for i := 1 to |lists|
invariant 1 <= i <= |lists|
invariant forall l :: l in lists[..i] ==> |l| <= |... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_292.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 421 | 2d0aca443e1d6ddcd1274d489bb990df40a67ececc8363e722f8bdd6926e9a92 | method Quotient(a: int, b: int) returns (result: int)
requires b != 0
ensures result == a / b
{
result := a / b;
}
method QuotientTest(){
var res1:=Quotient(10,3);
print(res1);print("\n");
assert res1==3;
var res2:=Quotient(4,2);
print(res2);print("\n");
assert res2==2;
var res3:=Quot... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_3.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 611 | 85de2df8ba42057d64008f89d3c78bbb58086c0fa36f9d586e97514fc2c208d6 | method IsNonPrime(n: int) returns (result: bool)
requires n >= 2
ensures result <==> (exists k :: 2 <= k < n && n % k == 0)
{
result := false;
var i := 2;
while i <= n/2
invariant 2 <= i
invariant result <==> (exists k :: 2 <= k < i && n % k == 0)
{
if n % i == 0
{
result :... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_304.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 807 | ece3649bff712fbb040ae70b4aedb8d97d7c7df31b13a87786b9a07479ad11f7 | method ElementAtIndexAfterRotation(l: seq<int>, n: int, index: int) returns (element: int)
requires n >= 0
requires 0 <= index < |l|
ensures element == l[(index - n + |l|) % |l|]
{
element := l[(index - n + |l|) % |l|];
}
method ElementAtIndexAfterRotationTest(){
var a1:seq<int>:=[1, 2, 3, 4, 5];
... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_307.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 990 | e27de5d7033e812f5bc98b37d3498f4955104325d87cda4398d60d9a6ecac69f | method DeepCopySeq(s: seq<int>) returns (copy: seq<int>)
ensures |copy| == |s|
ensures forall i :: 0 <= i < |s| ==> copy[i] == s[i]
{
var newSeq: seq<int> := [];
for i := 0 to |s|
invariant 0 <= i <= |s|
invariant |newSeq| == i
invariant forall k :: 0 <= k < i ==> newSeq[k] == s[k]
{
... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_309.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 486 | 2d4de9783f9d57064a7e25ac20ac2952ff3907df3c1b75b84f4fdc4bb5dfe849 | method Max(a: int, b: int) returns (maxValue: int)
ensures maxValue == a || maxValue == b
ensures maxValue >= a && maxValue >= b
{
if a >= b {
maxValue := a;
} else {
maxValue := b;
}
}
method MaxTest(){
var res1:=Max(5,10);
print(res1);print("\n");
assert res1==10;
var res2:=M... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_310.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,091 | 0abcf6ecaeb1b742066255520e96bc785fc28c7ff2f037cdf831999b31d70538 | method ToCharArray(s: string) returns (a: array<char>)
ensures a.Length == |s|
ensures forall i :: 0 <= i < |s| ==> a[i] == s[i]
{
a := new char[|s|];
for i := 0 to |s|
invariant 0 <= i <= |s|
invariant a.Length == |s|
invariant forall k :: 0 <= k < i ==> a[k] == s[k]
{
a[i] := s[i];... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_312.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 693 | 65c3e093bf62a0b5fa28728b8464c297914a9b94e6c0a40cc3c1c558cae9a6e8 | method ConeVolume(radius: real, height: real) returns (volume: real)
requires radius > 0.0 && height > 0.0
ensures volume == (1.0/3.0) * (3.14159265358979323846) * radius * radius * height
{
volume := (1.0/3.0) * (3.14159265358979323846) * radius * radius * height;
}
method ConeVolumeTest(){
var res1:=... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_396.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 560 | dcf1724166d7a794f98ccdc1111affdac6f0cf2fae7b1ed2d49aba2b03320df7 | method StartAndEndWithSameChar(s: string) returns (result: bool)
requires |s| > 0
ensures result <==> s[0] == s[|s| - 1]
{
result := s[0] == s[|s| - 1];
}
method StartAndEndWithSameCharTest(){
var res1:=StartAndEndWithSameChar("abba");
print(res1);print("\n");
assert res1==true;
var res2:=... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_397.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 888 | ca7c6a07fcdb3158847508748cae6e73b09bf4e4ce4cc5b3964e3d191aa46a68 | method MedianOfThree(a: int, b: int, c: int) returns (median: int)
ensures median == a || median == b || median == c
ensures (median >= a && median <= b) || (median >= b && median <= a) || (median >= a && median <= c) || (median >= c && median <= a) || (median >= b && median <= c) || (median >= c && median <= b)
... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_399.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,054 | 326038be1c36250728391d74f1ef446a136ee6dcb9faef408ceb7a5964c9d066 | method BitwiseXOR(a: seq<bv32>, b: seq<bv32>) returns (result: seq<bv32>)
requires |a| == |b|
ensures |result| == |a|
ensures forall i :: 0 <= i < |result| ==> result[i] == a[i] ^ b[i]
{
result := [];
var i := 0;
while i < |a|
invariant 0 <= i <= |a|
invariant |result| == i
invariant f... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_401.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,861 | 7173ee284fe82affaf67b30157cbb6c45fdaf8d553df8a368783d84ab7be8b65 | method IndexWiseAddition(a: seq<seq<int>>, b: seq<seq<int>>) returns (result: seq<seq<int>>)
requires |a| > 0 && |b| > 0
requires |a| == |b|
requires forall i :: 0 <= i < |a| ==> |a[i]| == |b[i]|
ensures |result| == |a|
ensures forall i :: 0 <= i < |result| ==> |result[i]| == |a[i]|
ensures forall i :... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_404.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 410 | 4ca463ab60e6a054cdd7c6aab2c3f6f6d250f2790f6996e35e4c85514851b098 | method Min(a: int, b: int) returns (minValue: int)
ensures minValue == a || minValue == b
ensures minValue <= a && minValue <= b
{
if a <= b {
minValue := a;
} else {
minValue := b;
}
}
method MinTest(){
var out1:=Min(1,2);
assert out1==1;
var out2:=Min(-5,-4);
assert out2=... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_406.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 396 | aaa9dc77d0c80c46eae737369c3e5e7cac510fe771515fb3789c02836905d835 | method IsOdd(n: int) returns (result: bool)
ensures result <==> n % 2 == 1
{
result := n % 2 == 1;
}
method IsOddTest(){
var res1:=IsOdd(12);
print(res1);print("\n");
assert res1==false;
var res2:=IsOdd(7);
print(res2);print("\n");
assert res2==true;
var res3:=IsOdd(10);
print(res3);p... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_412.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,342 | 09a0dfd5ac6cd157539046c46917681ff017f58d16fe912ce4b17f0a6addc91a | /**
* Remove odd numbers from an array of numbers
**/
predicate IsEven(n: int)
{
n % 2 == 0
}
method RemoveOddNumbers(arr: array<int>) returns (evenList: seq<int>)
// All numbers in the output are even and exist in the input
ensures forall i :: 0 <= i < |evenList| ==> IsEven(evenList[i]) && evenL... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_414.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 972 | ecfb5615f173bd5ac9a51b1e4c83e348404af8b5cfc33fd98283635f9e61093a | method AnyValueExists(seq1: seq<int>, seq2: seq<int>) returns (result: bool)
ensures result <==> (exists i :: 0 <= i < |seq1| && seq1[i] in seq2)
{
result := false;
for i := 0 to |seq1|
invariant 0 <= i <= |seq1|
invariant result <==> (exists k :: 0 <= k < i && seq1[k] in seq2)
{
if seq1[i] ... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_424.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,039 | d477db53190e1806a980dfc6c321f1740f02ee6798a47dd6baebcb4abc2ebb5f | method ExtractRearChars(l: seq<string>) returns (r: seq<char>)
requires forall i :: 0 <= i < |l| ==> |l[i]| > 0
ensures |r| == |l|
ensures forall i :: 0 <= i < |l| ==> r[i] == l[i][|l[i]| - 1]
{
var rearChars: seq<char> := [];
for i := 0 to |l|
invariant 0 <= i <= |l|
invariant |rearChars| == ... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_426.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,374 | 4f1cd46b71eb325317e1f8cb30fd366f1e78bb83fbc416db0cbbbf9d1043715d | /**
* Filter odd numbers from an array of numbers
**/
predicate IsOdd(n: int)
{
n % 2 != 0
}
method FilterOddNumbers(arr: array<int>) returns (oddList: seq<int>)
// All numbers in the output are odd and exist in the input
ensures forall i :: 0 <= i < |oddList| ==> IsOdd(oddList[i]) && oddList[i] ... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_430.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 618 | c4ab8c7ffa57a4301b15232845d61edb5e405ce3da8f650c3dd8e2093ffb9605 | method ParabolaDirectrix(a: real, h: real, k: real) returns (directrix: real)
requires a != 0.0
ensures directrix == k - 1.0 / (4.0 * a)
{
directrix := k - 1.0 / (4.0 * a);
}
method ParabolaDirectrixTest(){
var res1:=ParabolaDirectrix(5.0,3.0,2.0);
print(res1);print("\n");
//asser... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_431.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,183 | 85f8e10aaee983ed577cfd833cfc5dd63203614e10851a87c5ff49e03ee3692e | method HasCommonElement(a: array<int>, b: array<int>) returns (result: bool)
requires a != null && b != null
ensures result ==> exists i, j :: 0 <= i < a.Length && 0 <= j < b.Length && a[i] == b[j]
ensures !result ==> forall i, j :: 0 <= i < a.Length && 0 <= j < b.Length ==> a[i] != b[j]
{
result := false;... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_432.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 409 | 3d83207916d359b33f9e2a3d9d5b8fc6e95e0d84affba47f0c42ba6c852fbebe | method MedianLength(a: int, b: int) returns (median: int)
requires a > 0 && b > 0
ensures median == (a + b) / 2
{
median := (a + b) / 2;
}
method MedianLengthTest(){
var res1:=MedianLength(15,25,35);
assert res1==20.0;
var res2:=MedianLength(10,20,30);
assert res2==15.0;
var res3:=Media... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_433.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 889 | 015ab3b16e886b3bef6677a00cfdb724fd8454bf3015b6f785f0bc9dbf6bdf4a | method IsGreater(n: int, a: array<int>) returns (result: bool)
requires a != null
ensures result ==> forall i :: 0 <= i < a.Length ==> n > a[i]
ensures !result ==> exists i :: 0 <= i < a.Length && n <= a[i]
{
result := true;
var i := 0;
while i < a.Length
invariant 0 <= i <= a.Length
invari... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_435.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 349 | 1cf989b4001515b3c4e5c40e633bac85fc4998369b75c3a8b23a31f233dd7e60 | method LastDigit(n: int) returns (d: int)
requires n >= 0
ensures 0 <= d < 10
ensures n % 10 == d
{
d := n % 10;
}
method LastDigitTest(){
var out1:=LastDigit(123);
assert out1==3;
var out2:=LastDigit(25);
assert out2==5;
var out3:=LastDigit(30);
assert out3==0;
}
method Mai... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_436.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,452 | e40b92e35f02e17f911f2666e8d7cb0747dfcfe1944877bf2d6198be85fd6d1c | /**
* Find negative numbers from an array of numbers
**/
predicate IsNegative(n: int)
{
n < 0
}
method FindNegativeNumbers(arr: array<int>) returns (negativeList: seq<int>)
// All numbers in the output are negative and exist in the input
ensures forall i :: 0 <= i < |negativeList| ==> IsNegative(... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_441.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 398 | 63c624f530fb1c32cc86cd404512289758c3e02b1abe2432141692b8b07b9f92 | method CubeSurfaceArea(size: int) returns (area: int)
requires size > 0
ensures area == 6 * size * size
{
area := 6 * size * size;
}
method CubeSurfaceAreaTest(){
var out1:=CubeSurfaceArea(5);
assert out1==150;
var out2:=CubeSurfaceArea(3);
assert out2==54;
var out3:=CubeSurfaceArea(1... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_445.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,198 | 4f081ba4e0bff3b2f940d813c709bcb6e895cf25d1c39c62e244ab60dd28a209 | method MultiplyElements(a: seq<int>, b: seq<int>) returns (result: seq<int>)
requires |a| == |b|
ensures |result| == |a|
ensures forall i :: 0 <= i < |result| ==> result[i] == a[i] * b[i]
{
result := [];
var i := 0;
while i < |a|
invariant 0 <= i <= |a|
invariant |result| == i
invarian... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_447.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,474 | 0959ec36e7c723cb45c2a4ad93dc47e47b6aa40888f48b120dd5eac258c59079 | method CubeElements(a: array<int>) returns (cubed: array<int>)
ensures cubed.Length == a.Length
ensures forall i :: 0 <= i < a.Length ==> cubed[i] == a[i] * a[i] * a[i]
{
var cubedArray := new int[a.Length];
for i := 0 to a.Length
invariant 0 <= i <= a.Length
invariant cubedArray.Length == a.Leng... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_452.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 748 | 91e642eff1cf56d9898af3e7be0bd9dd45c53ea0097d56a182036afea6f13aaf | method CalculateLoss(costPrice: int, sellingPrice: int) returns (loss: int)
requires costPrice >= 0 && sellingPrice >= 0
ensures (costPrice > sellingPrice ==> loss == costPrice - sellingPrice) && (costPrice <= sellingPrice ==> loss == 0)
{
if (costPrice > sellingPrice) {
loss := costPrice - sellingPrice;... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_454.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 633 | 8b6c3e918b4bece1b1bf602058b709b5617034cea0d735ac49b4c0744245cdb2 | method ContainsZ(s: string) returns (result: bool)
ensures result <==> (exists i :: 0 <= i < |s| && (s[i] == 'z' || s[i] == 'Z'))
{
result := false;
for i := 0 to |s|
invariant 0 <= i <= |s|
invariant result <==> (exists k :: 0 <= k < i && (s[k] == 'z' || s[k] == 'Z'))
{
if s[i] == 'z' || s[... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_455.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 533 | e8ecaef457a712a3fae915edd828ed925ae262bf07b6bf25ce2271a81f26690b | method MonthHas31Days(month: int) returns (result: bool)
requires 1 <= month <= 12
ensures result <==> month in {1, 3, 5, 7, 8, 10, 12}
{
result := month in {1, 3, 5, 7, 8, 10, 12};
}
method MonthHas31DaysTest(){
var res1:=MonthHas31Days(5);
print(res1);print("\n");
assert res1==true;
var re... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_457.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 991 | fa679b1c7d4472af4a8f94051718d2a23d93c14681e49da670635b9b41693ea2 | method MinLengthSublist(s: seq<seq<int>>) returns (minSublist: seq<int>)
requires |s| > 0
ensures minSublist in s
ensures forall sublist :: sublist in s ==> |minSublist| <= |sublist|
{
minSublist := s[0];
for i := 1 to |s|
invariant 0 <= i <= |s|
invariant minSublist in s[..i]
invariant f... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_458.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 514 | da2d4171ebea1ee8507953d01dd654bb2dac3d39f76e066d041c9dd0a4273538 | method RectangleArea(length: int, width: int) returns (area: int)
requires length > 0
requires width > 0
ensures area == length * width
{
area := length * width;
}
method RectangleAreaTest(){
var out1:=RectangleArea(10,20);
print(out1);print("\n");
assert out1==200;
var out2:=RectangleA... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_460.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 973 | 5a8671f265897c72b017671431135900a854ceb49de1265fa6301eefed0b34e2 | method GetFirstElements(lst: seq<seq<int>>) returns (result: seq<int>)
requires forall i :: 0 <= i < |lst| ==> |lst[i]| > 0
ensures |result| == |lst|
ensures forall i :: 0 <= i < |result| ==> result[i] == lst[i][0]
{
result := [];
for i := 0 to |lst|
invariant 0 <= i <= |lst|
invariant |result... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_461.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 695 | 41b140848b0365e34479f63a18712b31ba1db0efae3057cd625a47c7ec178a19 | predicate IsUpperCase(c: char)
{
65 <= c as int <= 90
}
method CountUppercase(s: string) returns (count: int)
ensures count >= 0
ensures count == | set i: int | 0 <= i < |s| && IsUpperCase(s[i])|
{
var uppercase := set i: int | 0 <= i < |s| && IsUpperCase(s[i]);
count := |uppercase|;
}
method C... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_470.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,109 | 57629fab6f20e131b74cff0949bcc884f8d21c07f80f14ecb943c7428abfcf99 | method PairwiseAddition(a: array<int>) returns (result: array<int>)
requires a != null
requires a.Length % 2 == 0
ensures result != null
ensures result.Length == a.Length / 2
ensures forall i :: 0 <= i < result.Length ==> result[i] == a[2*i] + a[2*i + 1]
{
result := new int[a.Length / 2];
var i :=... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_472.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 920 | a26c529390f85667218657b4363288fd36a75e64dcdb3d69f9d3c8b74a93d444 | method ContainsConsecutiveNumbers(a: array<int>) returns (result: bool)
requires a.Length>0
ensures result <==> (exists i :: 0 <= i < a.Length - 1 && a[i] + 1 == a[i + 1])
//ensures forall i :: 0 <= i < a.Length-1 ==> a[i] + 1 == a[i + 1]
{
result := false;
for i := 0 to a.Length - 1
invariant 0 ... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_474.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 892 | 5e19998f223b65b5bad35f1eb4383415ab17ac628c7237ef5a5370c87d278159 | method ReplaceChars(s: string, oldChar: char, newChar: char) returns (v: string)
ensures |v| == |s|
ensures forall i :: 0 <= i < |s| ==> (s[i] == oldChar ==> v[i] == newChar) && (s[i] != oldChar ==> v[i] == s[i])
{
var s' : string := [];
for i := 0 to |s|
invariant 0 <= i <= |s|
invariant |s'| ==... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_476.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,583 | 3be8351f37db425b699e91dcb4a37d8103d9b600b44142e7d87a480f8990041e | method SumMinMax(a: array<int>) returns (sum: int)
requires a.Length > 0
ensures sum == Max(a[..]) + Min(a[..])
{
var minVal := a[0];
var maxVal := a[0];
for i := 1 to a.Length
invariant 1 <= i <= a.Length
invariant minVal <= maxVal
invariant forall k :: 0 <= k < i ==> minVal <= a[k] &&... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_477.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,119 | daf40289c6ea62e604d5a76dfb62e059c85036bda553619c214fae8a4ba1468b | predicate IsUpperCase(c : char)
{
65 <= c as int <= 90
}
predicate IsUpperLowerPair(C : char, c : char)
{
(C as int) == (c as int) - 32
}
function Shift32(c : char) : char
{
((c as int + 32) % 128) as char
}
method ToLowercase(s: string) returns (v: string)
ensures |v| == |s|
ensures fora... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_554.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,324 | 06f9c26b4da258ad55a78801694d036090bf69a0816d336d30b9a35ff56b7dd7 | /**
* Find odd numbers from an array of numbers
**/
predicate IsOdd(n: int)
{
n % 2 == 1
}
method FindOddNumbers(arr: array<int>) returns (oddList: seq<int>)
// All numbers in the output are odd and exist in the input
ensures forall i :: 0 <= i < |oddList| ==> IsOdd(oddList[i]) && oddList[i] in a... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_555.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 901 | ae7ff864e6d9baac578181e039784766402e4d734980bfc55b3f0bbcecda3d49 | method DifferenceSumCubesAndSumNumbers(n: int) returns (diff: int)
requires n >= 0
ensures diff == (n * n * (n + 1) * (n + 1)) / 4 - (n * (n + 1)) / 2
{
var sumCubes := 0;
var sumNumbers := 0;
for i := 1 to n + 1
invariant 0 <= i <= n + 1
invariant sumCubes == (i - 1) * (i - 1) * i * i / 4
... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_557.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,695 | 27379c874c369a0f628868c12ea2dc39f1767d37475e26b8a01f7e7b61d59380 | predicate IsLowerCase(c : char)
{
97 <= c as int <= 122
}
predicate IsUpperCase(c : char)
{
65 <= c as int <= 90
}
predicate IsLowerUpperPair(c : char, C : char)
{
(c as int) == (C as int) + 32
}
predicate IsUpperLowerPair(C : char, c : char)
{
(C as int) == (c as int) - 32
}
function Sh... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_565.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 798 | a59585a09fe7e2773572414ff4bf8b64435d271763a7b1f236b20841af260394 | method SplitStringIntoChars(s: string) returns (v: seq<char>)
ensures |v| == |s|
ensures forall i :: 0 <= i < |s| ==> v[i] == s[i]
{
v := [];
for i := 0 to |s|
invariant 0 <= i <= |s|
invariant |v| == i
invariant forall k :: 0 <= k < i ==> v[k] == s[k]
{
v := v + [s[i]];
}
}
... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_566.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 4,578 | 0b666947e32585e99badaf97b5f44db3066c39889c71aa3b8752ebbc8d01478e | method SumOfDigits(number: nat) returns (sum: nat)
requires number >= 0
ensures sum >= 0
ensures sum == SumDigits(number)
{
sum := 0;
var n: nat := number;
// Let's find out the number of digits, which is the same as powers of ten for the given number
ghost var ndigits := NumberOfDigits(number);... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_567.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 951 | 53d873ec94e8b42005ee118c9be3e69d537f4bac39bd91e2cf43306dd4c7969b | method IsSorted(a: array<int>) returns (sorted: bool)
requires a.Length > 0
ensures sorted <== forall i, j :: 0 <= i < j < a.Length ==> a[i] <= a[j]
ensures !sorted ==> exists i, j :: 0 <= i < j < a.Length && a[i] > a[j]
{
sorted := true;
for i := 0 to a.Length - 1
invariant 0 <= i < a.Length
... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_572.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,092 | 744d22cddcc27868f83bde0a668a83d25a9d71e887172e565c22f30c4ff6f385 | method RemoveDuplicates(a: array<int>) returns (result: seq<int>)
requires a != null
ensures forall x :: x in result <==> exists i :: 0 <= i < a.Length && a[i] == x
ensures forall i, j :: 0 <= i < j < |result| ==> result[i] != result[j]
{
var res: seq<int> := [];
for i := 0 to a.Length
invariant 0 ... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_573.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,882 | a37e81bcdede46d5f5621140201aeb0aa5abace8e92b932e6df256eb2a56d030 | method UniqueProduct (arr: array<int>) returns (product: int)
ensures product == SetProduct((set i | 0 <= i < arr.Length :: arr[i]))
{
var p := 1;
var seen: set<int> := {};
for i := 0 to arr.Length
invariant 0 <= i <= arr.Length
invariant seen == (set k | 0 <= k < i :: arr[k])
invariant p ... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_574.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 716 | 2b93f48d009319232e2c668f47848796bf3fe26ba225f1a7abf19b3ad9e3088e | method CylinderSurfaceArea(radius: real, height: real) returns (area: real)
requires radius > 0.0 && height > 0.0
ensures area == 2.0 * 3.14159265358979323846 * radius * (radius + height)
{
area := 2.0 * 3.14159265358979323846 * radius * (radius + height);
}
method CylinderSurfaceAreaTest(){
var res1... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_576.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 894 | 38e5dddb0b3866b770bb87d71b041fa447900d94b0dcf240db616ef97a3878ce | method IsSublist(sub: seq<int>, main: seq<int>) returns (result: bool)
ensures true <== (exists i :: 0 <= i <= |main| - |sub| && sub == main[i..i + |sub|])
{
if |sub| > |main| {
return false;
}
for i := 0 to |main| - |sub| + 1
invariant 0 <= i <= |main| - |sub| + 1
invariant true <== (exis... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_577.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 714 | 6cd7716badf0e7b739ca96654edec7ca2696f0fb80acd47ee81be2b3f1689d70 | function Factorial(n: int): int
requires n >= 0
ensures 0 <= Factorial(n)
{
if n == 0 then 1
else n * Factorial(n-1)
}
method FactorialOfLastDigit(n: int) returns (fact: int)
requires n >= 0
ensures fact == Factorial(n % 10)
{
var lastDigit := n % 10;
fact := Factorial(lastDigit);
}
me... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_578.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,312 | 91ac5a74020fad03477aaaf412b0ed6856cc9ce2d7919b7d0eeb974be88aff98 | method Interleave(s1: seq<int>, s2: seq<int>, s3: seq<int>) returns (r: seq<int>)
requires |s1| == |s2| && |s2| == |s3|
ensures |r| == 3 * |s1|
ensures forall i :: 0 <= i < |s1| ==> r[3*i] == s1[i] && r[3*i + 1] == s2[i] && r[3*i + 2] == s3[i]
{
r := [];
for i := 0 to |s1|
invariant 0 <= i <= |s1|
... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_579.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,835 | 949155d9d9de5e7d14c6f4e37b0e359095e86e510db546a0334238efe534b4ca | predicate InArray(a: array<int>, x: int)
reads a
{
exists i :: 0 <= i < a.Length && a[i] == x
}
method DissimilarElements(a: array<int>, b: array<int>) returns (result: seq<int>)
// All elements in the output are either in a or b, but not in both or neither
ensures forall x :: x in result ==> (InArray(... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_58.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 445 | 504cda881ede6232e9cdf451d766a1f28a90aa1702bc21b7204905160f3e6042 | method HasOppositeSign(a: int, b: int) returns (result: bool)
ensures result <==> (a < 0 && b > 0) || (a > 0 && b < 0)
{
result := (a < 0 && b > 0) || (a > 0 && b < 0);
}
method HasOppositeSignTest(){
var out1:=HasOppositeSign(1,-2);
assert out1==true;
var out2:=HasOppositeSign(3,2);
assert out... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_581.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 676 | 50d21571931edd6b2649617ace44781be6f19ddd976e7edf8808f55a87875614 | method SquarePyramidSurfaceArea(baseEdge: int, height: int) returns (area: int)
requires baseEdge > 0
requires height > 0
ensures area == baseEdge * baseEdge + 2 * baseEdge * height
{
area := baseEdge * baseEdge + 2 * baseEdge * height;
}
method SquarePyramidSurfaceAreaTest(){
var res1:=SquarePyrami... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_586.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 816 | 28431503581c78c71a0521b8e048dd10d0acb908306c9972ec25042641253823 | method SplitAndAppend(l: seq<int>, n: int) returns (r: seq<int>)
requires n >= 0 && n < |l|
ensures |r| == |l|
ensures forall i :: 0 <= i < |l| ==> r[i] == l[(i + n) % |l|]
{
var firstPart: seq<int> := l[..n];
var secondPart: seq<int> := l[n..];
r := secondPart + firstPart;
}
method SplitAndAppen... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_587.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 873 | 64773f43d5522f71a702bdfb84c27fcf5ad8a2b867e3e0db4b15bc59dfa79105 | method ArrayToSeq(a: array<int>) returns (s: seq<int>)
requires a != null
ensures |s| == a.Length
ensures forall i :: 0 <= i < a.Length ==> s[i] == a[i]
{
s := [];
for i := 0 to a.Length
invariant 0 <= i <= a.Length
invariant |s| == i
invariant forall j :: 0 <= j < i ==> s[j] == a[j]
{... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_588.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,506 | 45b2626aa75166a30eb7b20ac67602f0575d7be32cee6860c2c1218a2cf139e0 | method DifferenceMinMax(a: array<int>) returns (diff: int)
requires a.Length > 0
ensures diff == Max(a[..]) - Min(a[..])
{
var minVal := a[0];
var maxVal := a[0];
for i := 1 to a.Length
invariant 1 <= i <= a.Length
invariant minVal <= maxVal
invariant forall k :: 0 <= k < i ==> minVal <... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_59.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 533 | 9f8e06b85619e5198b3772ed1998f3a1a8b43bed124a02b3925886ce886ed513 | method NthOctagonalNumber(n: int) returns (octagonalNumber: int)
requires n >= 0
ensures octagonalNumber == n * (3 * n - 2)
{
octagonalNumber := n * (3 * n - 2);
}
method NthOctagonalNumberTest() {
var res1:= NthOctagonalNumber(5);
print(res1);print("\n");
assert res1==65;
var res2:= NthOc... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_591.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 766 | 3695b300ad4ce5dd30cc924d1ea1b894aefbf8ae72ecc8f85c020332fa301ea1 | method SwapFirstAndLast(a: array<int>)
requires a != null && a.Length > 0
modifies a
ensures a[0] == old(a[a.Length - 1]) && a[a.Length - 1] == old(a[0])
ensures forall k :: 1 <= k < a.Length - 1 ==> a[k] == old(a[k])
{
var temp := a[0];
a[0] := a[a.Length - 1];
a[a.Length - 1] := temp;
}
meth... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_594.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,818 | 3b73c5cc1c0f7e4af55fd3ca64cf1d87a9253314c73a931aec15c36cffe3df89 | predicate IsEven(n: int)
{
n % 2 == 0
}
predicate IsOdd(n: int)
{
n % 2 != 0
}
method FirstEvenOddDifference(a: array<int>) returns (diff: int)
requires a.Length >= 2
requires exists i :: 0 <= i < a.Length && IsEven(a[i])
requires exists i :: 0 <= i < a.Length && IsOdd(a[i])
ensures exists i... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_598.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 690 | ef6a19a98cace702c92d159242bc25cfd8edb73e1fa06c235903fa6e2b59a0a6 | method IsArmstrong(n: int) returns (result: bool)
requires 100 <= n < 5000
ensures result <==> (n == ((n / 100) * (n / 100) * (n / 100) + ((n / 10) % 10) * ((n / 10) % 10) * ((n / 10) % 10) + (n % 10) * (n % 10) * (n % 10)))
{
var a := n / 100;
var b := (n / 10) % 10;
var c := n % 10;
result := n =... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_599.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 671 | d403e9da2717991358bfdd46d4738d4d3b6807f5d1446cefc77b5ef9c623a9d7 | method SumAndAverage(n: int) returns (sum: int, average: real)
requires n > 0
ensures sum == n * (n + 1) / 2
ensures average == sum as real / n as real
{
sum := 0;
for i := 1 to n + 1
invariant 0 <= i <= n + 1
invariant sum == (i - 1) * i / 2
{
sum := sum + i;
}
average := sum as... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_600.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 324 | 7e8332df90375270bfda309edbb6d862fcc2c77ba3545249ef6c4a3691a4373f | method IsEven(n: int) returns (result: bool)
ensures result <==> n % 2 == 0
{
result := n % 2 == 0;
}
method IsEvenTest(){
var out1:=IsEven(1);
assert out1==false;
var out2:=IsEven(2);
assert out2==true;
var out3:=IsEven(3);
assert out3==false;
}
method Main(){
IsEvenTest();
... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_602.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,708 | af54856f7446e7a07bb6688dd31c61202105e52b9f53274dcc837b1fdb70fb1c | method FindFirstRepeatedChar(s: string) returns (found: bool, c: char)
ensures found ==> exists i, j :: 0 <= i < j < |s| && s[i] == s[j] && s[i] == c && (forall k, l :: 0 <= k < l < j && s[k] == s[l] ==> k >= i)
ensures !found ==> (forall i, j :: 0 <= i < j < |s| ==> s[i] != s[j])
{
c := ' ';
found := fals... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_603.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,087 | 97af7bf61fcdfb298096ac92898147c3130a9f7d233badf007dc7d2de9d711b3 | method LucidNumbers(n: int) returns (lucid: seq<int>)
requires n >= 0
ensures forall i :: 0 <= i < |lucid| ==> lucid[i] % 3 == 0
ensures forall i :: 0 <= i < |lucid| ==> lucid[i] <= n
ensures forall i, j :: 0 <= i < j < |lucid| ==> lucid[i] < lucid[j]
{
lucid := [];
var i := 0;
while i <= n
i... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_605.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 595 | 6f7509b8a7665035144181cd60f43bf939c89b320b250ae10a74391733c45c71 | method IsPrime(n: int) returns (result: bool)
requires n >= 2
ensures result <==> (forall k :: 2 <= k < n ==> n % k != 0)
{
result := true;
var i := 2;
while i <= n/2
invariant 2 <= i
invariant result <==> (forall k :: 2 <= k < i ==> n % k != 0)
{
if n % i == 0
{
result := ... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_606.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 626 | e0cf44cdab47c7c82e4f796653ae1741823e9e93de7e8451729590c1ccbe4fac | method DegreesToRadians(degrees: real) returns (radians: real)
ensures radians == degrees * 3.14159265358979323846 / 180.0
{
radians := degrees * 3.14159265358979323846 / 180.0;
}
method DegreesToRadiansTest(){
var res1:=DegreesToRadians(90.0);
print(res1);print("\n");
//assert res1==1.5... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_61.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,255 | f0f61f5adc27353e1812576e2c77140619b3ef810573bc1b7f2d5d46015ed22a | predicate IsDigit(c: char)
{
48 <= c as int <= 57
}
method CountSubstringsWithSumOfDigitsEqualToLength(s: string) returns (count: int)
ensures count >= 0
{
count := 0;
for i := 0 to |s|
invariant 0 <= i <= |s|
{
var sum := 0;
for j := i to |s|
invar... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_610.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,788 | c06a934c1d1080299f59320d98b9faa74a2b5b56f1021f2231f234c3d8ba29f0 | method RemoveElement(s: array<int>, k: int) returns (v: array<int>)
requires 0 <= k < s.Length
ensures v.Length == s.Length - 1
ensures forall i :: 0 <= i < k ==> v[i] == s[i]
ensures forall i :: k <= i < v.Length ==> v[i] == s[i + 1]
{
v := new int[s.Length - 1];
var i := 0;
while i < k
inva... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_616.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,714 | 92bbf84bad51c227a6c739102fb31b3520a9316f60f6ad34be03357cd21fe2f2 | method ElementWiseModulo(a: array<int>, b: array<int>) returns (result: array<int>)
requires a != null && b != null
requires a.Length == b.Length
requires forall i :: 0 <= i < b.Length ==> b[i] != 0
ensures result != null
ensures result.Length == a.Length
ensures forall i :: 0 <= i < result.Length ==>... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_618.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,061 | 2cca39b496ceb28f357f4e8dd18e6b3ff7048fbf79e6a28ac86407deec826b50 | method ElementWiseDivide(a: seq<int>, b: seq<int>) returns (result: seq<int>)
requires |a| == |b|
requires forall i :: 0 <= i < |b| ==> b[i] != 0
ensures |result| == |a|
ensures forall i :: 0 <= i < |result| ==> result[i] == a[i] / b[i]
{
result := [];
for i := 0 to |a|
invariant 0 <= i <= |a|
... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_62.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 797 | baab649aacebd6ba88bfca76cdf86f8f8630691b09865106644e0845ac5dc35f | method FindSmallest(s: array<int>) returns (min: int)
requires s.Length > 0
ensures forall i :: 0 <= i < s.Length ==> min <= s[i]
ensures exists i :: 0 <= i < s.Length && min == s[i]
{
min := s[0];
for i := 1 to s.Length
invariant 0 <= i <= s.Length
invariant forall k :: 0 <= k < i ==> min <= ... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_622.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,038 | 52f0f6367498dc4d2162db9cf5bc87a351861a30b57e64d6a2e536d7b7fdcd8b | method FindMedian(a: array<int>, b: array<int>) returns (median: int)
requires a != null && b != null
requires a.Length == b.Length
requires a.Length > 0
requires forall i :: 0 <= i < a.Length - 1 ==> a[i] <= a[i + 1]
requires forall i :: 0 <= i < b.Length - 1 ==> b[i] <= b[i + 1]
ensures ... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_623.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,138 | 51bb316a85ab13172b3b810b7b1de83a05ad2ca9c786feace26800cc335b0306 | method PowerOfListElements(l: seq<int>, n: int) returns (result: seq<int>)
requires n >= 0
ensures |result| == |l|
ensures forall i :: 0 <= i < |l| ==> result[i] == Power(l[i], n)
{
result := [];
for i := 0 to |l|
invariant 0 <= i <= |l|
invariant |result| == i
invariant forall k :: 0 <= ... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_624.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,124 | c713ad441d8b8db9be1d1e2ec0a1a1145d64adff2c49f745215cfd833dc1d7c5 | predicate IsLowerCase(c : char)
{
97 <= c as int <= 122
}
predicate IsLowerUpperPair(c : char, C : char)
{
(c as int) == (C as int) + 32
}
function ShiftMinus32(c : char) : char
{
((c as int - 32) % 128) as char
}
method ToUppercase(s: string) returns (v: string)
ensures |v| == |s|
ensure... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_625.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,213 | 4c5fa3e084b49b90238dc50f0a71df059ff1cd651b4650c694b17cfbe9c6207a | method SwapFirstAndLast(a: array<int>)
requires a.Length > 0
modifies a
ensures a[0] == old(a[a.Length - 1])
ensures a[a.Length - 1] == old(a[0])
ensures forall k :: 1 <= k < a.Length - 1 ==> a[k] == old(a[k])
{
var tmp := a[0];
a[0] := a[a.Length - 1];
a[a.Length - 1] := tmp;
}
method asse... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_626.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 628 | 756694b31c9fc569703bfb4a0c4497b2c246e507495195a3cb8f5274307a5159 | method AreaOfLargestTriangleInSemicircle(radius: int) returns (area: int)
requires radius > 0
ensures area == radius * radius
{
area := radius * radius;
}
method AreaOfLargestTriangleInSemicircleTest(){
var res1:=AreaOfLargestTriangleInSemicircle(1);
print(res1);print("\n");
//assert ... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_627.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,109 | cb2033975fb493851f8b6c22803ed22c8418ab0f5b0073c2c61b34a011c5d1ea | /**
* Find the smallest missing number from a sorted list of natural numbers.
*/
method SmallestMissingNumber(s: seq<int>) returns (v: int)
requires forall i, j :: 0 <= i < j < |s| ==> s[i] <= s[j]
requires forall i :: 0 <= i < |s| ==> s[i] >= 0
ensures 0 <= v
ensures v !in s
ensures forall k :: 0... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_629.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,180 | c374983bf67c8ff5bc3ec0d4c7d0009fa23098c8dad2288264042440c3263903 | predicate IsEven(n: int)
{
n % 2 == 0
}
method FindEvenNumbers(arr: array<int>) returns (evenList: seq<int>)
// All numbers in the output are even and exist in the input
ensures forall i :: 0 <= i < |evenList| ==> IsEven(evenList[i]) && evenList[i] in arr[..]
// All even numbers in the input are in the... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_632.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 4,032 | 3147ca3adf9ab561e3ccb6f3067b52782479f7dc395fab99d8abc7d9161aced8 | method MoveZeroesToEnd(arr: array<int>)
requires arr.Length >= 2
modifies arr
// Same size
ensures arr.Length == old(arr.Length)
// Zeros to the right of the first zero
ensures forall i, j :: 0 <= i < j < arr.Length && arr[i] == 0 ==> arr[j] == 0
// The final array is a permutation of the original ... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_637.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 567 | cdf179de8da673c48d6b0fcf191c3c07f2a226d0e307240efa7d2588ba4f47a7 | method IsBreakEven(costPrice: int, sellingPrice: int) returns (result: bool)
requires costPrice >= 0 && sellingPrice >= 0
ensures result <==> costPrice == sellingPrice
{
result := costPrice == sellingPrice;
}
method IsBreakEvenTest(){
var res1:=IsBreakEven(1500,1200);
print(res1);print("\n");
... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_641.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 514 | a8cdd0df2699274b8e8781acb50b6a07519e3d374edd9bf84466977a8ad4f381 | method NthNonagonalNumber(n: int) returns (number: int)
requires n >= 0
ensures number == n * (7 * n - 5) / 2
{
number := n * (7 * n - 5) / 2;
}
method NthNonagonalNumberTest(){
var res1:= NthNonagonalNumber(10);
print(res1);print("\n");
assert res1==325;
var res2:= NthNonagonalNumber(15);
... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_644.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,953 | fd97080ce972041fd60f55996865ae1db016a96df683a6606f595d6a030956db | method Reverse(a: array<int>)
modifies a;
ensures forall k :: 0 <= k < a.Length ==> a[k] == old(a[(a.Length-1) - k]);
{
var l := a.Length - 1;
var i := 0;
while (i < l-i)
invariant 0 <= i <= (l+1)/2;
invariant forall k :: 0 <= k < i || l-i < k <= l ==> a[k] == old(a[l-k]);
invariant foral... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_69.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 894 | 5bca6ea5787af1b8dc9782b75007e42ceecfa919973ced5be73f00e47c37d5e4 | method ContainsSequence(list: seq<seq<int>>, sub: seq<int>) returns (result: bool)
ensures result <==> (exists i :: 0 <= i < |list| && sub == list[i])
{
result := false;
for i := 0 to |list|
invariant 0 <= i <= |list|
invariant result <==> (exists k :: 0 <= k < i && sub == list[k])
{
if sub ... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_70.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,086 | 96763dab581e25a02d8b81622ac56fa5357f017994e53c7a853479bab6d160f0 | method AllSequencesEqualLength(sequences: seq<seq<int>>) returns (result: bool)
ensures result <==> forall i, j :: 0 <= i < |sequences| && 0 <= j < |sequences| ==> |sequences[i]| == |sequences[j]|
{
if |sequences| == 0 {
return true;
}
var firstLength := |sequences[0]|;
result := tr... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_728.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 960 | c7094583384a691f8f74aa79bb0066a46a919bf7fbe242341e6c02cb5112882d | method AddLists(a: seq<int>, b: seq<int>) returns (result: seq<int>)
requires |a| == |b|
ensures |result| == |a|
ensures forall i :: 0 <= i < |result| ==> result[i] == a[i] + b[i]
{
result := [];
for i := 0 to |a|
invariant 0 <= i <= |a|
invariant |result| == i
invariant forall k :: 0 <= ... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_732.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,062 | c53560600467e607974ea1cf1f3e43c100faeefd830318f85b1664a98495fa70 | predicate IsSpaceCommaDot(c: char)
{
c == ' ' || c == ',' || c == '.'
}
method ReplaceWithColon(s: string) returns (v: string)
ensures |v| == |s|
ensures forall i :: 0 <= i < |s| ==> (IsSpaceCommaDot(s[i]) ==> v[i] == ':') && (!IsSpaceCommaDot(s[i]) ==> v[i] == s[i])
{
var s' : string := [];
for i ... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_733.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 1,245 | 41361049aefae690ea7216cfe3832d6e40a763c7d81dba0f95bdaeabc2f70205 | method FindFirstOccurrence(arr: array<int>, target: int) returns (index: int)
requires arr != null
requires forall i, j :: 0 <= i < j < arr.Length ==> arr[i] <= arr[j]
ensures 0 <= index < arr.Length ==> arr[index] == target
ensures index == -1 ==> forall i :: 0 <= i < arr.Length ==> arr[i] != target
ens... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_741.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 836 | eefce38f2f2671d15e6119324f351cf4af0f76389ad866f0f55252dd482dce41 | method AllCharactersSame(s: string) returns (result: bool)
ensures result ==> forall i, j :: 0 <= i < |s| && 0 <= j < |s| ==> s[i] == s[j]
ensures !result ==> (|s| > 1) && (exists i, j :: 0 <= i < |s| && 0 <= j < |s| && i != j && s[i] != s[j])
{
if |s| <= 1 {
return true;
}
var firstChar := s[0];... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_743.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 943 | 88a835725557e3565a0dfbb3b43cf2ad898de80ba905cd761f648fc961be3363 | method RotateRight(l: seq<int>, n: int) returns (r: seq<int>)
requires n >= 0
ensures |r| == |l|
ensures forall i :: 0 <= i < |l| ==> r[i] == l[(i - n + |l|) % |l|]
{
var rotated: seq<int> := [];
for i := 0 to |l|
invariant 0 <= i <= |l|
invariant |rotated| == i
invariant forall k :: 0 <=... |
Mondego/dafny-synthesis | MBPP-DFY-153/test/task_id_750.dfy | GPL-3.0 | 57 | master | 4a06e8b09f48825458458aeacbe1622c26df4461 | 2024-06-09T21:49:08Z | 842 | b336696dbb281a66592e56917ea0948653285fbd1dacd90d994523a5791e7b6e | method AddTupleToList(l: seq<(int, int)>, t: (int, int)) returns (r: seq<(int, int)>)
ensures |r| == |l| + 1
ensures r[|r| - 1] == t
ensures forall i :: 0 <= i < |l| ==> r[i] == l[i]
{
r := l + [t];
}
method AddTupleToListTest(){
var s1: seq<(int,int)> := [(5, 6)];
var s2: (int,int):= (9, 10);
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.