mirror of
https://github.com/theoludwig/programming-challenges.git
synced 2025-05-18 12:02:53 +02:00
build(deps): update latest
This commit is contained in:
@ -1,12 +1,13 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Solution {
|
||||
public static void main(String[] args) {
|
||||
String line;
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
while(scanner.hasNextLine()) {
|
||||
line = scanner.nextLine();
|
||||
System.out.println("Hello, " + line + "!");
|
||||
public static void main(String[] args) {
|
||||
String line;
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
while (scanner.hasNextLine()) {
|
||||
line = scanner.nextLine();
|
||||
System.out.println("Hello, " + line + "!");
|
||||
}
|
||||
scanner.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
7
challenges/hello-world/solutions/rust/function/Cargo.lock
generated
Normal file
7
challenges/hello-world/solutions/rust/function/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 = "rust_application"
|
||||
version = "1.0.0"
|
@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "rust_application"
|
||||
version = "1.0.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
@ -1,8 +0,0 @@
|
||||
use std::io::{self, BufRead};
|
||||
|
||||
fn main() {
|
||||
let stdin = io::stdin();
|
||||
for line in stdin.lock().lines() {
|
||||
println!("Hello, {}!", line.unwrap());
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
use std::io::{self, BufRead};
|
||||
|
||||
fn main() {
|
||||
let stdin = io::stdin();
|
||||
for line in stdin.lock().lines() {
|
||||
println!("Hello, {}!", line.unwrap());
|
||||
}
|
||||
}
|
@ -1,22 +1,23 @@
|
||||
string = input()
|
||||
|
||||
def isalphanum(character: str)->bool:
|
||||
|
||||
def is_alphanumeric(character: str) -> bool:
|
||||
is_lowercase_letter = ord(character) >= ord('a') and ord(character) <= ord('z')
|
||||
is_upper_letter = ord(character) >= ord('A') and ord(character) <= ord('Z')
|
||||
is_digit = ord(character) >= ord('0') and ord(character) <= ord('9')
|
||||
return is_upper_letter or is_lowercase_letter or is_digit
|
||||
|
||||
string = string.strip(' ')
|
||||
string = string.strip('-')
|
||||
|
||||
string = string.strip(' ').strip('-')
|
||||
answer = ""
|
||||
current = ""
|
||||
|
||||
for character in string:
|
||||
if character == ' ' or (character == '-' and len(current)>0):
|
||||
if character == ' ' or (character == '-' and len(current) > 0):
|
||||
answer += current
|
||||
answer += '-'
|
||||
current = ""
|
||||
elif isalphanum(character):
|
||||
elif is_alphanumeric(character):
|
||||
current += character
|
||||
|
||||
answer += current
|
||||
|
7
challenges/sorting-algorithms/solutions/rust/bubble-sort/Cargo.lock
generated
Normal file
7
challenges/sorting-algorithms/solutions/rust/bubble-sort/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 = "rust_application"
|
||||
version = "1.0.0"
|
@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "rust_application"
|
||||
version = "1.0.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
@ -1,25 +0,0 @@
|
||||
use std::io::{self, BufRead};
|
||||
|
||||
fn main() {
|
||||
let mut numbers: Vec<i64> = Vec::new();
|
||||
let stdin = io::stdin();
|
||||
for line in stdin.lock().lines().skip(1) {
|
||||
let line = line.unwrap();
|
||||
let number: i64 = line.trim().parse().unwrap();
|
||||
numbers.push(number);
|
||||
}
|
||||
bubble_sort(&mut numbers);
|
||||
for number in numbers {
|
||||
println!("{}", number);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bubble_sort<T: Ord>(array: &mut [T]) {
|
||||
for index1 in 0..array.len() {
|
||||
for index2 in 0..array.len() - 1 - index1 {
|
||||
if array[index2] > array[index2 + 1] {
|
||||
array.swap(index2, index2 + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
use std::io::{self, BufRead};
|
||||
|
||||
fn main() {
|
||||
let mut numbers: Vec<i64> = Vec::new();
|
||||
let stdin = io::stdin();
|
||||
for line in stdin.lock().lines().skip(1) {
|
||||
let line = line.unwrap();
|
||||
let number: i64 = line.trim().parse().unwrap();
|
||||
numbers.push(number);
|
||||
}
|
||||
bubble_sort(&mut numbers);
|
||||
for number in numbers {
|
||||
println!("{}", number);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bubble_sort<T: Ord>(array: &mut [T]) {
|
||||
for index1 in 0..array.len() {
|
||||
for index2 in 0..array.len() - 1 - index1 {
|
||||
if array[index2] > array[index2 + 1] {
|
||||
array.swap(index2, index2 + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
7
challenges/sorting-algorithms/solutions/rust/function/Cargo.lock
generated
Normal file
7
challenges/sorting-algorithms/solutions/rust/function/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 = "rust_application"
|
||||
version = "1.0.0"
|
@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "rust_application"
|
||||
version = "1.0.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
@ -1,15 +0,0 @@
|
||||
use std::io::{self, BufRead};
|
||||
|
||||
fn main() {
|
||||
let mut numbers: Vec<i64> = Vec::new();
|
||||
let stdin = io::stdin();
|
||||
for line in stdin.lock().lines().skip(1) {
|
||||
let line = line.unwrap();
|
||||
let number: i64 = line.trim().parse().unwrap();
|
||||
numbers.push(number);
|
||||
}
|
||||
numbers.sort();
|
||||
for number in numbers {
|
||||
println!("{}", number);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
use std::io::{self, BufRead};
|
||||
|
||||
fn main() {
|
||||
let mut numbers: Vec<i64> = Vec::new();
|
||||
let stdin = io::stdin();
|
||||
for line in stdin.lock().lines().skip(1) {
|
||||
let line = line.unwrap();
|
||||
let number: i64 = line.trim().parse().unwrap();
|
||||
numbers.push(number);
|
||||
}
|
||||
numbers.sort();
|
||||
for number in numbers {
|
||||
println!("{}", number);
|
||||
}
|
||||
}
|
7
challenges/sorting-algorithms/solutions/rust/insertion-sort/Cargo.lock
generated
Normal file
7
challenges/sorting-algorithms/solutions/rust/insertion-sort/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 = "rust_application"
|
||||
version = "1.0.0"
|
@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "rust_application"
|
||||
version = "1.0.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
@ -1,25 +0,0 @@
|
||||
use std::io::{self, BufRead};
|
||||
|
||||
fn main() {
|
||||
let mut numbers: Vec<i64> = Vec::new();
|
||||
let stdin = io::stdin();
|
||||
for line in stdin.lock().lines().skip(1) {
|
||||
let line = line.unwrap();
|
||||
let number: i64 = line.trim().parse().unwrap();
|
||||
numbers.push(number);
|
||||
}
|
||||
insertion_sort(&mut numbers);
|
||||
for number in numbers {
|
||||
println!("{}", number);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn insertion_sort<T: Ord>(array: &mut [T]) {
|
||||
for index in 1..array.len() {
|
||||
let mut index2 = index;
|
||||
while index2 > 0 && array[index2] < array[index2 - 1] {
|
||||
array.swap(index2, index2 - 1);
|
||||
index2 -= 1;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
use std::io::{self, BufRead};
|
||||
|
||||
fn main() {
|
||||
let mut numbers: Vec<i64> = Vec::new();
|
||||
let stdin = io::stdin();
|
||||
for line in stdin.lock().lines().skip(1) {
|
||||
let line = line.unwrap();
|
||||
let number: i64 = line.trim().parse().unwrap();
|
||||
numbers.push(number);
|
||||
}
|
||||
insertion_sort(&mut numbers);
|
||||
for number in numbers {
|
||||
println!("{}", number);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn insertion_sort<T: Ord>(array: &mut [T]) {
|
||||
for index in 1..array.len() {
|
||||
let mut index2 = index;
|
||||
while index2 > 0 && array[index2] < array[index2 - 1] {
|
||||
array.swap(index2, index2 - 1);
|
||||
index2 -= 1;
|
||||
}
|
||||
}
|
||||
}
|
7
challenges/sorting-algorithms/solutions/rust/merge-sort/Cargo.lock
generated
Normal file
7
challenges/sorting-algorithms/solutions/rust/merge-sort/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 = "rust_application"
|
||||
version = "1.0.0"
|
@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "rust_application"
|
||||
version = "1.0.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
@ -1,52 +0,0 @@
|
||||
use std::io::{self, BufRead};
|
||||
|
||||
fn main() {
|
||||
let mut numbers: Vec<i64> = Vec::new();
|
||||
let stdin = io::stdin();
|
||||
for line in stdin.lock().lines().skip(1) {
|
||||
let line = line.unwrap();
|
||||
let number: i64 = line.trim().parse().unwrap();
|
||||
numbers.push(number);
|
||||
}
|
||||
merge_sort(&mut numbers);
|
||||
for number in numbers {
|
||||
println!("{}", number);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn merge_sort(array: &mut Vec<i64>) {
|
||||
if array.len() > 1 {
|
||||
let mid = array.len() / 2;
|
||||
let mut left = array[..mid].to_vec();
|
||||
let mut right = array[mid..].to_vec();
|
||||
merge_sort(&mut left);
|
||||
merge_sort(&mut right);
|
||||
merge(left, right, array);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn merge(left: Vec<i64>, right: Vec<i64>, array: &mut Vec<i64>) {
|
||||
let mut left_index = 0;
|
||||
let mut right_index = 0;
|
||||
let mut array_index = 0;
|
||||
while left_index < left.len() && right_index < right.len() {
|
||||
if left[left_index] <= right[right_index] {
|
||||
array[array_index] = left[left_index];
|
||||
left_index += 1;
|
||||
} else {
|
||||
array[array_index] = right[right_index];
|
||||
right_index += 1;
|
||||
}
|
||||
array_index += 1;
|
||||
}
|
||||
while left_index < left.len() {
|
||||
array[array_index] = left[left_index];
|
||||
left_index += 1;
|
||||
array_index += 1;
|
||||
}
|
||||
while right_index < right.len() {
|
||||
array[array_index] = right[right_index];
|
||||
right_index += 1;
|
||||
array_index += 1;
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
use std::io::{self, BufRead};
|
||||
|
||||
fn main() {
|
||||
let mut numbers: Vec<i64> = Vec::new();
|
||||
let stdin = io::stdin();
|
||||
for line in stdin.lock().lines().skip(1) {
|
||||
let line = line.unwrap();
|
||||
let number: i64 = line.trim().parse().unwrap();
|
||||
numbers.push(number);
|
||||
}
|
||||
merge_sort(&mut numbers);
|
||||
for number in numbers {
|
||||
println!("{}", number);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn merge_sort(array: &mut Vec<i64>) {
|
||||
if array.len() > 1 {
|
||||
let mid = array.len() / 2;
|
||||
let mut left = array[..mid].to_vec();
|
||||
let mut right = array[mid..].to_vec();
|
||||
merge_sort(&mut left);
|
||||
merge_sort(&mut right);
|
||||
merge(left, right, array);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn merge(left: Vec<i64>, right: Vec<i64>, array: &mut Vec<i64>) {
|
||||
let mut left_index = 0;
|
||||
let mut right_index = 0;
|
||||
let mut array_index = 0;
|
||||
while left_index < left.len() && right_index < right.len() {
|
||||
if left[left_index] <= right[right_index] {
|
||||
array[array_index] = left[left_index];
|
||||
left_index += 1;
|
||||
} else {
|
||||
array[array_index] = right[right_index];
|
||||
right_index += 1;
|
||||
}
|
||||
array_index += 1;
|
||||
}
|
||||
while left_index < left.len() {
|
||||
array[array_index] = left[left_index];
|
||||
left_index += 1;
|
||||
array_index += 1;
|
||||
}
|
||||
while right_index < right.len() {
|
||||
array[array_index] = right[right_index];
|
||||
right_index += 1;
|
||||
array_index += 1;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user