Some pretty cool code from the 70s'-80s' that a Reddit user shared at this question.
Here's what u/snarkuzoid wrote:
5x5 Knight's Tour in APL
It puts an A in the middle, then randomly does a knight's tour,
require 'viewmat' | |
NB. rules are base-4, but the base is dependent on the number of states | |
NB. output is 500x500 | |
NB. colors are encoded as hex | |
NB. r - 0 for custom rule, 1 for random rule | |
NB. s - 0 for single 1-cell start, 1 for random start | |
NB. c - 0 for custom colors, 1 for random colors | |
NB. g - iter function | |
NB. edit these to change modes |
Some pretty cool code from the 70s'-80s' that a Reddit user shared at this question.
Here's what u/snarkuzoid wrote:
5x5 Knight's Tour in APL
It puts an A in the middle, then randomly does a knight's tour,
:- use_module(library(dcgs)). | |
:- use_module(library(clpz)). | |
hex_number(N) --> | |
hex(A), | |
hex(B), | |
{ | |
N #= B + A*16 | |
}. |
In reverse chronological order from gist creation:
∇ solvePart1 { | |
⍝ Construct a 2-column array with the first column being the command | |
⍝ and the second being the distance. | |
list ← ⊃ {(d n) ← ⍵ ⊂⍨ ⍵≠↑" " ◊ d (⍎n)}¨ io:read "/home/elias/prog/advent-of-code2021/part02.txt" | |
⍝ Convert each direction instruction into a vector (up, down or right) | |
directions ← { ⊃ ((0 1) (¯1 0) (1 0))[(⊂¨ "forward" "up" "down") ⍳ ⊂⍵] }¨ list[;0] | |
⍝ Multiply each direction with the distance and sum the results | |
⍝ and finally multiply the individual values |
//Geometry | |
#pragma GCC target("avx2") | |
#pragma GCC optimize("O3") | |
#pragma GCC optimize("unroll-loops") | |
#include <bits/stdc++.h> | |
using namespace std; | |
typedef long long int ll; | |
typedef long double ld; | |
typedef complex<ld> pt; |
:- object(particle). | |
% common properties to all particles | |
:- public([ | |
boson/0, fermion/0, | |
mass/1, spin/1, lifetime/1, charge/1 | |
]). | |
:- end_object. |
//header | |
#pragma GCC target ("avx2") | |
#pragma GCC optimize ("O3") | |
#pragma GCC optimize ("unroll-loops") | |
#include <bits/stdc++.h> | |
using namespace std; | |
typedef long long int ll; | |
typedef long double ld; |
I was talking to a coworker recently about general techniques that almost always form the core of any effort to write very fast, down-to-the-metal hot path code on the JVM, and they pointed out that there really isn't a particularly good place to go for this information. It occurred to me that, really, I had more or less picked up all of it by word of mouth and experience, and there just aren't any good reference sources on the topic. So… here's my word of mouth.
This is by no means a comprehensive gist. It's also important to understand that the techniques that I outline in here are not 100% absolute either. Performance on the JVM is an incredibly complicated subject, and while there are rules that almost always hold true, the "almost" remains very salient. Also, for many or even most applications, there will be other techniques that I'm not mentioning which will have a greater impact. JMH, Java Flight Recorder, and a good profiler are your very best friend! Mea
This is a compiled list of falsehoods programmers tend to believe about working with time.
Don't re-invent a date time library yourself. If you think you understand everything about time, you're probably doing it wrong.