User Tools

Site Tools


competitive_programming:linux

This is an old revision of the document!


Linux Development

The Unix philosophy prizes modularity and reusability, and heavily favors small tools that solve a given problem. A basic mastery of Unix tools and workflows can go a long way for user's who are proficient in a Unix environment.

This section assumes a basic working knowledge of Unix development including the use of an command-line editor (e.g., Emacs, Vim), basic Unix commands and utilities (e.g., ls, cd, man), and development toolchains (g++, Python3, Make).

Python3 Extras

Interactive Interpreter

The Python3 interactive interpreter (typically invoked with python3 on the command line) allows for the entry of arbitrary Python3 commands, making it a great calculator and a great place to test simple ideas.

Interactive Interpreter: Loops

>>> from math import *
>>> for i in range(10):
...  print(int(log(2**i, 10))+1, end=' ') # single space before the print() to simulate indentation
...                                       # additional lines in the loop here or <return> to end
1 1 1 1 2 2 2 3 3 3 >>>

The above fragment computes powers of two, and then uses the decimal logarithm to compute the number of digits in each power.

This can be extended to basic nested structures.

>>> for i in range(3):
...  for j in range(3):             # preceded by a single space
...   print(i, j, sep=',', end=" ") # preceded by two spaces
...                                 # single <return> keystroke
0,0 0,1 0,2 1,0 1,1 1,2 2,0 2,1 2,2 >>>

If you are looking to do anything more complicated, it is likely that you should create a temporary '.py' file.

Interactive Interpreter: Importing Files

The import statement can be used to import arbitrary Python3 files, which can be useful for quick unit tests (and doesn't require further file manipulation to drive tests).

Consider the Python code:

test.py
 

-c Command Flag

While only occasionally convenient, limited Python3 code can also be entered directly on the command line with the command (-c) flag.

$ python3 -c "print('Hello') ; print('World!')"
Hello
World!

Pipes and Redirects

Pipes | and redirects > are common tools for creating basic workflows by manipulating input and output of programs and files or streams. Like many

In order to illustrate the use of pipes and redirects, consider the following

Command Line Utilities

time
wc
man

Bash Scripts

Additional Resources

Devices

/dev/null
/dev/random
/tmp/
competitive_programming/linux.1534194974.txt.gz · Last modified: 2018/08/13 16:16 by jguerin