View strobogrammatic_number.cpp
// https://leetcode.com/problems/strobogrammatic-number/description/
template <typename InputIter, typename Func>
struct mapped_iterator {
InputIter iter;
Func mapper;
mapped_iterator(InputIter iter, Func mapper)
: iter{iter}, mapper{mapper}
{ }
View ondulator.html
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Ondulator</title>
<script>
const PI = Math.PI;
const TAU = 2 * PI;
View integer_english.cpp
// https://leetcode.com/problems/integer-to-english-words/
class Solution {
static constexpr int BILLION = 1000000000;
static constexpr int MILLION = 1000000;
static constexpr int THOUSAND = 1000;
static constexpr int HUNDRED = 100;
static constexpr int TEN = 10;
public:
string numberToWords(int num) {
if (num == 0) return "Zero";
View text_justification.cpp
// https://leetcode.com/problems/text-justification/
class Solution {
public:
vector<string> fullJustify(vector<string>& words, int maxWidth) {
for (string& word : words) {
if (word.size() > maxWidth)
return {};
}
vector<string> ans;
View validate_ip.cpp
// https://leetcode.com/problems/validate-ip-address/
class Solution {
public:
string validIPAddress(string ip) {
try {
if (ip.find(':') != string::npos) {
parseV6(ip);
return "IPv6";
} else if (ip.find('.') != string::npos) {
parseV4(ip);
View Fruits.hs
import Data.SBV
fruits :: SInteger -> SInteger -> SInteger -> SBool
fruits a b c = equation &&& positive
where
x = sFromIntegral a :: SReal
y = sFromIntegral b :: SReal
z = sFromIntegral c :: SReal
equation = x / (y + z) + y / (x + z) + z / (x + y) .== 4
View Circle.hs
import Control.Monad
import Math.NumberTheory.Logarithms (integerLog2)
simulate :: Integer -> Integer
simulate n = head (go [1..n])
where
go [x] = [x]
go (x1:x2:xs) = go (xs ++ [x1])
View out_of_process.py
def out_of_process(func):
from types import GeneratorType
GENERATOR = b'#GENERATOR#'
DONE = b'#DONE#'
def runner(conn, *args, **kwargs):
return_value = func(*args, **kwargs)
if isinstance(return_value, GeneratorType):
conn.send(GENERATOR)
for val in return_value:
View wrap_wrap.cpp
#include <type_traits>
template <typename T>
struct wrap;
template <typename T>
constexpr auto is_wrap_v = false;
template <typename T>
constexpr auto is_wrap_v<wrap<T>> = true;
View JavaStringMemchr.java
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import sun.misc.Unsafe;
import java.lang.reflect.Field;
public class Program {
private static final Unsafe UNSAFE;