test_ID
stringlengths
3
3
test_file
stringlengths
14
119
ground_truth
stringlengths
70
28.7k
hints_removed
stringlengths
58
28.7k
500
dafny-synthesis_task_id_135.dfy
method NthHexagonalNumber(n: int) returns (hexNum: int) requires n >= 0 ensures hexNum == n * ((2 * n) - 1) { hexNum := n * ((2 * n) - 1); }
method NthHexagonalNumber(n: int) returns (hexNum: int) requires n >= 0 ensures hexNum == n * ((2 * n) - 1) { hexNum := n * ((2 * n) - 1); }
501
dafny-synthesis_task_id_139.dfy
method CircleCircumference(radius: real) returns (circumference: real) requires radius > 0.0 ensures circumference == 2.0 * 3.14159265358979323846 * radius { circumference := 2.0 * 3.14159265358979323846 * radius; }
method CircleCircumference(radius: real) returns (circumference: real) requires radius > 0.0 ensures circumference == 2.0 * 3.14159265358979323846 * radius { circumference := 2.0 * 3.14159265358979323846 * radius; }
502
dafny-synthesis_task_id_14.dfy
method TriangularPrismVolume(base: int, height: int, length: int) returns (volume: int) requires base > 0 requires height > 0 requires length > 0 ensures volume == (base * height * length) / 2 { volume := (base * height * length) / 2; }
method TriangularPrismVolume(base: int, height: int, length: int) returns (volume: int) requires base > 0 requires height > 0 requires length > 0 ensures volume == (base * height * length) / 2 { volume := (base * height * length) / 2; }
503
dafny-synthesis_task_id_142.dfy
method CountIdenticalPositions(a: seq<int>, b: seq<int>, c: seq<int>) returns (count: int) requires |a| == |b| && |b| == |c| ensures count >= 0 ensures count == | set i: int | 0 <= i < |a| && a[i] == b[i] && b[i] == c[i]| { var identical := set i: int | 0 <= i < |a| && a[i] == b[i] && b[i] == c[i]; ...
method CountIdenticalPositions(a: seq<int>, b: seq<int>, c: seq<int>) returns (count: int) requires |a| == |b| && |b| == |c| ensures count >= 0 ensures count == | set i: int | 0 <= i < |a| && a[i] == b[i] && b[i] == c[i]| { var identical := set i: int | 0 <= i < |a| && a[i] == b[i] && b[i] == c[i]; ...
504
dafny-synthesis_task_id_143.dfy
method CountArrays(arrays: seq<array<int>>) returns (count: int) ensures count >= 0 ensures count == |arrays| { count := |arrays|; }
method CountArrays(arrays: seq<array<int>>) returns (count: int) ensures count >= 0 ensures count == |arrays| { count := |arrays|; }
505
dafny-synthesis_task_id_145.dfy
method MaxDifference(a: array<int>) returns (diff: int) requires a.Length > 1 ensures forall i, j :: 0 <= i < a.Length && 0 <= j < a.Length ==> a[i] - a[j] <= diff { var minVal := a[0]; var maxVal := a[0]; for i := 1 to a.Length invariant 1 <= i <= a.Length invariant minVal <= maxVa...
method MaxDifference(a: array<int>) returns (diff: int) requires a.Length > 1 ensures forall i, j :: 0 <= i < a.Length && 0 <= j < a.Length ==> a[i] - a[j] <= diff { var minVal := a[0]; var maxVal := a[0]; for i := 1 to a.Length { if a[i] < minVal { minVal := a[i]; }...
506
dafny-synthesis_task_id_161.dfy
predicate InArray(a: array<int>, x: int) reads a { exists i :: 0 <= i < a.Length && a[i] == x } method RemoveElements(a: array<int>, b: array<int>) returns (result: seq<int>) // All elements in the output are in a and not in b ensures forall x :: x in result ==> InArray(a, x) && !InArray(b, x) // T...
predicate InArray(a: array<int>, x: int) reads a { exists i :: 0 <= i < a.Length && a[i] == x } method RemoveElements(a: array<int>, b: array<int>) returns (result: seq<int>) // All elements in the output are in a and not in b ensures forall x :: x in result ==> InArray(a, x) && !InArray(b, x) // T...
507
dafny-synthesis_task_id_17.dfy
method SquarePerimeter(side: int) returns (perimeter: int) requires side > 0 ensures perimeter == 4 * side { perimeter := 4 * side; }
method SquarePerimeter(side: int) returns (perimeter: int) requires side > 0 ensures perimeter == 4 * side { perimeter := 4 * side; }
508
dafny-synthesis_task_id_170.dfy
function sumTo( a:array<int>, start:int, end:int ) : int requires a != null; requires 0 <= start && start <= end && end <= a.Length; decreases end; reads a; { if (start == end) then 0 else sumTo(a, start, end-1) + a[end-1] } method SumInRange(a: array<int>, start: int, end: int) ret...
function sumTo( a:array<int>, start:int, end:int ) : int requires a != null; requires 0 <= start && start <= end && end <= a.Length; reads a; { if (start == end) then 0 else sumTo(a, start, end-1) + a[end-1] } method SumInRange(a: array<int>, start: int, end: int) returns (sum: int) ...
509
dafny-synthesis_task_id_171.dfy
method PentagonPerimeter(side: int) returns (perimeter: int) requires side > 0 ensures perimeter == 5 * side { perimeter := 5 * side; }
method PentagonPerimeter(side: int) returns (perimeter: int) requires side > 0 ensures perimeter == 5 * side { perimeter := 5 * side; }
510
dafny-synthesis_task_id_18.dfy
method RemoveChars(s1: string, s2: string) returns (v: string) ensures |v| <= |s1| ensures forall i :: 0 <= i < |v| ==> (v[i] in s1) && !(v[i] in s2) ensures forall i :: 0 <= i < |s1| ==> (s1[i] in s2) || (s1[i] in v) { var v' : string := []; for i := 0 to |s1| invariant 0 <= i <= |s1| invar...
method RemoveChars(s1: string, s2: string) returns (v: string) ensures |v| <= |s1| ensures forall i :: 0 <= i < |v| ==> (v[i] in s1) && !(v[i] in s2) ensures forall i :: 0 <= i < |s1| ==> (s1[i] in s2) || (s1[i] in v) { var v' : string := []; for i := 0 to |s1| { if !(s1[i] in s2) ...
511
dafny-synthesis_task_id_2.dfy
predicate InArray(a: array<int>, x: int) reads a { exists i :: 0 <= i < a.Length && a[i] == x } method SharedElements(a: array<int>, b: array<int>) returns (result: seq<int>) // All elements in the output are in both a and b ensures forall x :: x in result ==> (InArray(a, x) && InArray(b, x)) // Th...
predicate InArray(a: array<int>, x: int) reads a { exists i :: 0 <= i < a.Length && a[i] == x } method SharedElements(a: array<int>, b: array<int>) returns (result: seq<int>) // All elements in the output are in both a and b ensures forall x :: x in result ==> (InArray(a, x) && InArray(b, x)) // Th...
512
dafny-synthesis_task_id_227.dfy
method MinOfThree(a: int, b: int, c: int) returns (min: int) ensures min <= a && min <= b && min <= c ensures (min == a) || (min == b) || (min == c) { if (a <= b && a <= c) { min := a; } else if (b <= a && b <= c) { min := b; } else { min := c; } }
method MinOfThree(a: int, b: int, c: int) returns (min: int) ensures min <= a && min <= b && min <= c ensures (min == a) || (min == b) || (min == c) { if (a <= b && a <= c) { min := a; } else if (b <= a && b <= c) { min := b; } else { min := c; } }
513
dafny-synthesis_task_id_230.dfy
method ReplaceBlanksWithChar(s: string, ch: char) returns (v: string) ensures |v| == |s| ensures forall i :: 0 <= i < |s| ==> (s[i] == ' ' ==> v[i] == ch) && (s[i] != ' ' ==> v[i] == s[i]) { var s' : string := []; for i := 0 to |s| invariant 0 <= i <= |s| invariant |s'| == i invariant forall...
method ReplaceBlanksWithChar(s: string, ch: char) returns (v: string) ensures |v| == |s| ensures forall i :: 0 <= i < |s| ==> (s[i] == ' ' ==> v[i] == ch) && (s[i] != ' ' ==> v[i] == s[i]) { var s' : string := []; for i := 0 to |s| { if s[i] == ' ' { s' := s' + [ch]; ...
514
dafny-synthesis_task_id_233.dfy
method CylinderLateralSurfaceArea(radius: real, height: real) returns (area: real) requires radius > 0.0 && height > 0.0 ensures area == 2.0 * (radius * height) * 3.14 { area := 2.0 * (radius * height) * 3.14; }
method CylinderLateralSurfaceArea(radius: real, height: real) returns (area: real) requires radius > 0.0 && height > 0.0 ensures area == 2.0 * (radius * height) * 3.14 { area := 2.0 * (radius * height) * 3.14; }
515
dafny-synthesis_task_id_234.dfy
method CubeVolume(size: int) returns (volume: int) requires size > 0 ensures volume == size * size * size { volume := size * size * size; }
method CubeVolume(size: int) returns (volume: int) requires size > 0 ensures volume == size * size * size { volume := size * size * size; }
516
dafny-synthesis_task_id_238.dfy
method CountNonEmptySubstrings(s: string) returns (count: int) ensures count >= 0 ensures count == (|s| * (|s| + 1)) / 2 // Formula for the number of non-empty substrings of a string { count := (|s| * (|s| + 1)) / 2; }
method CountNonEmptySubstrings(s: string) returns (count: int) ensures count >= 0 ensures count == (|s| * (|s| + 1)) / 2 // Formula for the number of non-empty substrings of a string { count := (|s| * (|s| + 1)) / 2; }
517
dafny-synthesis_task_id_240.dfy
method ReplaceLastElement(first: seq<int>, second: seq<int>) returns (result: seq<int>) requires |first| > 0 ensures |result| == |first| - 1 + |second| ensures forall i :: 0 <= i < |first| - 1 ==> result[i] == first[i] ensures forall i :: |first| - 1 <= i < |result| ==> result[i] == second[i - |first| +...
method ReplaceLastElement(first: seq<int>, second: seq<int>) returns (result: seq<int>) requires |first| > 0 ensures |result| == |first| - 1 + |second| ensures forall i :: 0 <= i < |first| - 1 ==> result[i] == first[i] ensures forall i :: |first| - 1 <= i < |result| ==> result[i] == second[i - |first| +...
518
dafny-synthesis_task_id_242.dfy
method CountCharacters(s: string) returns (count: int) ensures count >= 0 ensures count == |s| { count := |s|; }
method CountCharacters(s: string) returns (count: int) ensures count >= 0 ensures count == |s| { count := |s|; }
519
dafny-synthesis_task_id_249.dfy
predicate InArray(a: array<int>, x: int) reads a { exists i :: 0 <= i < a.Length && a[i] == x } method Intersection(a: array<int>, b: array<int>) returns (result: seq<int>) // All elements in the output are in both a and b ensures forall x :: x in result ==> (InArray(a, x) && InArray(b, x)) // The ...
predicate InArray(a: array<int>, x: int) reads a { exists i :: 0 <= i < a.Length && a[i] == x } method Intersection(a: array<int>, b: array<int>) returns (result: seq<int>) // All elements in the output are in both a and b ensures forall x :: x in result ==> (InArray(a, x) && InArray(b, x)) // The ...
520
dafny-synthesis_task_id_251.dfy
method InsertBeforeEach(s: seq<string>, x: string) returns (v: seq<string>) ensures |v| == 2 * |s| ensures forall i :: 0 <= i < |s| ==> v[2*i] == x && v[2*i + 1] == s[i] { v := []; for i := 0 to |s| invariant 0 <= i <= |s| invariant |v| == 2 * i in...
method InsertBeforeEach(s: seq<string>, x: string) returns (v: seq<string>) ensures |v| == 2 * |s| ensures forall i :: 0 <= i < |s| ==> v[2*i] == x && v[2*i + 1] == s[i] { v := []; for i := 0 to |s| { v := v + [x, s[i]]; } }
521
dafny-synthesis_task_id_257.dfy
method Swap(a: int, b: int) returns (result: seq<int>) ensures |result| == 2 ensures result[0] == b ensures result[1] == a { result := [b, a]; }
method Swap(a: int, b: int) returns (result: seq<int>) ensures |result| == 2 ensures result[0] == b ensures result[1] == a { result := [b, a]; }
522
dafny-synthesis_task_id_261.dfy
method ElementWiseDivision(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 := []; var i := 0; while i < |a| inv...
method ElementWiseDivision(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 := []; var i := 0; while i < |a| { ...
523
dafny-synthesis_task_id_262.dfy
method SplitArray(arr: array<int>, L: int) returns (firstPart: seq<int>, secondPart: seq<int>) requires 0 <= L <= arr.Length ensures |firstPart| == L ensures |secondPart| == arr.Length - L ensures firstPart + secondPart == arr[..] { firstPart := arr[..L]; secondPart := arr[L..]; }
method SplitArray(arr: array<int>, L: int) returns (firstPart: seq<int>, secondPart: seq<int>) requires 0 <= L <= arr.Length ensures |firstPart| == L ensures |secondPart| == arr.Length - L ensures firstPart + secondPart == arr[..] { firstPart := arr[..L]; secondPart := arr[L..]; }
524
dafny-synthesis_task_id_264.dfy
method DogYears(humanYears: int) returns (dogYears: int) requires humanYears >= 0 ensures dogYears == 7 * humanYears { dogYears := 7 * humanYears; }
method DogYears(humanYears: int) returns (dogYears: int) requires humanYears >= 0 ensures dogYears == 7 * humanYears { dogYears := 7 * humanYears; }
525
dafny-synthesis_task_id_266.dfy
method LateralSurfaceArea(size: int) returns (area: int) requires size > 0 ensures area == 4 * size * size { area := 4 * size * size; }
method LateralSurfaceArea(size: int) returns (area: int) requires size > 0 ensures area == 4 * size * size { area := 4 * size * size; }
526
dafny-synthesis_task_id_267.dfy
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 { ...
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 { sum := sum + i * i; i := i + 2; } }
527
dafny-synthesis_task_id_268.dfy
method StarNumber(n: int) returns (star: int) requires n >= 0 ensures star == 6 * n * (n - 1) + 1 { star := 6 * n * (n - 1) + 1; }
method StarNumber(n: int) returns (star: int) requires n >= 0 ensures star == 6 * n * (n - 1) + 1 { star := 6 * n * (n - 1) + 1; }
528
dafny-synthesis_task_id_269.dfy
method AsciiValue(c: char) returns (ascii: int) ensures ascii == c as int { ascii := c as int; }
method AsciiValue(c: char) returns (ascii: int) ensures ascii == c as int { ascii := c as int; }
529
dafny-synthesis_task_id_273.dfy
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 ...
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| { result := result + [a[i] - b[i]]; i := i + ...
530
dafny-synthesis_task_id_276.dfy
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 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; }
531
dafny-synthesis_task_id_279.dfy
method NthDecagonalNumber(n: int) returns (decagonal: int) requires n >= 0 ensures decagonal == 4 * n * n - 3 * n { decagonal := 4 * n * n - 3 * n; }
method NthDecagonalNumber(n: int) returns (decagonal: int) requires n >= 0 ensures decagonal == 4 * n * n - 3 * n { decagonal := 4 * n * n - 3 * n; }
532
dafny-synthesis_task_id_282.dfy
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 ...
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 ...
533
dafny-synthesis_task_id_284.dfy
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 ...
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 { if a[i] != n { res...
534
dafny-synthesis_task_id_290.dfy
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] ==>...
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| { if |lists[i]| > |maxList| { maxList := lists[i]; } ...
535
dafny-synthesis_task_id_292.dfy
method Quotient(a: int, b: int) returns (result: int) requires b != 0 ensures result == a / b { result := a / b; }
method Quotient(a: int, b: int) returns (result: int) requires b != 0 ensures result == a / b { result := a / b; }
536
dafny-synthesis_task_id_3.dfy
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 ...
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 { if n % i == 0 { result := true; break; } i := i + 1; } }
537
dafny-synthesis_task_id_304.dfy
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 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|]; }
538
dafny-synthesis_task_id_307.dfy
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[...
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| { newSeq := newSeq + [s[i]]; } return newSeq; }
539
dafny-synthesis_task_id_309.dfy
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 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; } }
540
dafny-synthesis_task_id_310.dfy
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...
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| { a[i] := s[i]; } }
541
dafny-synthesis_task_id_312.dfy
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 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; }
542
dafny-synthesis_task_id_396.dfy
method StartAndEndWithSameChar(s: string) returns (result: bool) requires |s| > 0 ensures result <==> s[0] == s[|s| - 1] { result := s[0] == s[|s| - 1]; }
method StartAndEndWithSameChar(s: string) returns (result: bool) requires |s| > 0 ensures result <==> s[0] == s[|s| - 1] { result := s[0] == s[|s| - 1]; }
543
dafny-synthesis_task_id_397.dfy
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...
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...
544
dafny-synthesis_task_id_399.dfy
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 ...
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| { result := result + [a[i] ^ b[i]]; i := i + 1; ...
545
dafny-synthesis_task_id_401.dfy
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 fora...
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 fora...
546
dafny-synthesis_task_id_404.dfy
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 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; } }
547
dafny-synthesis_task_id_406.dfy
method IsOdd(n: int) returns (result: bool) ensures result <==> n % 2 == 1 { result := n % 2 == 1; }
method IsOdd(n: int) returns (result: bool) ensures result <==> n % 2 == 1 { result := n % 2 == 1; }
548
dafny-synthesis_task_id_412.dfy
/** * 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]) && evenList[i]...
/** * 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]) && evenList[i]...
549
dafny-synthesis_task_id_414.dfy
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) { ...
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| { if seq1[i] in seq2 { result := true; break; } } }
550
dafny-synthesis_task_id_424.dfy
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 |rear...
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| { rearChars := rearChars + [l[i][|l[i]| - 1...
551
dafny-synthesis_task_id_426.dfy
/** * 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] in arr...
/** * 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] in arr...
552
dafny-synthesis_task_id_430.dfy
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 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); }
553
dafny-synthesis_task_id_431.dfy
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 := fal...
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 := fal...
554
dafny-synthesis_task_id_432.dfy
method MedianLength(a: int, b: int) returns (median: int) requires a > 0 && b > 0 ensures median == (a + b) / 2 { median := (a + b) / 2; }
method MedianLength(a: int, b: int) returns (median: int) requires a > 0 && b > 0 ensures median == (a + b) / 2 { median := (a + b) / 2; }
555
dafny-synthesis_task_id_433.dfy
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 ...
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 { if n <= a[i] { ...
556
dafny-synthesis_task_id_435.dfy
method LastDigit(n: int) returns (d: int) requires n >= 0 ensures 0 <= d < 10 ensures n % 10 == d { d := n % 10; }
method LastDigit(n: int) returns (d: int) requires n >= 0 ensures 0 <= d < 10 ensures n % 10 == d { d := n % 10; }
557
dafny-synthesis_task_id_436.dfy
/** * 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(negati...
/** * 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(negati...
558
dafny-synthesis_task_id_441.dfy
method CubeSurfaceArea(size: int) returns (area: int) requires size > 0 ensures area == 6 * size * size { area := 6 * size * size; }
method CubeSurfaceArea(size: int) returns (area: int) requires size > 0 ensures area == 6 * size * size { area := 6 * size * size; }
559
dafny-synthesis_task_id_445.dfy
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 ...
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| { result := result + [a[i] * b[i]]; i := i + 1...
560
dafny-synthesis_task_id_447.dfy
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 ...
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 { cubedArray[i] := a[i] * a[i] * a[i]; } return cubed...
561
dafny-synthesis_task_id_452.dfy
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 - sellingP...
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 - sellingP...
562
dafny-synthesis_task_id_454.dfy
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] ...
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| { if s[i] == 'z' || s[i] == 'Z' { result := true; break; } } }
563
dafny-synthesis_task_id_455.dfy
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 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}; }
564
dafny-synthesis_task_id_457.dfy
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] ...
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| { if |s[i]| < |minSublist| { minSublist := s[i]; ...
565
dafny-synthesis_task_id_458.dfy
method RectangleArea(length: int, width: int) returns (area: int) requires length > 0 requires width > 0 ensures area == length * width { area := length * width; }
method RectangleArea(length: int, width: int) returns (area: int) requires length > 0 requires width > 0 ensures area == length * width { area := length * width; }
566
dafny-synthesis_task_id_460.dfy
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| invaria...
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| { result := result + [lst[i][0]]; ...
567
dafny-synthesis_task_id_461.dfy
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|; }
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|; }
568
dafny-synthesis_task_id_470.dfy
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]; va...
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]; va...
569
dafny-synthesis_task_id_472.dfy
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]) { result := false; for i := 0 to a.Length - 1 invariant 0 <= i <= a.Length - 1 invariant result <==> (exists k :: 0 ...
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]) { result := false; for i := 0 to a.Length - 1 { if a[i] + 1 == a[i + 1] { result := true; break;...
570
dafny-synthesis_task_id_474.dfy
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'| =...
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| { if s[i] == oldChar { ...
571
dafny-synthesis_task_id_476.dfy
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 ==> minVa...
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 { if a[i] < minVal { minVal := a[i]; } else if a[i] > maxVal { maxVal := a[i];...
572
dafny-synthesis_task_id_477.dfy
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 forall i ::...
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 forall i ::...
573
dafny-synthesis_task_id_554.dfy
/** * 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 arr[..]...
/** * 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 arr[..]...
574
dafny-synthesis_task_id_555.dfy
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 *...
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 { sumCubes := sumCubes + i * i * i; sumNumbers := sumNumbers + i; ...
575
dafny-synthesis_task_id_557.dfy
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 ShiftMinus32(c...
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 ShiftMinus32(c...
576
dafny-synthesis_task_id_565.dfy
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...
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| { v := v + [s[i]]; } }
577
dafny-synthesis_task_id_566.dfy
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); X(numb...
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); X(numb...
578
dafny-synthesis_task_id_567.dfy
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.Lengt...
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 { if a[i] > a[i + 1] ...
579
dafny-synthesis_task_id_572.dfy
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 invar...
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 { ...
580
dafny-synthesis_task_id_573.dfy
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]) ...
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 { if ! (arr[i] in seen) { seen := seen + { arr[i] }; p := p * arr[...
581
dafny-synthesis_task_id_574.dfy
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 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); }
582
dafny-synthesis_task_id_576.dfy
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 tru...
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 { if sub == main[i..i + |sub|] { result := t...
583
dafny-synthesis_task_id_577.dfy
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; fac...
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; fac...
584
dafny-synthesis_task_id_578.dfy
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 <...
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| { r := r + [s1...
585
dafny-synthesis_task_id_579.dfy
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(...
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(...
586
dafny-synthesis_task_id_58.dfy
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 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); }
587
dafny-synthesis_task_id_581.dfy
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 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; }
588
dafny-synthesis_task_id_586.dfy
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 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; }
589
dafny-synthesis_task_id_587.dfy
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]...
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 { s := s + [a[i]]; } }
590
dafny-synthesis_task_id_588.dfy
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 ...
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 { if a[i] < minVal { minVal := a[i]; } else if a[i] > maxVal { maxVal...
591
dafny-synthesis_task_id_59.dfy
method NthOctagonalNumber(n: int) returns (octagonalNumber: int) requires n >= 0 ensures octagonalNumber == n * (3 * n - 2) { octagonalNumber := n * (3 * n - 2); }
method NthOctagonalNumber(n: int) returns (octagonalNumber: int) requires n >= 0 ensures octagonalNumber == n * (3 * n - 2) { octagonalNumber := n * (3 * n - 2); }
592
dafny-synthesis_task_id_591.dfy
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; }
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; }
593
dafny-synthesis_task_id_594.dfy
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, ...
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, ...
594
dafny-synthesis_task_id_598.dfy
method IsArmstrong(n: int) returns (result: bool) requires 100 <= n < 1000 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 :=...
method IsArmstrong(n: int) returns (result: bool) requires 100 <= n < 1000 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 :=...
595
dafny-synthesis_task_id_599.dfy
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 :...
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 { sum := sum + i; } average := sum as real / n as real; }
596
dafny-synthesis_task_id_600.dfy
method IsEven(n: int) returns (result: bool) ensures result <==> n % 2 == 0 { result := n % 2 == 0; }
method IsEven(n: int) returns (result: bool) ensures result <==> n % 2 == 0 { result := n % 2 == 0; }
597
dafny-synthesis_task_id_602.dfy
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 := f...
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 := f...
598
dafny-synthesis_task_id_603.dfy
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 ...
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 ...
599
dafny-synthesis_task_id_605.dfy
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 { ...
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 { if n % i == 0 { result := false; break; } i := i + 1; } }