on master help sign in
can
commiteb29c2e0953fefe9a9ebef1222697c3371d32186 authoriko <mail@iko.soy> dateSat 24 Aug 2024, 18:08 (2 years ago) parentf4d4f3a
1 file changed+22
nock/src/jets.rs+22
nock/src/jets.rs+22
@@ -1,4 +1,5 @@
11use core::panic;
2+use num_bigint::BigUint;
23use num_integer::Integer;
34use std::{
45 cmp::Ordering,
@@ -63,6 +64,7 @@ pub fn generate_jets() -> Jets {
6364 (90634096513747887582230817128332929026, ZING),
6465 (59352245691598674621226842217946522940, BEX),
6566 (102718716366123785010912772034318125155, END),
67+ (233905026649167301608240871123208487851, CAN),
6668 ])
6769}
6870
@@ -566,3 +568,23 @@ static END: Jet = |ctx, n| {
566568
567569 Rc::new(Noun::Atom(mask & b.as_atom().unwrap()))
568570};
571+
572+static CAN: Jet = |ctx, n| {
573+ let (a, b) = n.as_cell().unwrap();
574+ let bloq = a.as_u32().unwrap();
575+ let bloq_ = 2u32.pow(bloq);
576+
577+ let atom: Atom =
578+ b.list_iter()
579+ .collect::<Vec<_>>()
580+ .iter()
581+ .rfold(ctx.big_uints.zero.clone(), |acc, next| {
582+ let (p, q) = next.as_cell().unwrap();
583+ let step = p.as_u32().unwrap();
584+ let bits = bloq_ * step;
585+ let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
586+
587+ (acc << bits) | (mask & q.as_atom().unwrap())
588+ });
589+ Rc::new(Noun::Atom(atom))
590+};