Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern crate primal;
- extern crate bmp;
- extern crate num;
- extern crate num_bigint;
- use std::io;
- use std::io::Write;
- use std::fs::File;
- use std::ops::Index;
- use std::fmt::Error;
- use std::num::ParseIntError;
- use std::collections::{HashMap, LinkedList};
- use primal::*;
- use num::{Integer, BigInt};
- use num_bigint::Sign;
- use bmp::Pixel;
- static RSA100C: &'static str = "1522605027922533360535618378132637429718068114961380688657908494580122963258952897654000350692006139";
- static RSA100C_N: &'static str = "14387588531011964456730684619177102985211280936";
- static RSA100A: &'static str = "37975227936943673922808872755445627854565536638199";
- static RSA100B: &'static str = "40094690950920881030683735292761468389214899724061";
- static RSA100D: &'static str = "39020571855401265512289573339484371018905006900194";
- static RSA100E: &'static str = "61218444075812733697456051513875809617598014768503";
- static RSA100F: &'static str = "16822699634989797327123095165092932420211999031886";//2d+1-e
- static RSA100N: &'static str = "14387588531011964456730684619177102985211280936";
- static RSA100X: &'static str = "1045343918457591589480700584038743164339470261995";
- static RSA100X_PLUS_N: &'static str = "1059731506988603553937431268657920267324681542931";
- pub trait BmpColor {
- fn color(e: i32, n: i32, f: i32, img: &mut bmp::Image, pixel: Pixel);
- }
- impl BmpColor for TheEnd {
- fn color(e: i32, n: i32, f: i32, img: &mut bmp::Image, pixel: Pixel) {
- img.set_pixel((e + 1024) as u32, n as u32, pixel);
- img.set_pixel((f + 1024) as u32, (n - 1) as u32, pixel);
- }
- }
- pub trait Hamilton {
- fn calculate_z(h: Hamiltonian) -> i32;
- fn hamiltonian_product(first: Hamiltonian, second: Hamiltonian) -> i32;
- }
- pub struct Hamiltonian{ a: i32, b: i32, c: i32, d: i32, i: i32, j: i32, k: i32 }
- pub struct CoordHamiltonian { e: i32, n: i32, hamiltonian: Hamiltonian }
- impl Hamilton for TheEnd {
- fn calculate_z(h: Hamiltonian) -> i32 {
- // calcualate Z
- (h.b * h.i) + (h.c * h.j) + (h.d * h.k)
- }
- fn hamiltonian_product(first: Hamiltonian, second: Hamiltonian) -> i32 {
- (first.a * second.a) + ((first.b * second.b) * first.i) + ((first.c * second.c) * first.j) + ((first.d * second.d) * first.k)
- + ((first.b * second.a) * first.i) + ((first.b * second.b) * (first.i * first.i)) + ((first.b * second.c) * (first.i * first.j)) + ((first.b * second.d) * (first.i * first.k))
- + ((first.c * second.a) * first.j) + ((first.c * second.b) * (first.j * first.i)) + ((first.c * second.c) * (first.j * first.j)) + ((first.c * second.d) * (first.j * first.k))
- + ((first.d * second.a) * first.k) + ((first.d * second.b) * (first.k * first.i)) + ((first.d * second.c) * (first.k * first.j)) + ((first.d * second.d) * (first.k * first.k))
- }
- }
- #[derive(Debug)]
- pub struct TheEnd(pub HashMap<i32, HashMap<i32, LinkedList<String>>>);
- impl TheEnd {
- pub fn new() -> TheEnd {
- TheEnd(HashMap::new())
- }
- pub fn create_the_end(&mut self) {
- let i_max: i32 = 512;
- let x_min: i32 = 0;
- let y_min: i32 = 0;
- let x_max: i32 = 64;
- let y_max: i32 = 64;
- let mut img = bmp::Image::new(2048, 512);
- let mut color = Pixel { r:255, g:000, b:000 };
- let mut red = Pixel { r:255, g:000, b:000 };
- let mut blue = Pixel { r:000, g:000, b:255 };
- let mut green = Pixel { r:000, g:255, b:000 };
- let mut white = Pixel { r:255, g:255, b: 255 };
- let mut black = Pixel { r: 000, g: 000, b: 000 };
- let mut orange = Pixel { r:255, g: 165, b: 000 };
- let mut purple = Pixel { r:255, g: 000, b: 255 };
- let mut yellow = Pixel { r:255, g: 255, b: 000 };
- let mut colors: Vec<Pixel> = Vec::new();
- colors.push(red);
- colors.push(blue);
- colors.push(green);
- colors.push(orange);
- colors.push(yellow);
- colors.push(purple);
- for i in 1 .. i_max {
- for j in 1 .. i {
- let a: i32 = i - j;
- let b: i32 = i + j;
- let c: i32 = a * b;
- let odd = c % 2 == 1;
- let d = (c as f64).sqrt() as i32;
- let e = c - (d * d) + 1;
- let f = e - ((2 * d) + 1);
- let n = i - d;
- let x = d - a;
- let k = i * j;
- let hamiltonian = Hamiltonian { a, b, c, d, i, j, k };
- let z = TheEnd::calculate_z(hamiltonian);
- let primes: Vec<u32> = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149].to_vec();
- colors.push(red);
- colors.push(blue);
- colors.push(green);
- //,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149].to_vec();
- let mut count = 1;
- let base = a + b/ a;
- for (color, prime) in colors.iter().cycle().zip(primes) {
- if a % base == prime as i32 {
- TheEnd::color(e,n,f,&mut img, *color);
- }
- }
- if e == 1 {
- TheEnd::color(e,n,f,&mut img, white);
- }
- if a % base == 1 {
- TheEnd::color(e,n,f,&mut img, blue);
- }
- if a % base == 3 {
- TheEnd::color(e,n,f,&mut img, green);
- }
- if a % base == 5 {
- TheEnd::color(e,n,f,&mut img, red);
- }
- /*
- if a % base == 7 {
- TheEnd::color(e,n,f,&mut img, purple);
- }
- if a % base == 11 {
- TheEnd::color(e,n,f,&mut img, yellow);
- }
- */
- if primal::is_prime(c as u64) {
- TheEnd::color(e,n,f,&mut img, white);
- }
- let text = format!("{{{}:{}:{}:{}:{}:{}}}", e, n, d, x, a, b);
- self.0
- .entry(e)
- .or_insert(HashMap::new())
- .entry(n)
- .or_insert(LinkedList::new())
- .push_back(text);
- let text = format!("{{{}:{}:{}:{}:{}:{}}}", f, n - 1, d + 1, x + 1, a, b);
- self.0
- .entry(f)
- .or_insert(HashMap::new())
- .entry(n - 1)
- .or_insert(LinkedList::new())
- .push_back(text);
- }
- }
- let _ = img.save("img.bmp");
- }
- pub fn output<W: Write>(&self, target: &mut W) -> io::Result<()> {
- let i_max = 256;
- let x_min = -64;
- let y_min = 0;
- let x_max = 64;
- let y_max = 64;
- let set_s = 12;
- for y in 0 .. y_max {
- for z in 0 .. set_s {
- for x in x_min .. x_max {
- match self.0.get(&x).and_then(|e| e.get(&y)).and_then(|e| e.iter().nth(z as usize)) {
- Some(x) => write!(target, "{},", x)?,
- None => write!(target, ",")?,
- }
- }
- write!(target, "\n")?
- }
- }
- Ok(())
- }
- }
- #[derive(Debug)]
- pub struct TheEndRecord {
- // column and remainder
- e: i32,
- // row and midpoint
- n: i32,
- d: i32,
- x: i32,
- a: i32,
- b: i32,
- c: Option<i32>,
- }
- impl TheEndRecord {
- fn new() -> TheEndRecord {
- TheEndRecord { e: 0, n: 0, d: 0, x: 0, a: 0, b: 0, c: None }
- }
- }
- pub trait Solver {
- fn generate_ter(c: i32, n: i32) -> Self;
- fn solve_na(x: i32, e: i32) -> i32;
- fn solve_n(x: i32, e: i32, a: i32) -> i32;
- fn solve_ed(c: i32) -> (i32, i32);
- fn solve_f(e: i32, d: i32) -> i32;
- fn solve_x(d: i32, n: i32, c: i32) -> i32;
- fn solve_a(d: i32, x: i32) -> i32;
- fn solve_b(c: i32, a: i32) -> i32;
- fn solve_c(&mut self);
- }
- impl Solver for TheEndRecord {
- fn generate_ter(c: i32, n: i32) -> Self {
- let mut ter = TheEndRecord::new();
- let ed = TheEndRecord::solve_ed(c);
- let f = TheEndRecord::solve_f(ed.0, ed.1);
- let x = TheEndRecord::solve_x(ed.1, n, c);
- let a = TheEndRecord::solve_a(ed.1, x);
- let b = TheEndRecord::solve_b(c, a);
- ter.e = ed.0;
- ter.n = n;
- ter.d = ed.1;
- ter.x = x;
- ter.a = a;
- ter.b = b;
- ter.c = Some(c);
- ter
- }
- fn solve_na(x: i32, e: i32) -> i32 {
- (x^2 + e)/2
- }
- fn solve_n(x: i32, e: i32, a: i32) -> i32 {
- ((x * x) + e )/ (2 * a)
- }
- // returns (e,d)
- fn solve_ed(c: i32) -> (i32, i32) {
- let c = (c as f64).sqrt();
- let rem = (c as f64).sqrt() % 1.0;
- (c as i32, rem as i32)
- }
- fn solve_f(e: i32, d: i32) -> i32 {
- e - ((2 * d) + 1).abs()
- }
- fn solve_x(d: i32, n: i32, c: i32) -> i32 {
- ((((d + n) * (d + n) - c) - n) as f64).sqrt() as i32
- }
- fn solve_a(d: i32, x: i32) -> i32 {
- d - x
- }
- fn solve_b(c: i32, a: i32) -> i32 {
- c / a
- }
- fn solve_c(&mut self) {
- let c = self.a * self.b;
- self.c = Some(c);
- }
- }
- pub trait Maps {
- fn prime_map(vec: Vec<TheEndRecord>) -> HashMap<i32, HashMap<i32, LinkedList<TheEndRecord>>>;
- }
- impl Maps for TheEndRecord {
- fn prime_map(vec: Vec<TheEndRecord>) -> HashMap<i32, HashMap<i32, LinkedList<TheEndRecord>>> {
- let mut hashmap: HashMap<i32, HashMap<i32, LinkedList<TheEndRecord>>> = HashMap::new();
- for ter in vec {
- let c = ter.c.unwrap();
- if primal::is_prime(c as u64) {
- hashmap.entry(c as i32)
- .or_insert(HashMap::new())
- .entry(c)
- .or_insert(LinkedList::new())
- .push_back(ter);
- }
- }
- hashmap
- }
- }
- fn main() {
- let mut the_end = TheEnd::new();
- the_end.create_the_end();
- // let mut buffer = File::create("./output.csv").unwrap();
- // the_end.output(&mut buffer).unwrap();
- let five: f64 = 5.0;
- let sqrt = five.sqrt();
- let gr = (1.0 + sqrt) / 2.0;
- let recip = 1.0 / gr;
- println!("{:?}", gr);
- println!("{:?}", recip);
- let mut ter_vec: Vec<TheEndRecord> = Vec::<TheEndRecord>::new();
- for x in -64 .. 64 {
- for y in -64 .. 64 {
- the_end.0.get(&x).unwrap().get(&y).map(|e| {
- for entry in e {
- let vec: Vec<&str> = entry.split(|c| c == '{' || c == ':' || c == '}').collect();
- let mut ter = TheEndRecord {
- e: vec.index(1).parse().unwrap(),
- n: vec.index(2).parse().unwrap(),
- d: vec.index(3).parse().unwrap(),
- x: vec.index(4).parse().unwrap(),
- a: vec.index(5).parse().unwrap(),
- b: vec.index(6).parse().unwrap(),
- c: None,
- };
- ter.solve_c();
- ter_vec.push(ter);
- }
- });
- }
- }
- let prime_map = TheEndRecord::prime_map(ter_vec);
- for entries in prime_map {
- println!("{:?}", entries.0);
- }
- }
- // 2an = xx + e
- // n = xx + e / 2a
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement