II5MBGXDOLONI4VZQLKT5KXRKTPMVWPQLG4BFVZYEZUL2TPOLXXAC
{ queen (I, 0..n-1) } = 1 :- I = 0..n-1.
{ queen (0..n-1, J) } = 1 :- J = 0..n-1.
:- { queen (D - J, J) } > 1, D = 2..2 * (n-1).
:- { queen (D + J, J) } > 1, D = n..n - 2.
{ queen (I, 1..n) } = 1 :- I = 1..n.
{ queen (1..n, J) } = 1 :- J = 1..n.
:- { queen (D - J, J) } > 1, D = 2..2 * n.
:- { queen (D + J, J) } > 1, D = 1 - n..n - 1.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
#[serde(transparent)]
pub struct ZeroBased<T>(T);
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
#[serde(transparent)]
pub struct OneBased<T>(T);
impl OneBased<u32> {
pub fn new(num: u32) -> Self {
debug_assert!(num >= 1);
OneBased(num)
}
pub fn raw(&self) -> u32 {
self.0
}
}
impl ZeroBased<u32> {
pub fn new(num: u32) -> Self {
ZeroBased(num)
}
pub fn raw(&self) -> u32 {
self.0
}
}
let x_param = params[0].number()?;
let y_param = params[1].number()?;
response.queens.push((x_param as u32, y_param as u32));
},
_ => unreachable!()
let x_param = OneBased(params[0].number()? as u32);
let y_param = OneBased(params[1].number()? as u32);
response.queens.push((x_param.into(), y_param.into()));
}
_ => unreachable!(),
impl From<OneBased<u32>> for ZeroBased<u32> {
fn from(num: OneBased<u32>) -> Self {
ZeroBased(num.0 - 1)
}
}
impl From<ZeroBased<u32>> for OneBased<u32> {
fn from(num: ZeroBased<u32>) -> Self {
OneBased(num.0 + 1)
}
}