Skip to content

Instantly share code, notes, and snippets.

View jiniux's full-sized avatar
🎯
Focusing, but not a lot

jiniux

🎯
Focusing, but not a lot
View GitHub Profile
@jiniux
jiniux / p001.swift
Last active November 25, 2019 14:17
Problem 1 from Project Euler Archive (Solution in Swift)
/*
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
*/
import Foundation
@jiniux
jiniux / p002.swift
Created November 25, 2019 14:17
Problem 2 from Project Euler Archive (Solution in Swift)
/*
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
*/
@jiniux
jiniux / p003.swift
Created November 25, 2019 14:52
Problem 3 from Project Euler Archive (Solution in Swift)
/*
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
*/
import Foundation
@jiniux
jiniux / rot13.c
Created September 24, 2020 13:51
ROT13 example in C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define TOTAL_LETTERS 26
#define KEY 13
char rotc(char ch, int key) {
if (ch >= 'A' && ch <= 'Z') {
return 'A' + ((ch - 'A' + key) % TOTAL_LETTERS);
@jiniux
jiniux / day1_p1.rs
Last active December 2, 2020 14:45
Advent of Code 2020 - Day 1, Part 1
use std::{error::Error, env::args, fs::File, io::Read};
fn load_input(path : &str) -> Result<Vec<i64>, std::io::Error> {
let mut file = File::open(path)?;
let mut data = String::new();
file.read_to_string(&mut data)?;
let data : Vec<i64> = data.split('\n')
.map(|line| line.parse::<i64>().unwrap_or(0)).collect();
@jiniux
jiniux / day1_p2.rs
Last active December 2, 2020 14:44
Advent of Code 2020 - Day 1, Part 2
use std::{error::Error, env::args, fs::File, io::Read};
fn load_input(path : &str) -> Result<Vec<i64>, std::io::Error> {
let mut file = File::open(path)?;
let mut data = String::new();
file.read_to_string(&mut data)?;
let data : Vec<i64> = data.split('\n')
.map(|line| line.parse::<i64>().unwrap_or(0)).collect();
@jiniux
jiniux / day2_p1.rs
Last active December 3, 2020 10:56
Advent of Code 2020 - Day 2, Part 1
use std::{env::args, error::Error, fs::File, ops::RangeInclusive, io::Read};
type PasswordPolicy = (RangeInclusive<u32>, char, String);
fn load_input(path : &str) -> Result<Vec<PasswordPolicy>, std::io::Error> {
let mut file = File::open(path)?;
let mut data = String::new();
file.read_to_string(&mut data)?;
@jiniux
jiniux / day2_p2.rs
Created December 3, 2020 10:58
Advent of Code 2020 - Day 2, Part 2
use std::{env::args, error::Error, fs::File, ops::RangeInclusive, io::Read};
type PasswordPolicy = (RangeInclusive<u32>, char, String);
fn load_input(path : &str) -> Result<Vec<PasswordPolicy>, std::io::Error> {
let mut file = File::open(path)?;
let mut data = String::new();
file.read_to_string(&mut data)?;
@jiniux
jiniux / day3_p1.rs
Last active December 4, 2020 12:57
Advent of Code 2020 - Day 3, Part 1
use std::{env::args, error::Error, fs::File, io::Read};
enum MapEntity {
Tree,
Square
}
struct Map {
pattern : Vec<Vec<MapEntity>>,
@jiniux
jiniux / day3_p2.rs
Last active December 4, 2020 12:57
Advent of Code 2020 - Day 3, Part 2
use std::{env::args, error::Error, fs::File, io::Read};
enum MapEntity {
Tree,
Square
}
struct Map {
pattern : Vec<Vec<MapEntity>>,