Skip to content

Instantly share code, notes, and snippets.

View kotlinsyntax's full-sized avatar
💭
Hi

ConstExpr kotlinsyntax

💭
Hi
View GitHub Profile
//
// Created by kotlinsyntax on 6/7/2024.
//
#ifndef ARRAY_HPP
#define ARRAY_HPP
#include <cstdarg>
#include <cstdio>
#include <cstring>
#include <functional>
@kotlinsyntax
kotlinsyntax / sha256.cpp
Created March 30, 2024 18:44
Sha256 Implementation in C++
#include <cstdint>
#include <string>
#include <sstream>
#include <iomanip>
uint32_t rotateLeft(uint32_t x, uint32_t n) {
return (x << n) | (x >> (32 - n));
}
std::string sha256(const std::string& input) {
@kotlinsyntax
kotlinsyntax / weighted_method.java
Created February 9, 2024 15:13
Simple method to get a random element from a map based on a weight
/**
*
* @param objects: A Map containing the objects to choose from, where the keys represent the objects and the values represent their respective weights.
* @return Returns a randomly selected element from a Map, with selection probabilities proportional to each element's weight.
* @param <T> A randomly selected element from the Map, or null if the Map is empty.
*/
public static <T> T getRandomWeightedElement(Map<T, Number> objects) {
double sum = objects.values().stream().mapToDouble(Number::doubleValue).sum();
for (T item : objects.keySet()) {
random -= objects.get(item).doubleValue();