Skip to content

Instantly share code, notes, and snippets.

@dlupaescu
Last active August 29, 2015 14:28
Show Gist options
  • Save dlupaescu/d00efa8b65afc72e4e48 to your computer and use it in GitHub Desktop.
Save dlupaescu/d00efa8b65afc72e4e48 to your computer and use it in GitHub Desktop.
Subjects
/*
Exercitiu : brainfuck
Fisiere de iesire : *.c, *.h
Functii autorizate : write, malloc, free
--------------------------------------------------------------------------------
Scrieti un interpretor de programe numit Brainfuck.
Codul sursa va fi dat ca primul argument.
Codul va fi mereu valid, cu cel mult 4096 operatii.
Barinfuck este un limbaj minimal. Contine un vector de bytes
(pentru acest exercitiu, 2048 bytes) initializati cu zero, si
un pointer spre primul byte.
Fiecare operator consista dintr-un singur caracter:
- '>' incrementeaza pointerul ;
- '<' decrementeaza pointerul ;
- '+' incrementeaza byte-ul la care pointeaza ;
- '-' decrementeaza byte-ul la care pointeaza ;
- '.' printeaza la iesirea standard byte-ul spre care pointeaza ;
- '[' du-te la perechea ']' byte-ul la care pointeaza e 0 (while start) ;
- ']' du-te la perechea '[' byte-ul la care pointeaza nu e 0 (while end).
Orice alt caracter este un comentariu.
Examples:
$>./brainfuck "++++++++++[>+++++++>++++++++++>+++>+<<<<-]
>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>." | cat -e
Hello World!$
$>./brainfuck "+++++[>++++[>++++H>+++++i<<-]>>>++\n<<<<-]>>--------.>+++++.>." | cat -e
Hi$
$>./brainfuck | cat -e
$
*/
/*
Assignment name : brainfuck
Expected files : *.c, *.h
Allowed functions: write, malloc, free
--------------------------------------------------------------------------------
Write a Brainfuck interpreter program.
The source code will be given as first parameter.
The code will always be valid, with no more than 4096 operations.
Brainfuck is a minimalist language. It consists of an array of bytes
(in our case, let's say 2048 bytes) initialized to zero,
and a pointer to its first byte.
Every operator consists of a single character :
- '>' increment the pointer ;
- '<' decrement the pointer ;
- '+' increment the pointed byte ;
- '-' decrement the pointed byte ;
- '.' print the pointed byte on standard output ;
- '[' go to the matching ']' if the pointed byte is 0 (while start) ;
- ']' go to the matching '[' if the pointed byte is not 0 (while end).
Any other character is a comment.
Examples:
$>./brainfuck "++++++++++[>+++++++>++++++++++>+++>+<<<<-]
>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>." | cat -e
Hello World!$
$>./brainfuck "+++++[>++++[>++++H>+++++i<<-]>>>++\n<<<<-]>>--------.>+++++.>." | cat -e
Hi$
$>./brainfuck | cat -e
$
*/
/*
Assignment name : ft_itoa_base
Expected files : ft_itoa_base.c
Allowed functions: malloc
--------------------------------------------------------------------------------
Write a function that converts an integer value to a null-terminated string
using the specified base and stores the result in a char array that you must
allocate.
The base is expressed as an integer, from 2 to 16. The characters comprising
the base are the digits from 0 to 9, followed by uppercase letter from A to F.
For example, base 4 would be "0123" and base 16 "0123456789ABCDEF".
If base is 10 and value is negative, the resulting string is preceded with a
minus sign (-). With any other base, value is always considered unsigned.
Your function must be declared as follows:
char *ft_itoa_base(int value, int base);
*/
/*
Assignment name : print_memory
Expected files : print_memory.c
Allowed functions: write
--------------------------------------------------------------------------------
Scrieti o functie care primeste (const void *addr, size_t size), si afiseaza memoria precum in exemplu.
Functia trebuie declarata ca si mai jos:
void print_memory(const void *addr, size_t size);
---------
$> cat main.c
void print_memory(const void *addr, size_t size);
int main(void)
{
int tab[10] = {0, 23, 150, 255,
12, 16, 21, 42};
print_memory(tab, sizeof(tab));
return (0);
}
$> gcc -Wall -Wall -Werror main.c print_memory.c && ./a.out | cat -e
0000 0000 1700 0000 9600 0000 ff00 0000 ................$
0c00 0000 1000 0000 1500 0000 2a00 0000 ............*...$
0000 0000 0000 0000 ........$
*/
/*
Assignment name : print_memory
Expected files : print_memory.c
Allowed functions: write
--------------------------------------------------------------------------------
Write a function that takes (const void *addr, size_t size), and displays the
memory as in the example.
Your function must be declared as follows:
void print_memory(const void *addr, size_t size);
---------
$> cat main.c
void print_memory(const void *addr, size_t size);
int main(void)
{
int tab[10] = {0, 23, 150, 255,
12, 16, 21, 42};
print_memory(tab, sizeof(tab));
return (0);
}
$> gcc -Wall -Wall -Werror main.c print_memory.c && ./a.out | cat -e
0000 0000 1700 0000 9600 0000 ff00 0000 ................$
0c00 0000 1000 0000 1500 0000 2a00 0000 ............*...$
0000 0000 0000 0000 ........$
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment