From 9db1b9e8779912f4fab1376bccf43bc31578a6e1 Mon Sep 17 00:00:00 2001 From: alex28sh Date: Thu, 22 Aug 2024 19:04:38 +0200 Subject: [PATCH 1/3] change 096 --- Bench/096-count_up_to.py | 6 ++++++ README.md | 16 ++++++++-------- WIP/WIP: 034-unique.py | 26 +++++++++++++------------- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/Bench/096-count_up_to.py b/Bench/096-count_up_to.py index 837cfc3..d63239e 100644 --- a/Bench/096-count_up_to.py +++ b/Bench/096-count_up_to.py @@ -13,6 +13,9 @@ def CountUpTo(n : int) -> List[int]: not (((0) <= (d_2_i_)) and ((d_2_i_) < (len(Result())))) or (((Result())[d_2_i_]) < (n)))) Ensures(Forall(int, lambda d_1_i_: not (((0) <= (d_1_i_)) and ((d_1_i_) < (len(Result())))) or (IsPrime((Result())[d_1_i_])))) + Ensures(Forall(int, lambda d_3_p_: + Implies((((2) <= (d_3_p_)) and ((d_3_p_) < (n))) and IsPrime(d_3_p_), + Exists(int, lambda x: x >= 0 and x < len(Result()) and Result()[x] == d_3_p_)))) primes = list([int(0)] * 0) # type : List[int] primes = list([]) if (n) <= (2): @@ -26,6 +29,9 @@ def CountUpTo(n : int) -> List[int]: Implies(x >= 0 and x < len(primes), 2 <= primes[x] and primes[x] < n))) Invariant(Forall(int, lambda d_5_j_: (Implies(((0) <= (d_5_j_)) and ((d_5_j_) < (len(primes))), IsPrime((primes)[d_5_j_])), [[IsPrime((primes)[d_5_j_])]]))) + Invariant(Forall(int, lambda d_3_p_: + (Implies((((2) <= (d_3_p_)) and ((d_3_p_) < (d_4_i_))) and IsPrime(d_3_p_), + Exists(int, lambda x: x >= 0 and x < len(primes) and primes[x] == d_3_p_)), [[IsPrime(d_3_p_),]]))) if IsPrime(d_4_i_): primes = primes + [(d_4_i_)] d_4_i_ = (d_4_i_) + (1) diff --git a/README.md b/README.md index bccf42d..d395f34 100644 --- a/README.md +++ b/README.md @@ -44,12 +44,12 @@ Current status: - [ ] 38. encode_cyclic - [ ] 39. prime_fib - [x] 40. triples_sum_to_zero -- [ ] 41. car_race_collision +- [x] 41. car_race_collision - [x] 42. incr_list - [x] 43. pairs_sum_to_zero - [ ] 44. change_base - [ ] 45. triangle_area -- [ ] 46. fib4 +- [x] 46. fib4 - [ ] 47. median - [x] 48. is_palindrome - [ ] 49. modp @@ -99,7 +99,7 @@ Current status: - [ ] 93. encode - [ ] 94. skjkasdkd - [ ] 95. check_dict_case -- [x] 96. count_up_to +- [ ] 96. count_up_to - [x] 97. multiply - [ ] 98. count_upper - [ ] 99. closest_integer @@ -107,7 +107,7 @@ Current status: - [ ] 101. words_string - [x] 102. choose_num - [ ] 103. rounded_avg -- [x] 104. unique_digits +- [ ] 104. unique_digits - [ ] 105. by_length - [x] 106. f - [ ] 107. even_odd_palindrome @@ -129,7 +129,7 @@ Current status: - [ ] 123. get_odd_collatz - [ ] 124. valid_date - [ ] 125. split_words -- [ ] 126. is_sorted +- [x] 126. is_sorted - [x] 127. intersection - [ ] 128. prod_signs - [ ] 129. minPath @@ -138,10 +138,10 @@ Current status: - [ ] 132. is_nested - [x] 133. sum_squares - [ ] 134. check_if_last_char_is_a_letter -- [ ] 135. can_arrange +- [x] 135. can_arrange - [ ] 136. largest_smallest_integers - [ ] 137. compare_one -- [ ] 138. is_equal_to_sum_even +- [x] 138. is_equal_to_sum_even - [x] 139. special_factorial - [ ] 140. fix_spaces - [ ] 141. file_name_check @@ -149,7 +149,7 @@ Current status: - [ ] 143. words_in_sentence - [ ] 144. simplify - [ ] 145. order_by_points -- [ ] 146. specialFilter +- [x] 146. specialFilter - [ ] 147. get_max_triples - [ ] 148. bf - [ ] 149. sorted_list_sum diff --git a/WIP/WIP: 034-unique.py b/WIP/WIP: 034-unique.py index da126d6..c53f899 100644 --- a/WIP/WIP: 034-unique.py +++ b/WIP/WIP: 034-unique.py @@ -43,20 +43,20 @@ def uniqueSorted(s : List[int]) -> List[int]: # not (((0) <= (d_11_j_)) and ((d_11_j_) < (d_6_i_))) or (((s)[d_11_j_]) in (result)))) if ((len(result)) == (0)) or (((result)[(len(result)) - (1)]) != ((s)[d_6_i_])): # Assert(((len(result)) == (0)) or (((result)[(len(result)) - (1)]) < ((s)[d_6_i_]))) - old_res = list(result) - Assert(Forall(int, lambda d_9_k_: - (Implies(((0) <= (d_9_k_)) and ((d_9_k_) < (len(result))), Exists(int, lambda d_10_m_: - (((0) <= (d_10_m_)) and ((d_10_m_) < (d_6_i_))) and (((result)[d_9_k_]) == ((s)[d_10_m_])))), [[(result)[d_9_k_]]]))) - Assert(Forall(int, lambda d_9_k_: Implies(0 <= d_9_k_ and d_9_k_ < len(result), result[d_9_k_] == old_res[d_9_k_]))) - Assert(Forall(int, lambda d_9_k_: - (Implies(((0) <= (d_9_k_)) and ((d_9_k_) < (len(old_res))), Exists(int, lambda d_10_m_: - (((0) <= (d_10_m_)) and ((d_10_m_) < (d_6_i_))) and (((old_res)[d_9_k_]) == ((s)[d_10_m_])))), [[(old_res)[d_9_k_]]]))) + # old_res = list(result) + # Assert(Forall(int, lambda d_9_k_: + # (Implies(((0) <= (d_9_k_)) and ((d_9_k_) < (len(result))), Exists(int, lambda d_10_m_: + # (((0) <= (d_10_m_)) and ((d_10_m_) < (d_6_i_))) and (((result)[d_9_k_]) == ((s)[d_10_m_])))), [[(result)[d_9_k_]]]))) + # Assert(Forall(int, lambda d_9_k_: Implies(0 <= d_9_k_ and d_9_k_ < len(result), result[d_9_k_] == old_res[d_9_k_]))) + # Assert(Forall(int, lambda d_9_k_: + # (Implies(((0) <= (d_9_k_)) and ((d_9_k_) < (len(old_res))), Exists(int, lambda d_10_m_: + # (((0) <= (d_10_m_)) and ((d_10_m_) < (d_6_i_))) and (((old_res)[d_9_k_]) == ((s)[d_10_m_])))), [[(old_res)[d_9_k_]]]))) result = (result) + [(s)[d_6_i_]] - Assert(Exists(int, lambda d_10_m_: - (((0) <= (d_10_m_)) and ((d_10_m_) <= (d_6_i_))) and (((result)[len(result) - 1]) == ((s)[d_10_m_])))) - Assert(Forall(int, lambda d_9_k_: - (Implies(((0) <= (d_9_k_)) and ((d_9_k_) < (len(old_res))), Exists(int, lambda d_10_m_: - (((0) <= (d_10_m_)) and ((d_10_m_) < (d_6_i_))) and (((old_res)[d_9_k_]) == ((s)[d_10_m_])))), [[(old_res)[d_9_k_]]]))) + # Assert(Exists(int, lambda d_10_m_: + # (((0) <= (d_10_m_)) and ((d_10_m_) <= (d_6_i_))) and (((result)[len(result) - 1]) == ((s)[d_10_m_])))) + # Assert(Forall(int, lambda d_9_k_: + # (Implies(((0) <= (d_9_k_)) and ((d_9_k_) < (len(old_res))), Exists(int, lambda d_10_m_: + # (((0) <= (d_10_m_)) and ((d_10_m_) < (d_6_i_))) and (((old_res)[d_9_k_]) == ((s)[d_10_m_])))), [[(old_res)[d_9_k_]]]))) # Assert(Forall(int, lambda d_9_k_: # (Implies(((0) <= (d_9_k_)) and ((d_9_k_) < (len(old_res))), Exists(int, lambda d_10_m_: # (((0) <= (d_10_m_)) and ((d_10_m_) <= (d_6_i_))) and (((old_res)[d_9_k_]) == ((s)[d_10_m_])))), [[(old_res)[d_9_k_]]]))) From 950264e9ea548ad816bbf4c49d55f8f3ec87134e Mon Sep 17 00:00:00 2001 From: alex28sh Date: Thu, 22 Aug 2024 19:22:11 +0200 Subject: [PATCH 2/3] change 096 --- Bench/096-count_up_to.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Bench/096-count_up_to.py b/Bench/096-count_up_to.py index d63239e..ef9ec4f 100644 --- a/Bench/096-count_up_to.py +++ b/Bench/096-count_up_to.py @@ -31,7 +31,7 @@ def CountUpTo(n : int) -> List[int]: (Implies(((0) <= (d_5_j_)) and ((d_5_j_) < (len(primes))), IsPrime((primes)[d_5_j_])), [[IsPrime((primes)[d_5_j_])]]))) Invariant(Forall(int, lambda d_3_p_: (Implies((((2) <= (d_3_p_)) and ((d_3_p_) < (d_4_i_))) and IsPrime(d_3_p_), - Exists(int, lambda x: x >= 0 and x < len(primes) and primes[x] == d_3_p_)), [[IsPrime(d_3_p_),]]))) + Exists(int, lambda x: x >= 0 and x < len(primes) and primes[x] == d_3_p_)), [[IsPrime(d_3_p_)]]))) if IsPrime(d_4_i_): primes = primes + [(d_4_i_)] d_4_i_ = (d_4_i_) + (1) From 028a450e916803b02a9434019f234c6b69b84536 Mon Sep 17 00:00:00 2001 From: alex28sh Date: Thu, 22 Aug 2024 19:29:59 +0200 Subject: [PATCH 3/3] delete 096 --- Bench/096-count_up_to.py | 38 -------------------------------------- 1 file changed, 38 deletions(-) delete mode 100644 Bench/096-count_up_to.py diff --git a/Bench/096-count_up_to.py b/Bench/096-count_up_to.py deleted file mode 100644 index ef9ec4f..0000000 --- a/Bench/096-count_up_to.py +++ /dev/null @@ -1,38 +0,0 @@ -from typing import cast, List, Dict, Set, Optional, Union -from nagini_contracts.contracts import * - -@Pure -def IsPrime(n : int) -> bool : - return ((n) > (1)) and (Forall(int, lambda d_0_k_: - Implies(((2) <= (d_0_k_)) and ((d_0_k_) < (n)), ((n % d_0_k_)) != (0)))) - -def CountUpTo(n : int) -> List[int]: - Requires((n) >= (0)) - Ensures(Acc(list_pred(Result()))) - Ensures(Forall(int, lambda d_2_i_: - not (((0) <= (d_2_i_)) and ((d_2_i_) < (len(Result())))) or (((Result())[d_2_i_]) < (n)))) - Ensures(Forall(int, lambda d_1_i_: - not (((0) <= (d_1_i_)) and ((d_1_i_) < (len(Result())))) or (IsPrime((Result())[d_1_i_])))) - Ensures(Forall(int, lambda d_3_p_: - Implies((((2) <= (d_3_p_)) and ((d_3_p_) < (n))) and IsPrime(d_3_p_), - Exists(int, lambda x: x >= 0 and x < len(Result()) and Result()[x] == d_3_p_)))) - primes = list([int(0)] * 0) # type : List[int] - primes = list([]) - if (n) <= (2): - return primes - d_4_i_ = int(0) # type : int - d_4_i_ = 2 - while (d_4_i_) < (n): - Invariant(Acc(list_pred(primes))) - Invariant(((2) <= (d_4_i_)) and ((d_4_i_) <= (n))) - Invariant(Forall(int, lambda x: - Implies(x >= 0 and x < len(primes), 2 <= primes[x] and primes[x] < n))) - Invariant(Forall(int, lambda d_5_j_: - (Implies(((0) <= (d_5_j_)) and ((d_5_j_) < (len(primes))), IsPrime((primes)[d_5_j_])), [[IsPrime((primes)[d_5_j_])]]))) - Invariant(Forall(int, lambda d_3_p_: - (Implies((((2) <= (d_3_p_)) and ((d_3_p_) < (d_4_i_))) and IsPrime(d_3_p_), - Exists(int, lambda x: x >= 0 and x < len(primes) and primes[x] == d_3_p_)), [[IsPrime(d_3_p_)]]))) - if IsPrime(d_4_i_): - primes = primes + [(d_4_i_)] - d_4_i_ = (d_4_i_) + (1) - return primes