Skip to content

Instantly share code, notes, and snippets.

View Mroik's full-sized avatar

Mroik/PositiveC Mroik

View GitHub Profile
@Mroik
Mroik / seq.rs
Last active February 9, 2024 05:29
Seq generator
use std::{env::args, fmt::Debug};
struct Seq<'a, T> {
items: Vec<T>,
func: &'a dyn Fn(T) -> Option<T>,
place: usize,
}
impl<'a, T> Debug for Seq<'a, T> where T: Debug {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
@Mroik
Mroik / sort.rs
Last active February 6, 2024 14:04
An algorithm visualizer
#![allow(arithmetic_overflow)]
use std::{
collections::HashMap,
error::Error,
io::{stdin, stdout, Stdout},
thread::sleep,
time::{Duration, Instant},
};
use crossterm::{
from itertools import repeat
from functools import reduce
def get_dir_nodes(root):
match root["type"]:
case "anyof" | "oneof":
return [root["name"]]
case "dir":
return reduce(lambda a, b: a + b, map(get_dir_nodes, root["children"]), [root["name"]])
@Mroik
Mroik / interval.ml
Created October 19, 2023 00:24
26 Feb 2015
module type Comparable = sig
type t
val compare: t -> t -> int
val to_string: t -> string
end;;
module Interval (IType: Comparable) = struct
type endpoint = IType.t
type interval = endpoint list
exception WrongInterval
type natural = Z | S of natural;;
exception NoSolutionInNatural;;
let rec sum a b =
match b with
| Z -> a
| S x -> sum (S a) x
;;
let rec sub a b =
@Mroik
Mroik / csp.py
Last active July 10, 2023 13:54
Example implementation of AC3 and Path Consistency algorithm to solve for CSP
arcs = {
"a": {
"b": lambda x, y: x != y,
#"c": lambda x, y: x != y,
},
"b": {
"a": lambda x, y: x != y,
"c": lambda x, y: x != y,
},
"c": {
@Mroik
Mroik / render_3d.rs
Last active April 25, 2023 17:30
An attempt to 3D rendering on the terminal using ASCII characters. The rendering works just fine, I don't understand why it isn't centered tho. It looks like I'm looking at the cube from the side.
use std::iter;
type Coordinates = (f64, f64, f64);
fn get_vector(a: Coordinates, b: Coordinates) -> Coordinates {
return (b.0 - a.0, b.1 - a.1, b.2 - a.2);
}
fn scale(point: Coordinates, scalar: f64) -> Coordinates {
return (point.0 * scalar, point.1 * scalar, point.2 * scalar);
@Mroik
Mroik / moving_stuff.rs
Last active April 23, 2023 16:40
2D stuff on terminal
use std::time::Instant;
struct Engine {
timer: Instant,
tick_rate: u128,
fps: u128,
last_update: u128,
last_draw: u128,
acc: u128,
width: i32,
int: type.
z: int.
s: int -> int.
0 = z.
1 = s 0.
2 = s 1.
3 = s 2.
4 = s 3.
5 = s 4.
int: type.
z: int.
s: int -> int.
0 = z.
1 = s 0.
2 = s 1.
3 = s 2.
4 = s 3.
5 = s 4.