Skip to content

Instantly share code, notes, and snippets.

View AlephAlpha's full-sized avatar

AlephAlpha

View GitHub Profile
+++++
++++-+><++++-+++<>-+><<>-++++><<>++-+++++
++++++-++-+++++<>+++++++++-++<>+++++++++->< +++
+++++><><+++-+-+<><>++++-+++- ++.>+<<> <+-<<<<<+-
+><<<>> <>>>>+-> <>-+>>>+-+
++><+++ ++>-+>> >>>[>++ +>-+-<>++-
<+-><++- ++<-]<< ><<<>+- <<<+++-><+-
++++++++ ><++++++ ++++++-+++<>- ++<>++-+-+-+ <>-+++
+><+++++++-++->>>>>><<>>[>+>++><---<+->< +-+-<-><]+-<+-<<<><<<><++<>><+++++<<<<><-+-+-+
<<<<<+++->>>>>>>>>+++><+++++<>+-+++>>>> >>[>+>+---+<>-++<<-]><<<<<<<++++-<-+>++++++
@AlephAlpha
AlephAlpha / Brainfuck
Last active December 25, 2015 14:39
Brainfuck interpreter in Mathematica.
ToExpression[
"input=StringToStream[\"" <> ##2 <>
"\"];Clear[memory];memory[_]=pointer=0;" <>
StringReplace[#,
{">" -> "pointer++;",
"<" -> "pointer--;",
"+" -> "memory[pointer]++;",
"-" -> "memory[pointer]--;",
"." -> "BinaryWrite[OutputStream[\"stdout\",1],memory[pointer]];",
"," -> "memory[pointer]=BinaryRead[input];",
@AlephAlpha
AlephAlpha / maze
Last active June 22, 2016 00:01
Maze generator in Mathematica.
MazeGraphics[m_, n_] :=
Block[{$RecursionLimit = Infinity,
unvisited = Tuples[Range /@ {m, n}], maze},
maze = Graphics[{Line[{{#, # - {0, 1}}, {#, # - {1, 0}}}] & /@
unvisited,
Line[{{0, n}, {0, 0}, {m, 0}}]}]; {unvisited =
DeleteCases[unvisited, #];
Do[If[MemberQ[unvisited, neighbor],
maze = DeleteCases[
maze, {#,
@AlephAlpha
AlephAlpha / snake
Last active May 21, 2020 16:10
Snake game in Mathematica.
Module[{a, s, d, f}, RemoveScheduledTask@ScheduledTasks[];
a[] := s =
If[#[[1]] == f,
f = RandomChoice[Complement[Tuples[Range /@ {34, 55}], #]]; #,
Most@#] &@PrependTo[s, s[[1]] + d]; s = {{17, 28}};
f = {18, 28}; d = {1, 0};
RunScheduledTask[
If[1 <= #[[1]] <= 34 && 1 <= #[[2]] <= 55 && FreeQ[Most@s, #] &[
s[[1]] + d], a[],
s = Position[
@AlephAlpha
AlephAlpha / Gomoku.nb
Last active April 29, 2022 10:34
Gomoku game in Mathematica.
DynamicModule[{board, winner, p, pmouse, ppossible, v, Reset},
Reset[] := {winner, board} = {"", ConstantArray[0, {20, 20}]};
Reset[]; Deploy@
Graphics[Button[{Brown, Rectangle[{0, 0}, {20, 20}], Black,
Line[Join @@
Table[{{{i, 0}, {i, 20}}, {{0, i}, {20, i}}}, {i, .5, 19.5}]],
Dynamic[pmouse =
Ceiling@MousePosition["Graphics", {-1, -1}] /. {0 -> 1,
21 -> 20};
If[1 <= Min@pmouse <= Max@pmouse <= 20 &&
@AlephAlpha
AlephAlpha / 2048.nb
Last active November 24, 2016 04:45
(*_*)
挪[左] = # //. {{x___, 1, a_ /; a > 1, y___} :> {x, a, 1, y},
{x___, a_ /; a > 1, a_, y___} :> {x, 2 抓住[a], 1, y}} /.
抓住[a_] :> a &;
挪[上] = Composition[Transpose, 挪[左], Transpose];
挪[下] = Composition[Reverse, 挪[上], Reverse];
挪[右] = Composition[Transpose, 挪[下], Transpose];
加块瓦 = ReplacePart[#, RandomChoice@Position[#, 1] -> 2] &;
@AlephAlpha
AlephAlpha / greek.dict.yaml
Last active December 5, 2022 08:19
Rime 的希腊字母输入方案,也支持一些常用的数学符号。如果需要在其他输入方案中直接输入希腊字母,请参考:https://gist.github.com/lotem/3705586
# Rime dictionary
# encoding: utf-8
---
name: greek
version: "0.1"
sort: original
...
# 小写希腊字母
@AlephAlpha
AlephAlpha / palladius.schema.yaml
Last active March 6, 2016 16:54
Rime 西里尔拼音输入方案
# Rime schema
# vim: set sw=2 sts=2 et:
# encoding: utf-8
schema:
schema_id: palladius
name: "西里尔拼音"
version: "0.0"
author:
- AlephAlpha <[email protected]>
@AlephAlpha
AlephAlpha / 10moliyf.md
Last active July 17, 2018 13:20
10 Mathematica One Liners to Impress Your Friends
@AlephAlpha
AlephAlpha / jcuken.schema.yaml
Created August 11, 2016 09:55
Rime 俄语 ЙЦУКЕН 键盘布局
# Rime schema
# vim: set sw=2 sts=2 et:
# encoding: utf-8
schema:
schema_id: jcuken
name: ЙЦУКЕН
version: "1.0"
author:
- AlephAlpha <[email protected]>