Started to learn Rust + renewed things out here
This commit is contained in:
parent
ae0b02fc09
commit
911d513829
3
.gitignore
vendored
3
.gitignore
vendored
@ -1 +1,2 @@
|
||||
ass.js
|
||||
.vscode/
|
||||
Rust/*/target/
|
79
C++/bogosort.cpp
Normal file
79
C++/bogosort.cpp
Normal file
@ -0,0 +1,79 @@
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include <locale>
|
||||
|
||||
void shuffle(long unsigned int *arr, int size) {
|
||||
for (int i = 0; i < size; ++i)
|
||||
std::swap(arr[i], arr[(rand() % size)]);
|
||||
}
|
||||
|
||||
bool correct(long unsigned int *arr, int size) {
|
||||
while (--size > 0)
|
||||
if (arr[size - 1] > arr[size])
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string num4(unsigned long int num){
|
||||
std::string cnum = std::to_string(num);
|
||||
if (cnum.length() <= 4) {
|
||||
printf("here\n");
|
||||
return cnum;
|
||||
}
|
||||
std::string postfixs = "kMBTqQsS";
|
||||
int nl = cnum.length()-1;
|
||||
int scale = std::min(int(nl / 3), 8);
|
||||
num /= 10^(3*scale);
|
||||
int decimal_length;
|
||||
if(int(nl / 3) <= 8){
|
||||
decimal_length = 2 - nl % 3;
|
||||
}else{
|
||||
decimal_length = 0;
|
||||
}
|
||||
cnum = std::to_string(num) + postfixs[scale-1]; //f"{num:.{decimal_length}f}{postfixs[scale-1]}";
|
||||
return cnum;
|
||||
}
|
||||
int main(){
|
||||
unsigned long int array_length, i, steps, a, b, c, wasted;
|
||||
time_t start, end;
|
||||
std::cout << "Enter array length: " << std::endl;
|
||||
std::cin >> array_length;
|
||||
unsigned long int array[array_length];
|
||||
for (i = 0; i < array_length; i++){
|
||||
array[i] = i;
|
||||
}
|
||||
shuffle(array, array_length);
|
||||
if (array_length > 100){
|
||||
std::cout << "Array created: " << array_length << " values in the array\n";
|
||||
}else{
|
||||
std::cout << "Array created: " << array << " \n";
|
||||
}
|
||||
time(&start);
|
||||
steps = 0;
|
||||
while(correct(array, array_length)){
|
||||
a = rand() % array_length;
|
||||
b = rand() % array_length;
|
||||
c = array[a];
|
||||
array[a] = array[b];
|
||||
array[b] = c;
|
||||
steps++;
|
||||
//printf("%d\r", steps);
|
||||
}
|
||||
time(&end);
|
||||
wasted = difftime(end, start);
|
||||
if (array_length > 100){
|
||||
std::cout << "Done: " << array_length << " values\n";
|
||||
}else{
|
||||
std::cout << "Done: " << array<< " values\n";
|
||||
}
|
||||
double steps_on_sec;
|
||||
if (wasted > 0){
|
||||
steps_on_sec = steps/wasted;
|
||||
}else{
|
||||
steps_on_sec = 0;
|
||||
}
|
||||
setlocale(LC_ALL, "en_US.UTF-8");
|
||||
printf("Steps: %'d\nWasted %'d seconds\nSpeed: %'f steps/second\n", steps, wasted, steps_on_sec);
|
||||
std::cout << num4(steps) << std::endl;
|
||||
return 0;
|
||||
}
|
BIN
C++/test.o
BIN
C++/test.o
Binary file not shown.
16
C/bogosort.c
16
C/bogosort.c
@ -28,6 +28,19 @@ void shuffle(unsigned long int *array, size_t n)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
char * num4(unsigned long num){
|
||||
char *res = malloc(6 * sizeof(char));
|
||||
sprintf(res, "%lu", num);
|
||||
const size_t length = NELEMS(res);
|
||||
if (length <= 4) {
|
||||
printf("here\n");
|
||||
return res;
|
||||
}
|
||||
printf("anti here\n");
|
||||
return res;
|
||||
}
|
||||
|
||||
int correct(unsigned long *arr, int size) {
|
||||
while ( --size > 0 )
|
||||
if (arr[size]-1 != arr[size-1])
|
||||
@ -64,7 +77,7 @@ int main(){
|
||||
}
|
||||
time(&end);
|
||||
double wasted = difftime(end, start);
|
||||
timespec lol;
|
||||
struct timespec lol;
|
||||
timespec_get(&lol, NULL);
|
||||
printf("\nDone: ");
|
||||
if (arr_len > 100){
|
||||
@ -74,5 +87,6 @@ int main(){
|
||||
}
|
||||
setlocale(LC_ALL, "en_US.UTF-8");
|
||||
printf("Steps: %'d\nWasted %'.0f seconds\nSpeed: %'f steps/second\n", steps, wasted, steps/wasted);
|
||||
printf(num4(steps));
|
||||
return 0;
|
||||
}
|
62
Python/.vscode/launch.json
vendored
62
Python/.vscode/launch.json
vendored
@ -1,62 +0,0 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "tetrio_stats.py: My nickname",
|
||||
"type": "python",
|
||||
"request": "launch",
|
||||
"program": "tetrio_stats.py",
|
||||
"args": ["dan6627"],
|
||||
"console": "integratedTerminal",
|
||||
"justMyCode": true
|
||||
},
|
||||
{
|
||||
"name": "tetrio_stats.py: stqrm",
|
||||
"type": "python",
|
||||
"request": "launch",
|
||||
"program": "tetrio_stats.py",
|
||||
"args": ["stqrm"],
|
||||
"console": "integratedTerminal",
|
||||
"justMyCode": true
|
||||
},
|
||||
{
|
||||
"name": "tetrio_stats.py: czsmall0402",
|
||||
"type": "python",
|
||||
"request": "launch",
|
||||
"program": "tetrio_stats.py",
|
||||
"args": ["czsmall0402"],
|
||||
"console": "integratedTerminal",
|
||||
"justMyCode": true
|
||||
},
|
||||
{
|
||||
"name": "tetrio_stats.py: osk",
|
||||
"type": "python",
|
||||
"request": "launch",
|
||||
"program": "tetrio_stats.py",
|
||||
"args": ["osk"],
|
||||
"console": "integratedTerminal",
|
||||
"justMyCode": true
|
||||
},
|
||||
{
|
||||
"name": "tetrio_stats.py: Invalid nickname",
|
||||
"type": "python",
|
||||
"request": "launch",
|
||||
"program": "tetrio_stats.py",
|
||||
"args": ["dan6626"],
|
||||
"console": "integratedTerminal",
|
||||
"justMyCode": true
|
||||
},
|
||||
{
|
||||
"name": "tetrio_stats.py: Banned",
|
||||
"type": "python",
|
||||
"request": "launch",
|
||||
"program": "tetrio_stats.py",
|
||||
"args": ["furry"],
|
||||
"console": "integratedTerminal",
|
||||
"justMyCode": true
|
||||
},
|
||||
]
|
||||
}
|
53
Python/parsing_by_railway.py
Normal file
53
Python/parsing_by_railway.py
Normal file
@ -0,0 +1,53 @@
|
||||
import requests, time, os
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
def clear():
|
||||
_ = os.system('cls') if os.name == 'nt' else os.system('clear')
|
||||
|
||||
def main_loop():
|
||||
site = requests.get("https://pass.rw.by/be/route/?from=%D0%9D%D1%8F%D1%81%D1%8F%D1%82%D0%B0&from_exp=2100076&from_esr=157103&to=%D0%9C%D1%96%D0%BD%D1%81%D0%BA+%D0%9F%D0%B0%D1%81%D0%B0%D0%B6%D1%8B%D1%80%D1%81%D0%BA%D1%96&to_exp=2100001&to_esr=140210&front_date=25+%D0%BA%D1%80%D0%B0%D1%81.+2023&date=2023-04-25")
|
||||
if site.ok:
|
||||
soup = BeautifulSoup(site.content, features="html.parser")
|
||||
table = soup.select("#sch-route > div.col-md-9.col-xs-12 > div.sch-le-wrap > div.sch-table.js-schSort.js-schedule > div.sch-table__body-wrap > div")
|
||||
entrys = list(table[0].children)
|
||||
while True:
|
||||
try:
|
||||
entrys.remove("\n")
|
||||
except ValueError:
|
||||
break
|
||||
entrys = entrys[:-1]
|
||||
first_entry_text = [str for str in entrys[0].stripped_strings]
|
||||
text_entrys = []
|
||||
for e in entrys:
|
||||
ent = [str for str in e.stripped_strings]
|
||||
if ent[0] == "Самы хуткі" or ent[0] == "Самы недарагі":
|
||||
ent.pop(0)
|
||||
if ent[11] == "Месцаў няма":
|
||||
text_entrys.append(ent[4] + " - " + ent[6] + ": " + ent[11])
|
||||
else:
|
||||
cutting_the_edge = ent[11:]
|
||||
cutting_the_edge.pop()
|
||||
variants = ""
|
||||
for i in cutting_the_edge:
|
||||
if i == "BYN":
|
||||
variants += i+", "
|
||||
else:
|
||||
variants += i+" "
|
||||
text_entrys.append(ent[4] + " - " + ent[6] + ": " + variants)
|
||||
train_name = first_entry_text[0] + " " + first_entry_text[1] + " " + first_entry_text[2]
|
||||
print("\033[H", time.ctime(), train_name)
|
||||
for i in text_entrys:
|
||||
print(i, " ")
|
||||
|
||||
else:
|
||||
print("\033[H", time.ctime(), site.status_code)
|
||||
time.sleep(60)
|
||||
|
||||
if __name__ == "__main__":
|
||||
clear()
|
||||
print("\033[?25l")
|
||||
try:
|
||||
while True:
|
||||
main_loop()
|
||||
except KeyboardInterrupt:
|
||||
print("\033[18H")
|
@ -4,7 +4,7 @@ import locale
|
||||
import json
|
||||
import datetime
|
||||
import math
|
||||
locale.setlocale(locale.LC_ALL, ('en', 'UTF-8'))
|
||||
# locale.setlocale(locale.LC_ALL, ('en', 'UTF-8'))
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Insert nickname or id of player and get detalied stats into output')
|
||||
parser.add_argument("nick", metavar="p", type=str,
|
||||
@ -301,9 +301,7 @@ if teto_records['data']['zen'] is not None:
|
||||
print("\n")
|
||||
data_to_print = [
|
||||
("", "Zen"),
|
||||
("Level", teto_records['data']['zen']['level']),
|
||||
("Score", locale.format_string(
|
||||
'%.0f', teto_records['data']['zen']['score'], True))
|
||||
(f"Level {teto_records['data']['zen']['level']}", f"Score {locale.format_string('%.0f', teto_records['data']['zen']['score'], True)}")
|
||||
]
|
||||
|
||||
for key, value in data_to_print:
|
||||
|
@ -6,7 +6,7 @@ import pygame # pip install pygame
|
||||
|
||||
# Моделирование жизни клетки
|
||||
WORLD_SIZE = [64, 64] # Размер мира x y
|
||||
CELL_SIZE = 14 # Размер ячейки мира при отрисовке в пикселях
|
||||
CELL_SIZE = 10 # Размер ячейки мира при отрисовке в пикселях
|
||||
SPAWN_CELLS = 256 # Сколько появится в мире
|
||||
CELLS_COLORS = ( # RGB цвета, которые может иметь клетка
|
||||
(200, 0, 0),
|
||||
|
@ -1,5 +1,5 @@
|
||||
# GitHub аккаунт самого унылого разраба
|
||||
Может разработать какую-нибудь простенькую хрень на JavaScript/Python. Репозиторий, из которого берётся этот README, является моей личной свалкой, в которой валяется всякая хрень.
|
||||
Репозиторий, из которого берётся этот README, является моей личной свалкой, в которой валяется всякая хрень.
|
||||
|
||||
[](https://github.com/anuraghazra/github-readme-stats)
|
||||
|
||||
|
7
Rust/cargo_test/Cargo.lock
generated
Normal file
7
Rust/cargo_test/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "cargo_test"
|
||||
version = "0.1.0"
|
8
Rust/cargo_test/Cargo.toml
Normal file
8
Rust/cargo_test/Cargo.toml
Normal file
@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "cargo_test"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
3
Rust/cargo_test/src/main.rs
Normal file
3
Rust/cargo_test/src/main.rs
Normal file
@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
75
Rust/guess_the_number/Cargo.lock
generated
Normal file
75
Rust/guess_the_number/Cargo.lock
generated
Normal file
@ -0,0 +1,75 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "guess_the_number"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"rand",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.147"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.11.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
9
Rust/guess_the_number/Cargo.toml
Normal file
9
Rust/guess_the_number/Cargo.toml
Normal file
@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "guess_the_number"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
rand = "0.8.5"
|
33
Rust/guess_the_number/src/main.rs
Normal file
33
Rust/guess_the_number/src/main.rs
Normal file
@ -0,0 +1,33 @@
|
||||
use std::io;
|
||||
use std::cmp::Ordering;
|
||||
use rand::Rng;
|
||||
|
||||
fn main() {
|
||||
println!("Guess the number!");
|
||||
|
||||
let secret_number = rand::thread_rng().gen_range(1..=100);
|
||||
|
||||
loop{
|
||||
println!("Please input your guess.");
|
||||
|
||||
let mut guess = String::new();
|
||||
|
||||
io::stdin().read_line(&mut guess).expect("Failed to read line");
|
||||
|
||||
let guess: u32 = match guess.trim().parse() {
|
||||
Ok(num) => num,
|
||||
Err(_) => continue,
|
||||
};
|
||||
|
||||
println!("You guessed: {guess}");
|
||||
|
||||
match guess.cmp(&secret_number) {
|
||||
Ordering::Less => println!("Too small!"),
|
||||
Ordering::Greater => println!("Too big!"),
|
||||
Ordering::Equal => {
|
||||
println!("You win!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
3
Rust/hello_world.rs
Normal file
3
Rust/hello_world.rs
Normal file
@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
println!("Ку!");
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user