• API
• FAQ
• Tools
• Archive
SHARE
TWEET

Untitled

a guest Apr 26th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. use std::collections::BTreeMap;
2. use std::ops::Bound::Included;
3.
4. fn main () {
5.     test();
6. }
7.
8. fn test() {
9.     let mut bt: BTreeMap<u128, u128> = BTreeMap::new();
10.     let mut a: u128 = 0;
11.     let div: u128 = 8;
12.     for x in 0..100_u128 {
13.         for y in 0..100_u128 {
14.             let zey = zeeify(x*div, y*div);
15.             a += 1;
16.             bt.insert(zey, a);
17.         }
18.     }
19.     let test = 400;
20.     println!("{:?}", zee_neighbors(test, 8));
21.     let n = zee_neighbors(400, 8);
22.     // [x: 40 y: 40] -> [x: 48, y: 48]
23.     let xs = 46;
24.     let ys = 46;
25.     for r in 0..div {
26.         let yss = (ys-div/2) + r;
27.         let xss = (xs-div/2);
28.         let minzee = zeeify(xss, yss);
29.         let maxzee = zeeify(xss+div, yss);
30.         for v in bt.range( (Included(minzee), Included(maxzee)) ) {
31.             println!("{:?}", v);
32.         }
33.     }
34.
35. }
36.
37. fn abs_u128(a: u128, b: u128) -> u128 {
38.     if a > b {a - b} else { b-a }
39. }
40.
41. fn zee_neighbors(zee: u128, div: u128) -> [u128; 4] {
42.     let a: u128 = 0b10101010101010101010101010101010;
43.     let b: u128 = 0b01010101010101010101010101010101;
44.     let t: u128 = ((zee & a) - div & a) | (zee & b);
45.     let b: u128 = ((zee & b) + div & a) | (zee & b);
46.     let l: u128 = ((zee & b) - div & b) | (zee & a);
47.     let r: u128 = ((zee & a) + div & b) | (zee & a);
48.     [t,b,l,r]
49. }
50.
51. fn zeeify(a: u128, b: u128) -> u128 {
52.     let mut f: u128 = 0;
53.     for i in 0..16 {
54.         f |= ((a & 1<<i) << i) | ((b & 1<<i) << i+1);
55.         //println!("{:b} {:b} | {:b} {:b} | {:b}", a, a&1<<i, b, b&1<<i, f);
56.     }
57.     f
58. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top