-
Notifications
You must be signed in to change notification settings - Fork 519
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
✨ (concept) Add new concept exercise cars-assemble
#1675
base: main
Are you sure you want to change the base?
Conversation
a0d86e5
to
d22c6f9
Compare
} | ||
|
||
fn round_to_1_decimal(input: f64) -> f64 { | ||
return (input * 10.0).round() / 10.0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return (input * 10.0).round() / 10.0; | |
(input * 10.0).round() / 10.0 |
if speed == 10 { | ||
return 0.77; | ||
} | ||
|
||
if speed == 9 { | ||
return 0.8; | ||
} | ||
|
||
if speed >= 5 { | ||
return 0.9; | ||
} | ||
|
||
if speed <= 0 { | ||
return 0.0; | ||
} | ||
|
||
return 1.0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can avoid explicit return
entirely.
if speed == 10 { | |
return 0.77; | |
} | |
if speed == 9 { | |
return 0.8; | |
} | |
if speed >= 5 { | |
return 0.9; | |
} | |
if speed <= 0 { | |
return 0.0; | |
} | |
return 1.0; | |
if speed == 10 { | |
0.77 | |
} else if speed == 9 { | |
0.8 | |
} else if speed >= 5 { | |
0.9 | |
} else if speed <= 0 { | |
0.0 | |
} else { | |
1.0 | |
} |
unimplemented!("Implement working_items_per_minute") | ||
} | ||
|
||
pub fn success_rate(_speed: u8) -> f32 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function signature does not match the exemplar.rs
@@ -0,0 +1,11 @@ | |||
pub fn production_rate_per_hour(_speed: u8) -> f32 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function signature does not match the exemplar.rs
unimplemented!("Implement production_rate_per_hour") | ||
} | ||
|
||
pub fn working_items_per_minute(_speed: u8) -> u8 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub fn working_items_per_minute(_speed: u8) -> u8 { | |
pub fn working_items_per_minute(_speed: i32) -> f64 { |
Returning a f64
will allow us to avoid talking about type casting with as
entirely in this exercise, which would be consistent with the book.
} | ||
|
||
fn production_rate_per_hour_for_speed(speed: i32) -> f64 { | ||
(PRODUCTION_RATE_PER_HOUR_FOR_DEFAULT_SPEED * speed) as f64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(PRODUCTION_RATE_PER_HOUR_FOR_DEFAULT_SPEED * speed) as f64 | |
(PRODUCTION_RATE_PER_HOUR_FOR_DEFAULT_SPEED * speed).into() |
778289e
to
ed689eb
Compare
@devkabiir I don't think there is a need for force-pushes. The commits will probably be squashed at the end anyway. On the other hand force-pushes make it slightly harder for observers to follow developments in the PR. |
This is inspired by the same in csharp track. Provides a gentle introduction to variable assignment, if-statements and numbers.
ed689eb
to
0b5dbdb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On a general note, this exercise seems a bit overloaded with concepts to me. I'm counting five in total:
- number types
- constants
- variable declaration
- type conversion
- arithmetic operators
- if statements
I wonder if one or more other exercises should come before this, introducing a subset of these concepts to the students can make smaller steps.
"if-statements", | ||
"assignment", | ||
"numbers" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell, these concepts do not exist? I'm assuming these need to reference some actual concept, I didn't find precise documentation on the purpose of this key here.
pub fn working_items_per_minute(speed: i32) -> i32 { | ||
(production_rate_per_hour(speed) / 60.0) as i32 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub fn working_items_per_minute(speed: i32) -> i32 { | |
(production_rate_per_hour(speed) / 60.0) as i32 | |
} | |
pub fn working_items_per_minute(speed: i32) -> f64 { | |
production_rate_per_hour(speed) / 60.0 | |
} |
As discussed here.
|
||
```rust | ||
let my_int = 5; | ||
let my_float = my_int; // => panic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let my_float = my_int; // => panic | |
let my_float = my_int; // => compiler error |
let my_float = my_int; // => panic | ||
|
||
let my_float2 = 5.0; | ||
let my_int2 = my_float2; // => panic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let my_int2 = my_float2; // => panic | |
let my_int2 = my_float2; // => compiler error |
- Integers: numbers with no digits behind the decimal separator (whole numbers). Examples are `-6`, `0`, `1`, `25`, `976` and `500000`. | ||
- Floating-point numbers: numbers with zero or more digits behind the decimal separator. Examples are `-2.4`, `0.1`, `3.14`, `16.984025` and `1024.0`. | ||
|
||
The two default numeric types in Rust are `i32` and `f64`. An `i32` is a 32-bit integer and a `f64` is a 64-bit floating-point number. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They aren't used in the exercise, but it might be appropriate to include a note about the other number types? Something like:
There are other number types with different precision, like
f32
andi16
. Unsigned (always positive) integers start with au
instead ofi
. For example, a byte is expressed asu8
. Another number type you'll come across isusize
, its precision depends on your computer (usually64
bits) and is used for lengths and indexes.
The author of this PR has stopped responding in the discussions planning the work on the syllabus. But there's been a lot of work put into reviews already, so I'm keeping it open in case it can be salvaged in a future attempt to create a good syllabus. |
This is inspired by the same in csharp track. Provides a gentle introduction to variable assignment, if-statements and numbers.