Update
This commit is contained in:
parent
2897818490
commit
f96124b085
3 changed files with 67 additions and 5 deletions
66
brainfuck.md
66
brainfuck.md
|
@ -8,7 +8,7 @@ The language is based on a 1964 language P´´ which was published in a mathemat
|
|||
|
||||
Brainfuck has seen tremendous success in the [esolang](esolang.md) community as the **lowest common denominator language**: just as mathematicians use [Turing machines](turing_machine.md) in proofs, esolang programmers use brainfuck in similar ways -- many esolangs just compile to brainfuck or use brainfuck in proofs of [Turing completeness](turing_complete.md) etc. This is thanks to brainfuck being an actual, implemented and working language reflecting real computers, not just a highly abstract mathematical model with many different variants. For example if one wants to encode a program as an integer number, we can simply take the binary representation of the program's brainfuck implementation.
|
||||
|
||||
In [LRS](lrs.md) program brainfuck may be seriously used as a super simple [scripting language](script.md).
|
||||
In [LRS](lrs.md) programs brainfuck may be seriously used as a super simple [scripting language](script.md).
|
||||
|
||||
## Specification
|
||||
|
||||
|
@ -23,10 +23,70 @@ A program consists of these possible commands:
|
|||
- `>`: move the data pointer to the right
|
||||
- `<`: move the data pointer to the left
|
||||
- `[`: jump after corresponding `]` if value under data pointer is zero
|
||||
- `]`: jump after corresponding `[` if value under data pointer is zero
|
||||
- `]`: jump after corresponding `[` if value under data pointer is not zero
|
||||
- `.`: output value under data pointer as an ASCII character
|
||||
- `,`: read value and store it to the cell under data pointer
|
||||
|
||||
## Variations
|
||||
## Implementation
|
||||
|
||||
This is a very simple [C](c.md) implementation of brainfuck:
|
||||
|
||||
```
|
||||
#include <stdio.h>
|
||||
|
||||
#define CELLS 30000
|
||||
|
||||
const char program[] = ",[.-]"; // your program here
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char tape[CELLS];
|
||||
unsigned int cell = 0;
|
||||
const char *i = program;
|
||||
int bDir, bCount;
|
||||
|
||||
while (*i != 0)
|
||||
{
|
||||
switch (*i)
|
||||
{
|
||||
case '>': cell++; break;
|
||||
case '<': cell--; break;
|
||||
case '+': tape[cell]++; break;
|
||||
case '-': tape[cell]--; break;
|
||||
case '.': putchar(tape[cell]); fflush(stdout); break;
|
||||
case ',': scanf("%c",tape + cell); break;
|
||||
case '[':
|
||||
case ']':
|
||||
if ((tape[cell] == 0) == (*i == ']'))
|
||||
break;
|
||||
|
||||
bDir = (*i == '[') ? 1 : -1;
|
||||
bCount = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (*i == '[')
|
||||
bCount += bDir;
|
||||
else if (*i == ']')
|
||||
bCount -= bDir;
|
||||
|
||||
if (bCount == 0)
|
||||
break;
|
||||
|
||||
i += bDir;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## Variants
|
||||
|
||||
TODO
|
|
@ -5,10 +5,10 @@ The word *computer* can be defined in many ways and can also take many different
|
|||
We can divide computers based on many attributes, e.g.:
|
||||
|
||||
- by **representation of data**: [digital](digital.md) vs [analog](analog.md)
|
||||
- by **[hardware](hw.md) technology**: [electronic](electronics.md), [mechanical](mechanical.md), biological etc.
|
||||
- by **[hardware](hw.md) technology**: [electronic](electronics.md), [mechanical](mechanical.md), [quantum](quantum.md), biological etc.
|
||||
- by **purpose**: special purpose vs general purpose, [personal](pc.md), [embedded](embedded.md), [supercomputers](supercomputer.md) etc.
|
||||
- by **[programmability](programming.md)**: non-programmable, partially or fully programmable
|
||||
- by **other criteria**: conventional vs [quantum computers](quantum.md) etc.
|
||||
- by **other criteria**: conventional vs [quantum computers](quantum.md), gaming computers etc.
|
||||
|
||||
Computers are studied by [computer science](compsci.md). The kind of computer we normally talk about consists of two main parts:
|
||||
|
||||
|
|
2
math.md
2
math.md
|
@ -8,6 +8,8 @@ Some see math not as a science but rather a discipline that develops formal tool
|
|||
|
||||
On the other hand, one does not have to be a math [PhD](phd.md) in order to be a good programmer in most fields. Sure, knowledge and overview of advanced mathematics is needed to excel, to be able to spot and sense elegant solutions, but beyond these essentials that anyone can learn with a bit of will it's really more about just not being afraid of math, accepting and embracing the fact that it permeates what we do and studying it when the study of a new topic is needed.
|
||||
|
||||
**The power of math is limited.** In 1932 [Kurt Godel](godel.md) mathematically proved, with his [incompleteness theorems](incompleteness.md), that (basically) there are completely logical truths which however math itself can never prove, and that math itself cannot prove its own consistency (which killed so called Hilbert's program which seeked to do exactly that). This is related to the limited power of [computers](computer.md) due to [undecidability](undecidability.md) (there are problems a computer can never decide).
|
||||
|
||||
## Overview
|
||||
|
||||
Following are some areas and topics which a programmer should be familiar with:
|
||||
|
|
Loading…
Reference in a new issue