Skip to content

Commit

Permalink
84, 134
Browse files Browse the repository at this point in the history
  • Loading branch information
WeetHet committed Aug 29, 2024
1 parent 8b9e581 commit 895fe91
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
16 changes: 16 additions & 0 deletions 084-solve.dfy
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
method solve(n: nat) returns (r: nat)
ensures r == popcount(n)
{
var m := n;
r := 0;
while m > 0
invariant r + popcount(m) == popcount(n)
{
r := r + m % 2;
m := m / 2;
}
}

function popcount(n: nat): nat {
if n == 0 then 0 else n % 2 + popcount(n / 2)
}
10 changes: 10 additions & 0 deletions 134-check_if_last_char_is_a_letter.dfy
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
method check_if_last_char_is_a_letter(s: string) returns (b: bool)
ensures b <==> |s| > 0 && is_alpha(s[|s| - 1]) && (|s| == 1 || s[|s| - 2] == ' ')
{
b := |s| > 0 && is_alpha(s[|s| - 1]) && (|s| == 1 || s[|s| - 2] == ' ');
}


predicate is_alpha(c: char) {
'a' <= c <= 'z' || 'A' <= c <= 'Z'
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Current status:
- [x] 81. numerical_letter_grade
- [x] 82. prime_length
- [x] 83. starts_one_ends
- [ ] 84. solve
- [x] 84. solve
- [x] 85. add
- [ ] 86. anti_shuffle - complex strings
- [ ] 87. get_row - sorting
Expand Down Expand Up @@ -136,7 +136,7 @@ Current status:
- [ ] 131. digits
- [ ] 132. is_nested
- [x] 133. sum_squares
- [ ] 134. check_if_last_char_is_a_letter
- [x] 134. check_if_last_char_is_a_letter
- [x] 135. can_arrange
- [x] 136. largest_smallest_integers
- [ ] 137. compare_one - ill-typed
Expand Down
6 changes: 2 additions & 4 deletions REMAINING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Current status:
## Priority
- [ ] 25. factorize
- [ ] 36. fizz_buzz
- [ ] 147. get_max_triples

## Other

Expand All @@ -14,7 +15,6 @@ Current status:
- [ ] 47. median
- [ ] 65. circular_shift
- [ ] 79. decimal_to_binary
- [ ] 84. solve
- [ ] 90. next_smallest - nullable
- [ ] 103. rounded_avg
- [ ] 107. even_odd_palindrome
Expand All @@ -25,10 +25,7 @@ Current status:
- [ ] 129. minPath
- [ ] 131. digits
- [ ] 132. is_nested
- [ ] 134. check_if_last_char_is_a_letter
- [ ] 141. file_name_check
- [ ] 144. simplify
- [ ] 147. get_max_triples
- [ ] 156. int_to_mini_roman
- [ ] 161. solve
- [ ] 162. string_to_md5 - needs hash
Expand All @@ -50,6 +47,7 @@ Current status:
- [ ] 117. select_words
- [ ] 125. split_words
- [ ] 140. fix_spaces
- [ ] 144. simplify
- [ ] 143. words_in_sentence
- [ ] 160. do_algebra

Expand Down

0 comments on commit 895fe91

Please sign in to comment.