This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstddef> | |
#include <cstdint> | |
#include <cstring> | |
#include <limits> | |
std::uint32_t floatrep(float x) { | |
std::uint32_t n; | |
std::memcpy(&n, &x, sizeof(x)); | |
return n; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cassert> | |
#include <cstddef> | |
#include <initializer_list> | |
#include <tuple> | |
#include <variant> | |
template <std::size_t ORDER, typename... Ts> | |
class multivariant { | |
std::variant<Ts...> members[ORDER]; | |
public: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <typename T, typename E, E SYMBOL> | |
class Proxy { | |
public: | |
Proxy(T& value, E& which) : ref(value), which(which) {} | |
Proxy& operator=(const T& value) { | |
ref = value; | |
which = SYMBOL; | |
} | |
operator T() { return ref; } | |
protected: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstddef> | |
#include <span> | |
std::span<int> allocate(std::size_t size) { | |
int* storage = new int[size]; | |
return std::span<int>{storage, size}; | |
} | |
void deallocate(std::span<int>& items) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import combinations | |
from math import log, ceil | |
def common_bases(x: int, y: int) -> int: | |
""" | |
Returns a list of all the bases common to x and y | |
That is to say, all bases n such that n can be raised by an integer power to | |
produce x or y | |
The list returned is sorted in ascending order, and may be empty if there |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class List { | |
public: | |
constexpr ~List() { | |
if (next != nullptr) { | |
delete next; | |
next = nullptr; | |
} | |
} | |
constexpr void push(int n) { | |
get_end().next = new List; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdlib> | |
#include <iostream> | |
signed operator "" _signed(const char* literal) { | |
std::cout << "actual literal value: " << literal << std::endl; | |
return std::strtol(literal, nullptr, 0); | |
} | |
int main() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstddef> | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
struct RepeatingDecimal { | |
std::vector<bool> integer; | |
std::vector<bool> decimal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstddef> | |
namespace { | |
/* | |
* Helper function, variadic xor | |
* It works by counting the number of true values and returning true only | |
* if this number is 1. | |
*/ | |
template <typename T> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstddef> | |
#include <vector> | |
template <typename T> | |
class ContainerAdaptor { | |
public: | |
constexpr ContainerAdaptor(std::vector<T>& container) : _container(container) {} | |
// no const version of operator[] is provided, because we always want to resize the vector on out-of-bounds |