Skip to content

Instantly share code, notes, and snippets.

View H2CO3's full-sized avatar
🦀

Árpád Goretity  H2CO3

🦀
View GitHub Profile
function getLargestArray(a, b) {
let as = a.map(_ => 'x').join('');
let bs = b.map(_ => 'x').join('');
let arx = new RegExp(as);
let brx = new RegExp(bs);
let aNotShorter = as.match(brx) !== null;
let bNotShorter = bs.match(arx) !== null;
let compare = aNotShorter - bNotShorter;
switch (compare) {
case -1: return b;
@H2CO3
H2CO3 / queens.rs
Created December 26, 2017 09:46
n-queens problem in Rust, with (some) reference counting
use std::rc::Rc;
#[derive(Copy, Clone)]
struct IntInt {
x: i32,
y: i32,
}
struct Cons<T: Copy> {
elt: T,
#include <vector>
#include <cstdio>
struct Node {
int value;
Node *next;
Node(int _value, Node *_next): value(_value), next(_next) {}
~Node() {
@H2CO3
H2CO3 / test_guard.rs
Created October 15, 2017 18:58
Protect against forgetting to call a test case evaluation function
fn make_test_evaluator() -> Box<Fn(YourTestCaseTypeHere)> {
use std::cell::RefCell;
struct EvalGuard(bool);
impl Drop for EvalGuard {
fn drop(&mut self) {
if !self.0 {
panic!("Did not actually evaluate test cases");
}
Rust…
- is functional
- but not pure, so you can printf-debug without IO() ALL THE FUNCTIONS
- has a strong Hindley-Milner type system
- but has convenient implicit coercions too, so you don't have to cast all over the place
- safe and high-level (with ownership, static/dynamic borrowing, Send and Sync)
- yet deterministic and fast with zero-/low-cost abstractions and RAII
- has a standard build system and dependency management
- but it doesn't force you to use it, and it has a simple Make-like CLI that doesn't hurt
- lets you write your code in the 'modern' IDE of your choice with all bells and whistles
Békésen ülök a Mammut KFC-ben, mellettem két, 24-28 éves forma lány. Egyikük hevesen ecseteli
a pasizás terén véghezvitt hőstetteit.
Sztori #1: Volt egy barátja, annak egy húga. A húgnak volt egy pasija. A csaj ezzel a csávóval jött össze,
még mielőtt a barátjával szakított volna, ezért hetekig titkolóztak – amit a leányzó láthatóan roppant humorosnak tartott.
Sztori #2: Nagyon büszke volt arra is, hogy ezután (meg előtt) volt pár egyéjszakás kalandja is. (vajon közben is voltak…?)
Sztori #3: 2 hónapig volt egy 20 éves (!!!) barátja, aki állítása szerint 16-ként viselkedett. De legalább vicces volt!
Úgy látszik, azt, hogy – idézem "mások előtt is képtelen volt normálisan viselkedni" –, ez teljesen jól ellensúlyozta.
Na, ezek után végre kifújta magát, így hagyta a másik lányt is szóhoz jutni, aki erre: "Jé, ez olyan érdekes! Nekem
#include <stdio.h>
#include "bmp.h"
typedef struct __attribute__((packed)) {
uint16_t bfType; // specifies the file type
uint32_t bfSize; // specifies the size in bytes of the bitmap file
uint16_t bfReserved1; // reserved; must be 0
uint16_t bfReserved2; // reserved; must be 0
uint32_t bfOffBits; // species the offset in bytes from the bitmapfileheader to the bitmap bits
Learning TODO:
~~~~~~~~~~~~~~
* Theoretical(-ish) Stuff:
------------------------
- Computer Science, Algorithms, Data Structures (e.g. Finite Automata,
Classic Graph Algos, Searching and Sorting, Solutions to NP-Complete
Problems, Inventing and Using Heuristics, Complexity Theory in Depth,
use std::ops::{Add,Sub,Mul,Div,Neg};
use std::fmt;
use std::fmt::Display;
#[derive(Clone, Copy, Debug)]
struct Complex {
re: f32,
im: f32,
}
1 + 0.000i 1 + 1.732i 1 - 1.732i
1 + 1.732i -2 + 3.464i 4 - 0.000i
1 - 1.732i 4 - 0.000i -2 - 3.464i