(2..).for_each(|x|(1..x).for_each(|y|print!("{} ",y)))
rand="0"
9 bytes with newline
in the Cargo.toml and
loop{print!("{} ", rand::random::<i32>())}
+ 42 bytes = 51 bytes @Ryozukii32
with u32
use std::fs;
fn main() {
let r = fs::read_to_string("input").unwrap();
let x: Vec<i64> = r.split("\n")
.filter(|x| !x.is_empty())
.map(|x| x.parse::<i64>().unwrap()).collect();
for a in x.iter() {
for b in x.iter() {
for c in x.iter() {
if a + b + c == 2020 {
println!("{}", a * b * c);
return;
}
}
}
}
}
x.iter()
→ &x
for a in x.iter()
→ for a in &x
str
primitive in crate std
.hexdump -C
.trim()
probably though.parse::<i64>()
probably chokes on whitespacev
in rust I can create a slice with &v[x..y]
but v[x..y]
also works. Does the second one copy the vector?&v
is the same as v.iter()
then &v[x..y]
is the same as v[x..y].iter()
?v[x..y].iter()
autoreferences v[x..y]
to &v[x..y]
.
can autoreference one levelsolve(L, Z) :- member(W, L), member(X, L), member(Y, L), 2020 is W + X + Y, Z is W * X * Y.
(edited)config_store.exe
to store the config with the same name into the mapsv_deepfly 0
to be sure I'm not seeing things wrongc++
void SomeFunc()
{
// throws an exception with all the error info if something goes wrong
DoSomething();
}
void SomeFunc()
{
if (!DoSomething())
{
// obtain the error info and report it to the caller somehow
}
}
properly used exceptions = clean code
or no?try{ SomeFunc(); } catch(whatever) { handleerror; }
is equivalent to if(!SomeFunc()){ handleerror; }
. I think the second is cleaner, I also think limiting them to such contexts (e.g. exceptions that can only go back 1 stack frame) makes exceptions not the correct solutiontry { whatever(); } catch (Exception e){ handle(); }
is easier to understand than if(!whatever()) { handle(); }
. That's just sillyFileNotFoundError(/var/cache/firefox/acbjksbefjksf)
what do you do now?LibraryError(FileNotFound: /path/to/file)
if-error(e : fopen()) { return wrap_unrecoverable(e); }
Type?
e.g. where either an object of typetry { foo(); goo(); boo(); doo(); } catch (Exception e) { ... }
Each of foo, goo, boo and doo have recovery routines on error. You caught an e, how do you recover?noexcept(false)
close(2)
public static int primeraPuntuacio(String ruta) throws ParserConfigurationException, IOException,
SAXException, XPathExpressionException
malloc
returning NULL
- what can you do with that? malloc
returns NULL
, so you log that first, but then you realize that your logging function calls malloc internally - how to fix that? printf
may call malloc
in glibc implementationchar[256] buffer
to avoid malloc? or whatObjectOutputStream oos = null;
try {
oos = new ObjectOutputStream(new FileOutputStream(file));
oos.writeObject(shapes);
oos.flush();
} catch (FileNotFoundException ex) {
// complain to user
} catch (IOException ex) {
// notify user
} finally {
if (oos != null) {
try {
oos.close();
} catch (IOException ex) {
// ignore ... any significant errors should already have been
// reported via an IOException from the final flush.
}
}
}
Cow
enum in crate std
.