updated license information

This commit is contained in:
Sven Vogel 2023-04-21 12:38:18 +02:00
parent 885f3cdf0d
commit 1f094c137d
8 changed files with 195 additions and 17 deletions

8
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/duplicates/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/duplicates/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
.idea/misc.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Rust-Programming.iml" filepath="$PROJECT_DIR$/.idea/Rust-Programming.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@ -1,19 +1,123 @@
/**
* _ _ _ _
* __ ___ __(_) |_| |_ ___ _ __ | |__ _ _
* \ \ /\ / / '__| | __| __/ _ \ '_ \ | '_ \| | | |
* \ V V /| | | | |_| || __/ | | | | |_) | |_| |
* \_/\_/ |_| |_|\__|\__\___|_| |_| |_.__/ \__, |
* |___/
* ____ __ __ _
* / ___|_ _____ _ __ \ \ / /__ __ _ ___| |
* \___ \ \ / / _ \ '_ \ \ \ / / _ \ / _` |/ _ \ |
* ___) \ V / __/ | | | \ V / (_) | (_| | __/ |
* |____/ \_/ \___|_| |_| \_/ \___/ \__, |\___|_|
* |___/
* Licensed under the GPLv2 License, Version 2.0 (the "License");
* Copyright (c) Sven Vogel
*/
use crate::FloatOrChar::{Char, Float};
use std::collections::{HashMap, HashSet};
use std::fmt::Debug;
use std::usize;
/// pretty useless enum that either contains a char or
/// a f32
#[derive(Debug)]
enum FloatOrChar {
Float(f64),
Char(char),
}
impl PartialEq for FloatOrChar {
/// only returns true if
/// self and other of the same enum variant and their wrapped values match
fn eq(&self, other: &Self) -> bool {
return match self {
Float(x) => {
if let Float(y) = *other {
// compare floats with tolerance
(*x - y).abs() < f64::EPSILON
} else {
false // other is not a Float32
}
}
Char(x) => {
if let Char(y) = *other {
*x == y
} else {
false // other is not a Char
}
}
};
}
/// opposite of equals
fn ne(&self, other: &Self) -> bool {
!self.eq(other)
}
}
/// count all duplicate values in an array
/// equivalence is determined by the [`PartialEq`] trait
fn duplicates<T>(arr: &[T]) -> usize
where
T: PartialEq + Debug,
{
let mut total_dups = 0;
fn duplicates<T>(arr: &[T]) -> usize where T: PartialEq {
let mut dups = 0;
for x in 0..arr.len() {
let to_cmp = &arr[x];
let mut count = 0;
for y in (x + 1)..arr.len() {
if &arr[y] == to_cmp {
dups += 1;
count += 1;
}
}
total_dups += count;
if count > 0 {
println!("Element {:?} was duplicated {} time(s)", to_cmp, count);
}
dups * 2
}
total_dups
}
/// read some data from stdin and stores it into a vector.
/// the reading of data stops if the input is neither a float nor a single character.
/// input line are trimmed
fn read_array() -> Vec<FloatOrChar> {
// temporary string buffer for reading
let mut buf = String::new();
// storage for our parsed array
let mut elems = Vec::<FloatOrChar>::new();
println!("Enter some floats or characters, one per line:");
loop {
// read some characters
std::io::stdin().read_line(&mut buf).unwrap();
// parse the data
if let Ok(float) = buf.trim().parse::<f64>() {
elems.push(Float(float));
} else if let Ok(char) = buf.trim().parse::<char>() {
elems.push(Char(char));
} else {
break;
}
// empty string
buf.clear();
}
elems
}
fn main() {
let arr = ['😇', '🙈', '💀', '💦', '💣', '💀'];
let arr = &read_array()[..];
println!("Duplicates: {}", duplicates(&arr));
}

View File

@ -1,4 +1,21 @@
/**
* _ _ _ _
* __ ___ __(_) |_| |_ ___ _ __ | |__ _ _
* \ \ /\ / / '__| | __| __/ _ \ '_ \ | '_ \| | | |
* \ V V /| | | | |_| || __/ | | | | |_) | |_| |
* \_/\_/ |_| |_|\__|\__\___|_| |_| |_.__/ \__, |
* |___/
* ____ __ __ _
* / ___|_ _____ _ __ \ \ / /__ __ _ ___| |
* \___ \ \ / / _ \ '_ \ \ \ / / _ \ / _` |/ _ \ |
* ___) \ V / __/ | | | \ V / (_) | (_| | __/ |
* |____/ \_/ \___|_| |_| \_/ \___/ \__, |\___|_|
* |___/
* Licensed under the GPLv2 License, Version 2.0 (the "License");
* Copyright (c) Sven Vogel
*/
/// recursive variant of the fibonacci function
fn fib_rec(x: u128) -> u128 {
if x < 2 {
return x;
@ -7,6 +24,7 @@ fn fib_rec(x: u128) -> u128 {
return fib_rec(x - 1) + fib_rec(x - 2);
}
/// iterative variant of the fibonacci function
fn fib_loop(x: u128) -> u128 {
let mut sum = 0;
let mut sum2 = 1;
@ -20,6 +38,5 @@ fn fib_loop(x: u128) -> u128 {
}
fn main() {
println!("{}", fib_loop(5));
}

View File

@ -1,4 +1,20 @@
/* Compressed version:
/**
* _ _ _ _
* __ ___ __(_) |_| |_ ___ _ __ | |__ _ _
* \ \ /\ / / '__| | __| __/ _ \ '_ \ | '_ \| | | |
* \ V V /| | | | |_| || __/ | | | | |_) | |_| |
* \_/\_/ |_| |_|\__|\__\___|_| |_| |_.__/ \__, |
* |___/
* ____ __ __ _
* / ___|_ _____ _ __ \ \ / /__ __ _ ___| |
* \___ \ \ / / _ \ '_ \ \ \ / / _ \ / _` |/ _ \ |
* ___) \ V / __/ | | | \ V / (_) | (_| | __/ |
* |____/ \_/ \___|_| |_| \_/ \___/ \__, |\___|_|
* |___/
* Licensed under the GPLv2 License, Version 2.0 (the "License");
* Copyright (c) Sven Vogel
*
* Compressed version:
*
* type V=(f64,f64);fn t(a:V,b:V,f:fn(
* a:f64,b:f64)->f64)->V{(f(a.0,b.0),f
@ -6,15 +22,10 @@
* t(t((2.42,2.07),(0.3,3.2),|a,b|{a/b
* }),t((1.7,2.3),(0.73,0.42),|a,b|{a*
* b}),|a,b|{a-b}))}
*
*/
fn merge_tuple(a: (f64, f64), b: (f64, f64), f: fn(a: f64, b: f64) -> f64) -> (f64, f64) {
(
f(a.0, b.0),
f(a.1, b.1),
)
(f(a.0, b.0), f(a.1, b.1))
}
fn add_tuple(a: (f64, f64), b: (f64, f64)) -> (f64, f64) {
@ -34,5 +45,11 @@ fn div_tuple(a: (f64, f64), b: (f64, f64)) -> (f64, f64) {
}
fn main() {
println!("{:#?}", sub_tuple(div_tuple((2.42, 2.07), (0.3, 3.2)), mul_tuple((1.7, 2.3), (0.73, 0.42))));
println!(
"{:#?}",
sub_tuple(
div_tuple((2.42, 2.07), (0.3, 3.2)),
mul_tuple((1.7, 2.3), (0.73, 0.42))
)
);
}