Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump to v2.9.2 #320

Merged
merged 15 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Getting scarb
uses: software-mansion/setup-scarb@v1
with:
scarb-version: "2.8.2"
scarb-version: "2.9.2"

- name: Verify all exercises
env:
Expand All @@ -56,7 +56,7 @@ jobs:
- name: Getting scarb
uses: software-mansion/setup-scarb@v1
with:
scarb-version: "2.8.2"
scarb-version: "2.9.2"

- name: Format
run: ./bin/format_exercises.sh --check
Expand Down
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
scarb 2.8.2
scarb 2.9.2
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ _Thoughtful suggestions will likely result faster & more enthusiastic responses

## Testing

Tests currently use Cairo v2.8.2 (included with Scarb v2.8.2).
Tests currently use Cairo v2.9.2 (included with Scarb v2.9.2).

To test all exercises, run `./bin/verify-exercises`.
This command will iterate over all exercises and check to see if their exemplar/example implementation passes all the tests.
Expand Down
17 changes: 4 additions & 13 deletions bin/format_exercises.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,11 @@ for exercise_dir in $exercises; do
continue
fi

if [ -f "./src/lib.cairo" ]; then
scaffold_solution="./src/lib.cairo"
else
if [ ! -s "./src/lib.cairo" ]; then
echo "Could not locate scaffold implementation for $exercise"
exit 1
fi

# check scaffold solution formatting
scarb fmt "${SCARB_FMT_ARGS[@]}"

# scarb fmt cannot currently format individual files, so we have to
# temporarily move the solution files into the Cairo package, where
# 'scarb fmt' can format it as well
Expand All @@ -47,17 +42,13 @@ for exercise_dir in $exercises; do
exit 1
fi

# backup scaffold solution
cp "$scaffold_solution" "$tmp_file"

# copy the example solution file into the package
cp "$solution_file" "$scaffold_solution"
cp "$solution_file" "$tmp_file"

# check example solution formatting
scarb fmt "${SCARB_FMT_ARGS[@]}"

# copy the scaffold solution back
cp "$tmp_file" "$scaffold_solution"
# copy the example solution back in case it was formatted
cp "$tmp_file" "$solution_file"

rm "$tmp_file"
done
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn can_signal_prisoner(archer_awake: bool, prisoner_awake: bool) -> bool {
}

pub fn can_free_prisoner(
knight_awake: bool, archer_awake: bool, prisoner_awake: bool, dog_present: bool
knight_awake: bool, archer_awake: bool, prisoner_awake: bool, dog_present: bool,
) -> bool {
(prisoner_awake && !knight_awake && !archer_awake) || (dog_present && !archer_awake)
}
2 changes: 1 addition & 1 deletion exercises/concept/annalyns-infiltration/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2024_07"

[dev-dependencies]
cairo_test = "2.8.2"
cairo_test = "2.9.2"
2 changes: 1 addition & 1 deletion exercises/concept/annalyns-infiltration/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn can_signal_prisoner(archer_awake: bool, prisoner_awake: bool) -> bool {
}

pub fn can_free_prisoner(
knight_awake: bool, archer_awake: bool, prisoner_awake: bool, dog_present: bool
knight_awake: bool, archer_awake: bool, prisoner_awake: bool, dog_present: bool,
) -> bool {
panic!("implement `can_free_prisoner`")
}
2 changes: 1 addition & 1 deletion exercises/concept/calculator-conundrum/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2024_07"

[dev-dependencies]
cairo_test = "2.8.2"
cairo_test = "2.9.2"
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn addition_with_small_operands() {
#[ignore]
fn addition_with_large_operands() {
assert_eq!(
SimpleCalculator::calculate(378_961, 399_635, "+").unwrap(), "378961 + 399635 = 778596"
SimpleCalculator::calculate(378_961, 399_635, "+").unwrap(), "378961 + 399635 = 778596",
);
}

Expand All @@ -23,7 +23,7 @@ fn multiplication_with_small_operands() {
#[ignore]
fn multiplication_with_large_operands() {
assert_eq!(
SimpleCalculator::calculate(72_441, 2_048, "*").unwrap(), "72441 * 2048 = 148359168"
SimpleCalculator::calculate(72_441, 2_048, "*").unwrap(), "72441 * 2048 = 148359168",
);
}

Expand All @@ -37,7 +37,7 @@ fn division_with_small_operands() {
#[ignore]
fn division_with_large_operands() {
assert_eq!(
SimpleCalculator::calculate(1_338_800, 83_675, "/").unwrap(), "1338800 / 83675 = 16"
SimpleCalculator::calculate(1_338_800, 83_675, "/").unwrap(), "1338800 / 83675 = 16",
);
}

Expand Down
2 changes: 1 addition & 1 deletion exercises/concept/chrono-realms-time-tree/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2024_07"

[dev-dependencies]
cairo_test = "2.8.2"
cairo_test = "2.9.2"
2 changes: 1 addition & 1 deletion exercises/concept/chrono-realms/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2024_07"

[dev-dependencies]
cairo_test = "2.8.2"
cairo_test = "2.9.2"
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub impl EvensImpl<T, +Drop<T>, +Copy<T>> of EvensTrait<T> {
if i % 2 == 0 {
result.append(*self.at(i));
}
i += 1;
i += 2;
0xNeshi marked this conversation as resolved.
Show resolved Hide resolved
};
result
}
Expand Down
2 changes: 1 addition & 1 deletion exercises/concept/low-power-embedded-game/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2024_07"

[dev-dependencies]
cairo_test = "2.8.2"
cairo_test = "2.9.2"
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ mod evens {
#[ignore]
fn strs() {
let arr: Array<felt252> = array![
'You', 'really', 'must', 'never', 'be', 'above', 'joking.'
'You', 'really', 'must', 'never', 'be', 'above', 'joking.',
];
assert_eq!(arr.evens(), array!['You', 'must', 'be', 'joking.']);
}
Expand Down
2 changes: 1 addition & 1 deletion exercises/concept/lucians-luscious-lasagna/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2024_07"

[dev-dependencies]
cairo_test = "2.8.2"
cairo_test = "2.9.2"
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use lucians_luscious_lasagna::{
elapsed_time_in_minutes, expected_minutes_in_oven, preparation_time_in_minutes,
remaining_minutes_in_oven
remaining_minutes_in_oven,
};

#[test]
Expand Down
2 changes: 1 addition & 1 deletion exercises/concept/the-realm-of-echoes/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2024_07"

[dev-dependencies]
cairo_test = "2.8.2"
cairo_test = "2.9.2"
12 changes: 6 additions & 6 deletions exercises/practice/acronym/.meta/example.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@ pub fn abbreviate(phrase: ByteArray) -> ByteArray {
i += 1;
};

return result;
result
}

fn to_uppercase(c: u8) -> u8 {
if is_lowercase(c) {
return c - 32;
c - 32
} else {
return c;
c
}
}

fn is_letter(c: u8) -> bool {
return is_uppercase(c) || is_lowercase(c);
is_uppercase(c) || is_lowercase(c)
}

fn is_uppercase(c: u8) -> bool {
return c >= 'A' && c <= 'Z';
c >= 'A' && c <= 'Z'
}

fn is_lowercase(c: u8) -> bool {
return c >= 'a' && c <= 'z';
c >= 'a' && c <= 'z'
}
2 changes: 1 addition & 1 deletion exercises/practice/acronym/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2024_07"

[dev-dependencies]
cairo_test = "2.8.2"
cairo_test = "2.9.2"
18 changes: 3 additions & 15 deletions exercises/practice/all-your-base/.meta/example.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use core::num::traits::Pow;

#[derive(Drop, Debug, PartialEq)]
pub enum Error {
InvalidInputBase,
Expand Down Expand Up @@ -45,7 +47,7 @@ fn convert_to_base_10(digits: Array<u32>, input_base: u32) -> u32 {
while i < len {
let digit = digits[i];
let exp = len - 1 - i;
let pow = pow(input_base, exp);
let pow = input_base.pow(exp);
sum += *digit * pow;
i += 1;
};
Expand Down Expand Up @@ -80,17 +82,3 @@ fn reverse_array(arr: Array<u32>) -> Array<u32> {

reversed
}

fn pow(base: u32, mut power: u32) -> u32 {
if base == 0 {
return base;
}
let base: u256 = base.into();
let mut result = 1_u256;
while power != 0 {
result *= base;
power -= 1;
};

result.try_into().expect('too large to fit output type')
}
2 changes: 1 addition & 1 deletion exercises/practice/all-your-base/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2024_07"

[dev-dependencies]
cairo_test = "2.8.2"
cairo_test = "2.9.2"
31 changes: 6 additions & 25 deletions exercises/practice/allergies/.meta/example.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use core::num::traits::Pow;

#[derive(Drop)]
struct Allergies {
score: u32,
Expand All @@ -15,17 +17,9 @@ pub enum Allergen {
Cats,
}

const ALLERGENS: [
Allergen
; 8] = [
Allergen::Eggs,
Allergen::Peanuts,
Allergen::Shellfish,
Allergen::Strawberries,
Allergen::Tomatoes,
Allergen::Chocolate,
Allergen::Pollen,
Allergen::Cats,
const ALLERGENS: [Allergen; 8] = [
Allergen::Eggs, Allergen::Peanuts, Allergen::Shellfish, Allergen::Strawberries,
Allergen::Tomatoes, Allergen::Chocolate, Allergen::Pollen, Allergen::Cats,
];

#[generate_trait]
Expand All @@ -45,7 +39,7 @@ pub impl AllergiesImpl of AllergiesTrait {
}
index += 1;
};
found && (*self.score & pow(2, index)) != 0
found && (*self.score & 2_u32.pow(index)) != 0
}

fn allergies(self: @Allergies) -> Array<Allergen> {
Expand All @@ -59,16 +53,3 @@ pub impl AllergiesImpl of AllergiesTrait {
result
}
}

fn pow(base: u32, mut power: u32) -> u32 {
if base == 0 {
return base;
}
let base: u256 = base.into();
let mut result = 1_u256;
while power != 0 {
result *= base;
power -= 1;
};
result.try_into().expect('too large to fit output type')
}
2 changes: 1 addition & 1 deletion exercises/practice/allergies/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2024_07"

[dev-dependencies]
cairo_test = "2.8.2"
cairo_test = "2.9.2"
2 changes: 1 addition & 1 deletion exercises/practice/allergies/tests/allergies.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ fn testing_for_cats_allergy_allergic_to_everything() {
fn compare_allergy_vectors(expected: @Array<Allergen>, actual: @Array<Allergen>) {
if actual.len() != expected.len() {
panic!(
"Allergy vectors are of different lengths\n expected {expected:?}\n got {actual:?}"
"Allergy vectors are of different lengths\n expected {expected:?}\n got {actual:?}",
);
}

Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/anagram/.meta/example.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use core::dict::Felt252Dict;

#[derive(Drop, Debug)]
struct Set {
values: Array<ByteArray>
values: Array<ByteArray>,
}

#[generate_trait]
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/anagram/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2024_07"

[dev-dependencies]
cairo_test = "2.8.2"
cairo_test = "2.9.2"
2 changes: 1 addition & 1 deletion exercises/practice/anagram/tests/anagram.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn detects_anagram() {
fn detects_three_anagrams() {
let word: ByteArray = "allergy";
let inputs = Set::new(
array!["gallery", "ballerina", "regally", "clergy", "largely", "leading",]
array!["gallery", "ballerina", "regally", "clergy", "largely", "leading"],
);
let output = anagrams_for(@word, @inputs);
let expected = Set::new(array!["gallery", "regally", "largely"]);
Expand Down
19 changes: 4 additions & 15 deletions exercises/practice/armstrong-numbers/.meta/example.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use core::num::traits::Pow;

pub fn is_armstrong_number(mut num: u128) -> bool {
let mut original_num = num;
let digits = count_digits(num);
Expand All @@ -7,7 +9,7 @@ pub fn is_armstrong_number(mut num: u128) -> bool {
}

let lastDigit = num % 10;
let sum = pow(lastDigit, digits);
let sum = lastDigit.pow(digits);
num = num / 10;
if sum > original_num {
break false;
Expand All @@ -16,24 +18,11 @@ pub fn is_armstrong_number(mut num: u128) -> bool {
}
}

fn count_digits(mut num: u128) -> u128 {
fn count_digits(mut num: u128) -> u32 {
let mut res = 0;
while num != 0 {
num = num / 10;
res += 1;
};
res
}

fn pow(base: u128, mut power: u128) -> u128 {
if base == 0 {
return base;
}
let base: u256 = base.into();
let mut result = 1_u256;
while power != 0 {
result *= base;
power -= 1;
};
result.try_into().expect('too large to fit output type')
}
2 changes: 1 addition & 1 deletion exercises/practice/armstrong-numbers/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2024_07"

[dev-dependencies]
cairo_test = "2.8.2"
cairo_test = "2.9.2"
Loading
Loading