Sandwich layer validator (Rust)
#[derive(Debug, PartialEq, Eq)]
enum Layer {
Bread,
Cheese,
Ham,
Cucumber,
Other(&'static str),
}
fn validate_layers(layers: &[Layer]) -> Result<(), String> {
// Helper to find index of first occurrence
let pos = |item: Layer| -> Option<usize> {
layers.iter().position(|l| *l == item)
};
// Cheese must exist
let cheese_idx = pos(Layer::Cheese)
.ok_or_else(|| "Invalid sandwich: missing cheese".to_string())?;
// Ham must be above (i.e., appear after) cheese
if let Some(ham_idx) = pos(Layer::Ham) {
if ham_idx < cheese_idx {
return Err("Awkward: ham is below cheese; ham should be on top of cheese".into());
}
}
// Cucumber must be on top of cheese (i.e., after cheese).
if let Some(cuke_idx) = pos(Layer::Cucumber) {
if cuke_idx < cheese_idx {
return Err("Invalid: cucumber is below cheese; cucumber must be on top of cheese".into());
}
}
// If both ham and cucumber exist, order among them is allowed as long as both are after cheese.
Ok(())
}
fn main() {
let good = vec![
Layer::Bread,
Layer::Cheese,
Layer::Ham,
Layer::Cucumber,
Layer::Bread,
];
let bad_ham = vec![
Layer::Bread,
Layer::Ham,
Layer::Cheese,
Layer::Bread,
];
let bad_cuke = vec![
Layer::Bread,
Layer::Cucumber,
Layer::Cheese,
Layer::Bread,
];
for (name, s) in &[("good", &good), ("bad_ham", &bad_ham), ("bad_cuke", &bad_cuke)] {
match validate_layers(s) {
Ok(()) => println!("{}: valid sandwich", name),
Err(e) => println!("{}: {}", name, e),
}
}
}
Notes:
Cheese must exist.
Ham and cucumber, if present, must appear after the cheese (i.e., on top of it).
Order between ham and cucumber is allowed (both on top of cheese).
2140.wtf #blockworkgallery
2140wtf@rizful.com
npub1lwsm...y86j
https://x.com/2140wtf
..........
https://2140.wtf
.
. _________ A HOST OF: _________ #NOSTRLDN #NOSTRLONDON
@nostr.london
(NOSTR-only meetup in London)
............
2140 EVENTS (global Bitcoin events with music, food, art, meetups, workshops, bitcoin games) .............
.
2140 SESSIONS - B2B DJ sets
............
RUNNING:
.....
₿LOCKWORK GALLERY, LONDON
......
😍Bitcoin Culture Festival London '24 '25 '26😍
.
#purplepodcast
.
.
Lightning Wallets:
⚡ 2140wtf@rizful.com ⚡
2140hq@blink.sv ⚡....
email : helloat2140.wtf
...
............... for private DMs with us use keychat app.........
https://www.keychat.io/u/?k
@2140.wtf #blockworkgallery it's not so hard to be honest
Very interesting special edition of @npub1t8a7...56yu about #lightning spotted at @btcplusplus Berlin


Stay safe out there, Signal or Molly from trusted sources only


The Hacker News
Warning: Beware of Android Spyware Disguised as Signal Encryption Plugin and ToTok Pro
ESET uncovers ProSpy and ToSpy Android spyware posing as Signal and ToTok apps in U.A.E.
What a nice weather, Ich liebe Berlin!
@btcplusplus let's go!
In 2003, at a London fashion show, Hamnett's catwalk models wore shirts with "STOP WAR, BLAIR OUT", a reference to the looming invasion of Iraq.
Here we have another one...


#shitshow



