#rustchallenge — Public Fediverse posts
Live and recent posts from across the Fediverse tagged #rustchallenge, aggregated by home.social.
-
What will be result?
A. Both X & Y will give error
B. Y will give error & X will print "Kernel" and "Astra"
C. X will print "Kernel" & Y will print "Kernel" and "Astra"
D. both prints "Kernel" & "Astra"(it was shared in ThePrimeagen stream by one of viewers)
-
Will it print Hello World?
A. No, it will give compilation error
B. Yes, it will print `Hello World`
C. No, it will panic at runtime but prints 1
This challenge was brought to you by @tuxmain
-
-
@AstraKernel I have a #RustChallenge for you.
What will be the output of the following code:
- A) nothing, it's not valid rust code 😞
- B) nothing, it will crash runtime 💩
- D) something nice 😻
- E) undefined behavior 💀
#rust #cpp #unsafe #gnu #crablang #imsorry #nice -
What will be the output in "Nightly"?
A. Compilation error (already mentioned nightly so it might run, but will you trust me? 😜)
B. prints "return"
C. prints "!"
D. prints nothing
It's been a long time since I posted (found this in discord)
-
-
What is the output?
A. Both X and Y prints "True" and "False"
B.
Only Y prints "True" and "False"
X just prints "False"C. Gives compilation error
D. Runtime error
i know i know, sorry... :P
-
What is the output?
A. Prints memory address 3 times
B.
"Rust"
Memory Address
Memory AddressC.
"R"
"u"
"st"D.
"Rust"
"Rust"
"Rust" -
✨ Rust challenge explained
Ans: C. It never reaches the prints statement. It goes in an infinite loop 😲
But, how? Let's break down
👉 End value is 0xfffffff which is 268435455.0. it is not very important here. So let's remove it and simplify the code with a constant 20,000,000.0 end value
👉 `f` value stops increasing(round upped) after value 16777216.0 when you add just 1.0 🤯
👉 To know why,you have to understand how the f32 is stored. Float is not stored as simple as integer
👉 f32 uses IEEE 754 format to store the value
👉 Larger f32 number loses accuracy
In a 32 bit float (any language not just rust):
👉 1st bit is used for sign identification (positive or negative)
👉 Following 8 bits used for exponent
👉 Next 23 bits used for storing mantissa 🙃You can see more here, how it is calculated
https://youtu.be/8afbTaA-gOQ(Continued 👇)
-
🦀 an Interesting #RustChallenge given by @sombrastudios
What will happen?
A) prints "Hello World" instantly
B) prints "Hello World" after 3 seconds
C) never reaches the print statement
D) Compilation error -
What will be the result?
A. Runtime error
B. Compile time error
C. It won't give an error and does nothingCredits : @musicmatze
-
What is the output?
A. It will print Kernel
B. It will give a compilation error (explain why)
C. It will give a runtime error (explain why)
-
What is the output of this?
A. Error
B. RustJsPython
C. (Rust, Js, Python)
D. Rust(Not hard/tricky or unique as #RustChallenge, just simple quizzes)
-
-
🦀 Fix the following code
🪲 Error: "cannot borrow `x` as mutable because it is also borrowed as immutable"
Playground link:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=b13fc771b4c2ea39d490375c54fd5a4d👉 You can answer either with fixed playground link or just explanation (No poll)
-
-
What is the result?
A. Error
B. Prints 2 4 6 8
C. Prints 2
D. Prints 2 6 8Vote here 👇
-
✨ Underscore expressions in Rust
Underscore `_`, a reserved identifier - Anything passed to into it will be ignored(But careful, it is not dropped)
👉 Underscore doesnt copy,move or borrow the value
👉 In the following code, we create String instance 'x'.We pass it to the underscore which does nothing than ignoring whatever we give. It does not move the ownership.
Ownership still remains with 'x' 😱let x = String::new("Kernel");
let _ = x;👉 Then what is the use?
👉 It will be useful in situation, when you are not interested in a certain value and ignore it.
For example:
fn main(){
let x = (21, "Parker");
let (age, _) = x; //Ignore the name, only want age from the tuple.
println!("age: {}", age);
}Resources:
https://runrust.miraheze.org/wiki/UnderscoreUnderscore is not exactly "throw away" but rather it is exactly "don't bind to variable:
https://news.ycombinator.com/item?id=22449960
https://www.reddit.com/r/rust/comments/96zxge/underscore_does_not_bind_codechain/ -
What is the result?
1. A and B both print "Kernel"
2. A prints "Kernel" and B gives error
3. B prints "Kernel" and A gives error
4. A and B both gives errorVote your answer here 👇
-
-
🦀 One more #RustChallenge for today on the same concept
A.
Starting race
Ending race
140
280B. Error (explain why)
C.
Starting race
140
280
Ending raceD.
Starting race
Ending race
280
140Vote your answer here 👇
-
What is the result?
A.
Hello
Drop it - Samson
Drop it - Ross
Bye, WorldB.
Hello
Drop it - Ross
Drop it - Samson
Bye, WorldC. Error (explain why)
D.
Hello
Bye, World
Drop it - Samson
Drop it - RossYou can also vote 👇
-
What is the result?
1. A and B will print 5 5
2. A will give error and B prints 5 5
3. B will give error and A prints 5 5
4. Both will give error(Boost this post if you like this challenge)
You can reply or Vote your answer here in the poll
👇 -
What will be the result?
1. Both A and B will print `true`
2. B will give an error and A will print `true`
3. A will give an error and B will print. `true`
4. A and B both will throw error* Idea source will be shared later
#rust #rustlang #rustaceans
You can also vote your answer 👇 -
Answer to the challenge:
3. B will throw an errorhttps://infosec.exchange/users/AstraKernel/statuses/109789451277060852
--Example code for clarification, hope it helps 👇
-
Two sets of codes. What will be the result?
1. A and B will print "1 2 3" two times
2. A will throw an error (explain)
3. B will throw an error (explain)
4. A and B will throw an error (explain)
You can also vote your answer here 👇
-
What is the output?
A. Hello world!
B. Helloworld!
C. Moo
D. "no method named `contains` found for enum `Cow<'_, str>`" -
What is the output and why?
A Syntax error
B. 2 3
C. 3 2
D. 2 2