Skip to content

Commit

Permalink
println macro
Browse files Browse the repository at this point in the history
  • Loading branch information
country cousin authored and country cousin committed Feb 29, 2024
1 parent a158f2a commit 851e274
Show file tree
Hide file tree
Showing 54 changed files with 197 additions and 372 deletions.
6 changes: 2 additions & 4 deletions exercises/arrays/arrays1.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
// Make me compile and pass the test!
// Execute `starklings hint arrays1` or use the `hint` watch subcommand for a hint.

// I AM DONE
// I AM NOT DONE

use array::ArrayTrait;
use option::OptionTrait;

fn create_array() -> Array<felt252> {
let mut a = ArrayTrait::new(); // something to change here...
a.append(0);
a.append(1);
let a = ArrayTrait::new(); // something to change here...
a.append(1);
a
}
Expand Down
3 changes: 1 addition & 2 deletions exercises/arrays/arrays2.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Make me compile and pass the test!
// Execute `starklings hint arrays2` or use the `hint` watch subcommand for a hint.

// I AM DONE
// I AM NOT DONE

use array::ArrayTrait;
use option::OptionTrait;
Expand All @@ -18,7 +18,6 @@ fn create_array() -> Array<felt252> {
fn remove_element_from_array(
ref a: Array<felt252>
) { //TODO something to do here...Is there an array method I can use?
a.pop_front();
}

#[test]
Expand Down
6 changes: 3 additions & 3 deletions exercises/arrays/arrays3.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
// Make me compile and pass the test!
// Execute `starklings hint arrays3` or use the `hint` watch subcommand for a hint.

// I AM DONE
// I AM NOT DONE

use array::ArrayTrait;
use option::OptionTrait;

fn create_array() -> Array<felt252> {
let mut a = ArrayTrait::new(); // something to change here...
let a = ArrayTrait::new(); // something to change here...
a.append(0);
a.append(1);
a.append(2);
a.append(0);
a.pop_front().unwrap();
a
}
Expand All @@ -25,3 +24,4 @@ fn test_arrays3() {
// You should not change the index accessed.
a.at(2);
}

6 changes: 1 addition & 5 deletions exercises/dict/dict1.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@
// Make me compile and pass the test!
// Execute `starklings hint dict1` or use the `hint` watch subcommand for a hint.

// I AM DONE
// I AM NOT DONE


fn create_dictionary() -> Felt252Dict<u32> {
let mut dict: Felt252Dict<u32> = Default::default();
//TODO
dict.insert('A', 1);
dict.insert('B', 2);
dict.insert('bob', 3);
dict

}

Expand Down
20 changes: 4 additions & 16 deletions exercises/dict/dict2.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,14 @@
// Make me compile and pass the test!
// Execute `starklings hint dict2` or use the `hint` watch subcommand for a hint.

// I AM DONE
// I AM NOT DONE



fn multiply_element_by_10(ref dict: Felt252Dict<u32>, n:u32) {
fn multiply_element_by_10(ref dict: Felt252Dict<u32>, n: usize) {
//TODO : make a function that multiplies the elements stored at the indexes 0 to n of a dictionary by 10



let mut value = 0;
loop {
if value > n {
break;
}
let multiplied_value = dict.get(value.into()) * 10;
dict.insert(value.into(), multiplied_value);
value += 1;
}



}

// Don't change anything in the test
Expand All @@ -45,7 +33,7 @@ fn test_3() {
#[test]
#[available_gas(200000000)]
fn test_4() {
let muta dict: Felt252Dict<u32> = Default::defult();
let mut dict: Felt252Dict<u32> = Default::default();
dict.insert(0, 1);
dict.insert(1, 2);
dict.insert(2, 5);
Expand Down
16 changes: 2 additions & 14 deletions exercises/dict/dict3.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// Execute `starklings hint dict3` or use the `hint` watch subcommand for a hint.


// I AM DONE
// I AM NOT DONE


#[derive(Destruct)]
Expand All @@ -20,35 +20,23 @@ struct Team {
#[generate_trait]
impl TeamImpl of TeamTrait {
fn new() -> Team {
// TODO : initialize empty team with 0 player
let mut level: Felt252Dict<u32> = Default::default();
let team = Team{level: level, players_count:0};
team


//TODO : initialize empty team with 0 player
}

fn get_level(ref self: Team, name: felt252) -> usize {
//TODO
self.level.get(name)
}

fn add_player(ref self: Team, name: felt252, level: usize) -> () {
//TODO
self.level.insert(name, level);
self.players_count += 1;

}

fn level_up(ref self: Team, name: felt252) {
//TODO
let mut current_level = self.level.get(name);
let mut level_up = self.level.insert(name, current_level + 1);
}

fn players_count(self: @Team) -> usize {
//TODO
*self.players_count
}
}

Expand Down
17 changes: 7 additions & 10 deletions exercises/enums/enums1.cairo
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
// enums1.cairo
// No hints this time! ;)

// I AM DONE
// I AM NOT DONE


// use debug::print;
use debug::PrintTrait;
enum Message { // TODO: define a few types of messages as used below
Quit,
Echo,
Move,
ChangeColor
}

fn main() {
Expand All @@ -22,10 +18,11 @@ fn main() {
impl MessagePrintImpl of PrintTrait<Message> {
fn print(self: Message) {
match self {
Message::Quit => ('Quit').print(),
Message::Echo => ('Echo').print(),
Message::Move => ('Move').print(),
Message::ChangeColor => ('ChangeColor').print()

Message::Quit => println!("Quit"),
Message::Echo => println!("Echo"),
Message::Move => println!("Move"),
Message::ChangeColor => println!("ChangeColor")
}
}
}
24 changes: 10 additions & 14 deletions exercises/enums/enums2.cairo
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
// enums2.cairo
// Execute `starklings hint enums2` or use the `hint` watch subcommand for a hint.

// I AM DONE
// I AM NOT DONE

use debug::PrintTrait;
use array::ArrayTrait;
use traits::Into;

#[derive(Copy, Drop)]
enum Message { // TODO: define the different variants used below
Quit,
Echo: felt252,
Move : (u8, u8),
ChangeColor: (u8, u8, u8)
}


Expand Down Expand Up @@ -58,20 +54,20 @@ fn print_messages_recursive(messages: Array<Message>, index: u32) {

impl MessagePrintImpl of PrintTrait<Message> {
fn print(self: Message) {
('___MESSAGE BEGINS___').print();
println!("___MESSAGE BEGINS___");
match self {
Message::Quit => ('Quit').print(),
Message::Echo(msg) => msg.print(),
Message::Quit => println!("Quit"),
Message::Echo(msg) => println!("{}", msg),
Message::Move((a, b)) => {
a.print();
b.print();
println!("{}", a);
println!("{}",b);
},
Message::ChangeColor((red, green, blue)) => {
red.print();
green.print();
blue.print();
println!("{}",red);
println!("{}",green);
println!("{}",blue);
}
}
('___MESSAGE ENDS___').print();
println!("___MESSAGE ENDS___");
}
}
14 changes: 2 additions & 12 deletions exercises/enums/enums3.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@
// Address all the TODOs to make the tests pass!
// Execute `starklings hint enums3` or use the `hint` watch subcommand for a hint.

// I AM DONE
// I AM NOT DONE print

use debug::PrintTrait;

#[derive(Drop, Copy)]
enum Message { // TODO: implement the message variant types based on their usage below
ChangeColor: (u8, u8, u8),
Echo: felt252,
Move: Point,
Quit
}

#[derive(Drop, Copy)]
Expand Down Expand Up @@ -45,7 +41,7 @@ impl StateImpl of StateTrait {
}

fn echo(ref self: State, s: felt252) {
s.print();
println!("{}", s);
}

fn move_position(ref self: State, p: Point) {
Expand All @@ -56,12 +52,6 @@ impl StateImpl of StateTrait {
fn process(
ref self: State, message: Message
) { // TODO: create a match expression to process the different message variants
match message{
Message::ChangeColor(color) => self.change_color(color),
Message::Echo(s)=> self.echo(s),
Message::Move(point) => self.move_position(point),
Message::Quit(_) => self.quit()
}
}
}

Expand Down
4 changes: 1 addition & 3 deletions exercises/functions/functions1.cairo
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// functions1.cairo
// Execute `starklings hint functions1` or use the `hint` watch subcommand for a hint.

// I AM DONE
// I AM NOT DONE

fn main() {
call_me();
}

fn call_me(){}
7 changes: 3 additions & 4 deletions exercises/functions/functions2.cairo
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// functions2.cairo
// Execute `starklings hint functions2` or use the `hint` watch subcommand for a hint.

// I AM DONE
use debug::PrintTrait;
// I AM NOT DONE

fn main() {
call_me(3);
}

fn call_me(num:felt252) {
num.print();
fn call_me(num:) {
println!("num is {}", num);
}
9 changes: 5 additions & 4 deletions exercises/functions/functions3.cairo
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// functions3.cairo
// Execute `starklings hint functions3` or use the `hint` watch subcommand for a hint.

// I AM DONE
use debug::PrintTrait;
// I AM NOT DONE


fn main() {
call_me(4);
call_me();
}

fn call_me(num: u64) {
num.print();

println!("num is {}", num);
}
8 changes: 4 additions & 4 deletions exercises/functions/functions4.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
// in the signatures for now. If anything, this is a good way to peek ahead
// to future exercises!)

// I AM DONE
use debug::PrintTrait;
// I AM NOT DONE


fn main() {
let original_price = 51;
sale_price(original_price).print();
println!("sale_price is {}", sale_price(original_price));
}

fn sale_price(price: u32) -> usize{
fn sale_price(price: u32) -> {
if is_even(price) {
price - 10
} else {
Expand Down
8 changes: 2 additions & 6 deletions exercises/if/if1.cairo
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
// if1.cairo
// Execute `starklings hint if1` or use the `hint` watch subcommand for a hint.

// I AM DONE
// I AM NOT DONE

fn bigger(a: usize, b: usize) -> usize { // Complete this function to return the bigger number!
// Do not use:
// - another function call
// - additional variables
if a > b {
a
}else{
b
}
}

// Don't mind this for now :)
Expand All @@ -29,3 +24,4 @@ mod tests {
assert(42 == bigger(32, 42), '42 bigger than 32');
}
}

Loading

0 comments on commit 851e274

Please sign in to comment.