Skip to content

Instantly share code, notes, and snippets.

View adrian17's full-sized avatar

Adrian Wielgosik adrian17

View GitHub Profile
@adrian17
adrian17 / collatz.ijs
Last active August 29, 2015 14:17
collatz fractal in J
load 'viewmat'
gen_table =: 4 : '(0j1*(i: x)) +/ i: y'
fractal =: 1 : 0
:
x u"0 (y +~ 30000 %~ 150 gen_table 150) NB. resolution and scale, not sure how to decouple them
)
collatz =: 4 %~ 2 + (7*]) - (2+5*])* 2 o. o.
is_bounded_c =: 4 : '((0: collatz^:x) :: 1:) y' NB. collatz
@adrian17
adrian17 / contour_plot.py
Created March 18, 2015 08:43
/r/dailyprogrammer #206I on reals
import numpy as np
import matplotlib.cm as cm
import matplotlib.pyplot as plt
header, *lines = open("map2.txt").read().splitlines()
R = float(header.split()[2])
H, W = len(lines), len(lines[0])
crops = []
for y, line in enumerate(lines):
for x, c in enumerate(line):
1!:44 ;}:<;.1> (4!:4<'thisfile'){(4!:3) thisfile=.'' NB. boilerplate to set the working directory
input =: cutopen 0 : 0
9 6
A000055 1, 1, 1, 1, 2, 3, 6, 11, 23, 47
A000045 0, 1, 1, 2, 3, 5, 8, 13, 21, 34
A050278 1029, 1028, 1029, 1027, 1028, 1027, 1029, 1028, 1029, 1026
A000010 1, 1, 2, 2, 4, 2, 6, 4, 6, 4
A194508 _1, 1, 0, 2, 1, 0, 2, 1, 3, 2
A000111 1, 1, 1, 2, 5, 16, 61, 272, 1385, 7936
6 1 1
T H T L E D
P E N U R G
I G S D I S
Y G A W S I
W H L Y N T
I T A R G I
main.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <_Z16NormalizedVectorRKN2sf7Vector2IfEE>:
0: 48 83 ec 28 sub rsp,0x28
4: f3 0f 10 0f movss xmm1,DWORD PTR [rdi]
8: f3 0f 10 47 04 movss xmm0,DWORD PTR [rdi+0x4]
@adrian17
adrian17 / whence.ijs
Last active August 29, 2015 14:20
whence for J
whence =: verb define
select. 4!:0 < y
case. _2 do. 'invalid name'
case. _1 do. 'name not defined'
case. 0;1;2;3 do.
index =. 4!:4 < y
select. * >: index
case. 0 do. 'name defined locally'
case. 1 do. > index { 4!:3''
end.
@adrian17
adrian17 / each_cons.h
Last active August 29, 2015 14:21
each_cons in C++
#include <utility>
namespace detail
{
template <typename Fun>
struct function_params
: public function_params<decltype(&Fun::operator())>
{};
template <typename Class, typename Ret, typename... Args> // for lambdas
# [2015-06-01] Challenge #217 [Easy] Lumberjack Pile Problem
# http://www.reddit.com/r/dailyprogrammer/comments/3840rp/20150601_challenge_217_easy_lumberjack_pile/
n, to_place, *piles = [int(n) for n in open("input.txt").read().split()]
print(len(piles))
def get_smallest(piles):
smallest, second = piles[0], piles[0]
for i, pile in enumerate(piles):
@adrian17
adrian17 / TeXSCII.py
Last active August 29, 2015 14:22
TeXSCII (/r/dailyprogrammer #217)
# [2015-06-05] Challenge #217 [Practical Exercise] TeXSCII
# http://www.reddit.com/r/dailyprogrammer/comments/38nhgx/20150605_challenge_217_practical_exercise_texscii/
class Symbol:
def size(self):
raise Exception("should not be used")
def draw(self, canvas, x, y):
raise Exception("should not be used")
def __repr__(self):
if self.contents:
#include <iostream>
using namespace std;
int left;
int main() {
left = 1;
}