-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
start of a simple shell sort fucntion
- Loading branch information
1 parent
6f4f8a0
commit 1a7c5a8
Showing
7 changed files
with
220 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// fn f(a: i8) -> i8 { | ||
// return a + 1; | ||
// } | ||
|
||
// pub struct Row { | ||
// a: i8, | ||
// b: String, | ||
// } | ||
|
||
// impl Row { | ||
// fn print_a(&self) -> () { | ||
// println!("a: {}, yes", self.a); | ||
// } | ||
// } | ||
|
||
// impl std::fmt::Display for Row { | ||
// fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
// write!(f, "(value a: {}, value b: {})", self.a, self.b) | ||
// } | ||
// } | ||
|
||
// impl std::fmt::Display for Vec { | ||
// fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
// write!(f, "(value a: {}, value b: {})", self.a, self.b) | ||
// } | ||
// } | ||
|
||
fn main() { | ||
let mut a: Vec<i64> = vec![]; | ||
a.push(1); | ||
print!("a: {:?}\n", a); | ||
|
||
// let mut a = [1, 2, 3]; | ||
// let b = 4; | ||
// println!("Hello World! b: {}", b); | ||
// for (i, v) in a.iter_mut().enumerate() { | ||
// println!("i: {}, v: {}", i, v); | ||
// } | ||
// let s = format!{"{:?}", a}; | ||
// println!("s: {}", s); | ||
|
||
// let c = 6; | ||
// let d = f(c); | ||
// println!("d: {}", d); | ||
|
||
// let d = Row { | ||
// a: 48, | ||
// b: String::from("Test"), | ||
// }; | ||
|
||
// println!("d: {}", d); | ||
|
||
// d.print_a(); | ||
// d.print_a(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
target/* | ||
Cargo.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "shell_sort" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
oorandom = "11.1.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use oorandom; | ||
|
||
fn check_vec_sorted(v: &Vec<i64>) -> bool { | ||
if v.len() < 2 { | ||
return true; | ||
} | ||
|
||
for i in 0..v.len()-1 { | ||
// println!("i: {}", i); | ||
if v[i] > v[i + 1] { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
fn sort_vec_bubble(v: &mut Vec<i64>) { | ||
if v.len() < 2 { | ||
return; | ||
} | ||
|
||
for i in (0..v.len()).rev() { | ||
for j in 0..i { | ||
// print!("j: {}", j); | ||
if v[j] > v[j + 1] { | ||
// print!(", swap!"); | ||
(v[j], v[j + 1]) = (v[j + 1], v[j]) | ||
} | ||
// println!(""); | ||
} | ||
} | ||
} | ||
|
||
fn main() { | ||
let mut a: Vec<i64> = Vec::new(); | ||
let mut rnd = oorandom::Rand64::new(0x1234); | ||
|
||
for _ in 0..10 { | ||
a.push(rnd.rand_i64()); | ||
} | ||
println!("a: {:?}", a); | ||
|
||
println!("a.len(): {}", a.len()); | ||
|
||
let mut b = a.clone(); | ||
println!("b.len(): {}", b.len()); | ||
println!("b: {:?}", b); | ||
println!("b is sorted? {}", check_vec_sorted(&b)); | ||
sort_vec_bubble(&mut b); | ||
println!("b: {:?}", b); | ||
println!("b is sorted? {}", check_vec_sorted(&b)); | ||
} |
92 changes: 92 additions & 0 deletions
92
sequence_generators/prime_generators/gcd_prime_generator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#! /usr/bin/env -S /usr/bin/time /usr/bin/python3.11 -i | ||
|
||
# -*- coding: utf-8 -*- | ||
|
||
# Some other needed imports | ||
import datetime | ||
import dill | ||
import gzip | ||
import itertools | ||
import os | ||
import pdb | ||
import re | ||
import sys | ||
import time | ||
import traceback | ||
|
||
import numpy as np # need installation from pip | ||
import pandas as pd # need installation from pip | ||
import multiprocessing as mp | ||
|
||
import matplotlib.pyplot as plt # need installation from pip | ||
|
||
from collections import defaultdict | ||
from copy import deepcopy, copy | ||
from dotmap import DotMap # need installation from pip | ||
from functools import reduce | ||
from hashlib import sha256 | ||
from io import BytesIO | ||
from math import gcd | ||
from memory_tempfile import MemoryTempfile # need installation from pip | ||
from shutil import copyfile | ||
from pprint import pprint | ||
from typing import List, Set, Tuple, Dict, Union, Any | ||
from PIL import Image | ||
|
||
CURRENT_WORKING_DIR = os.getcwd() | ||
PATH_ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) | ||
HOME_DIR = os.path.expanduser("~") | ||
TEMP_DIR = MemoryTempfile().gettempdir() | ||
PYTHON_PROGRAMS_DIR = os.path.join(HOME_DIR, 'git/python_programs') | ||
|
||
# set the relative/absolute path where the utils_load_module.py file is placed! | ||
sys.path.append(PYTHON_PROGRAMS_DIR) | ||
from utils_load_module import load_module_dynamically | ||
|
||
var_glob = globals() | ||
load_module_dynamically(**dict(var_glob=var_glob, name='utils', path=os.path.join(PYTHON_PROGRAMS_DIR, "utils.py"))) | ||
load_module_dynamically(**dict(var_glob=var_glob, name='utils_multiprocessing_manager', path=os.path.join(PYTHON_PROGRAMS_DIR, "utils_multiprocessing_manager.py"))) | ||
|
||
mkdirs = utils.mkdirs | ||
MultiprocessingManager = utils_multiprocessing_manager.MultiprocessingManager | ||
|
||
OBJS_DIR_PATH = os.path.join(PATH_ROOT_DIR, 'objs') | ||
mkdirs(OBJS_DIR_PATH) | ||
|
||
PLOTS_DIR_PATH = os.path.join(PATH_ROOT_DIR, 'plots') | ||
mkdirs(PLOTS_DIR_PATH) | ||
|
||
if __name__ == '__main__': | ||
print("Hello World!") | ||
|
||
for v_start in range(1, 100): | ||
# v_start = 6 | ||
l_v = [] | ||
l_gcd = [] | ||
v = v_start | ||
l_v.append(v) | ||
for n in range(2, 1000000): | ||
if n % 1000000 == 0: | ||
print(f"n: {n}") | ||
v_gcd = gcd(n, v) | ||
v = v + v_gcd | ||
|
||
l_gcd.append(v_gcd) | ||
l_v.append(v) | ||
|
||
arr_gcd = np.array(l_gcd) | ||
|
||
arr_idx = np.where(arr_gcd > 1)[0] | ||
arr_gcd_gt_1 = arr_gcd[arr_idx] | ||
|
||
arr_idx_n = arr_idx + 2 | ||
|
||
arr_n_gcd = np.vstack((arr_idx_n, arr_gcd_gt_1)).T | ||
# print(f"arr_n_gcd:\n{arr_n_gcd}") | ||
|
||
print(f"v_start: {v_start}") | ||
print(f"arr_n_gcd.shape[0]: {arr_n_gcd.shape[0]}") | ||
if arr_n_gcd.shape[0] > 0: | ||
max_v_gcd = np.max(arr_n_gcd[:, 1]) | ||
print(f"max_v_gcd: {max_v_gcd}") | ||
print("") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters