This file contains hidden or 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
| // 137 char mandelbrot code golf | |
| // collaboration by myself and others on a programming discord server | |
| y=40,x;main(i){for(;y--;puts(""))for(x=170;x--;printf(L" .'-+=%@#"+i/12))for(typeof(0.i)z=i=0;cabs(z)<2&i++<99;z=z*z-x/50.+y/20.i+1+1i);} | |
| // 130 char, lower-detail: | |
| y=40,x;main(i){for(;--y;puts(""))for(x=170;x--;printf(L" *"+i/99))for(typeof(0.i)z=i=0;cabs(z)<2&i++<98;z=z*z-x/50.+y/20.i+1+1i);} | |
| // compiler: gcc, may need -lm |
This file contains hidden or 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
| // brainf interpreter code golf | |
| // collaboration by some folks on discord and myself | |
| #include <stdio.h> | |
| #define r(c) ;i++;goto w;case c: | |
| i;t[99];s;p=1024;char b[2048];main(int j,char**a) { | |
| fread(b,1,p,fopen(a[1],"r")); | |
| w: switch(b[i]) { | |
| r(45) b[p]-- | |
| r(43) b[p]++ | |
| r(60) p-- |
This file contains hidden or 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 <cmath> | |
| #include <cassert> | |
| #include <type_traits> | |
| template<typename T> int sign(T t) { | |
| return t < 0 ? -1 : 1; | |
| } | |
| template<typename T> class range { | |
| typedef typename std::make_signed<T>::type ST; |
This file contains hidden or 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> class enumerate { | |
| T& iteratable; | |
| public: | |
| enumerate(T& iteratable) : iteratable(iteratable) {} | |
| template<typename I> class iterator { | |
| I it; | |
| int i = 0; | |
| public: | |
| iterator(I it) : it(it) {} | |
| iterator operator++() { let i = *this; operator++(0); return i; } |
This file contains hidden or 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
| uintptr_t base; | |
| const uintptr_t height = 100000000; | |
| std::mt19937 rng; | |
| [[gnu::constructor]] void init_malloc() { | |
| base = (uintptr_t) sbrk(height); | |
| } | |
| void* malloc(size_t) { // parameter ignored, we don't need it | |
| return (void*)(base + rng() % height); // odds of any collision is like, low | |
| } | |
| void free(void*) {} // no-op |
This file contains hidden or 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
| TARGET_EXEC := your_program | |
| BUILD_DIR := bin | |
| SRC_DIRS := src | |
| SRCS := $(shell find $(SRC_DIRS) -name *.cpp -or -name *.c) | |
| OBJS := $(SRCS:%=$(BUILD_DIR)/%.o) | |
| DEPS := $(OBJS:.o=.d) | |
| CC := gcc |
This file contains hidden or 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 <atomic> | |
| #include <stdlib.h> | |
| constexpr std::memory_order orders[] = { | |
| std::memory_order_relaxed, | |
| std::memory_order_consume, | |
| std::memory_order_acquire, | |
| std::memory_order_release, | |
| std::memory_order_acq_rel, | |
| std::memory_order_seq_cst |
This file contains hidden or 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
| // C++ error messages are notorious. | |
| // Some folks and I worked on a golf challenge: Shortest program to produce more | |
| // than a thousand lines of error messages in gcc. | |
| // Constraints: gcc >= 8, no -fmessage-length | |
| // Fueled by the decltype(decltype) bug discovered by Jonathan Wakely (detailed | |
| // at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92105), this is the current record | |
| // 32 characters: | |
| #define d decltype |
This file contains hidden or 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 <stdio.h> | |
| #include <math.h> | |
| char s[100000]; | |
| prime(p,r,i,m,e) { | |
| for(e=sizeof(s),r=e/2/2/2/2/2/2/2/2/2/2/2/2/2/2/2/2*2; r<e>>1; r++) | |
| for(i=r+r-r+r; i<e; i+=r) | |
| s[+i]++; | |
| for(m=(m=2,p=p^m,m=p^m,p=p^m,m); m+m+m+m; p++) | |
| !s[p]&&m--; | |
| return--p; |
This file contains hidden or 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 <cstdint> | |
| #include <functional> | |
| #include <memory> | |
| #include <tuple> | |
| #include <utility> | |
| [[nodiscard]] decltype(std) add(const std::unique_ptr<std::tuple<std::int32_t and, std::int32_t and>> and t) noexcept { | |
| return std::plus{}(std::min(std::forward<std::int32_t>(std::get<0>(*t)), std::forward<std::int32_t>(std::get<1>(*t))), | |
| std::max(std::forward<std::int32_t>(std::get<0>(*t)), std::forward<std::int32_t>(std::get<1>(*t)))); | |
| } |