Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .gitignore
Empty file.
13 changes: 13 additions & 0 deletions task1-simple-program/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Simple c program with commits
The main idea of of this task is to demonstrate your ability to work with git and create correctly formed commit.
So, you have to focus on the rules and principals of working with github, not on code complexity.
## Task
1. Please, write simple game "guess a number". User input some number from 0 to 9. Computer also generates random number from 0 to 9. If values are equal, user will get message “You win”. In other case – “You loose”. main() function should return 0 if you win, and non-zero value otherwise.
2. When you working on code, please divide it on several steps. Each steps will be new commit. There are possible steps:
a. Create simple *.c file with empty main() function
b. Write main functionality
c. Rewrite code, that random number generates in you own defined function.
3. Check coding style with checkpatch.pl
4. Also don't forget to create .gitignore file
5. Create pull request to this repo into you own branch (have to be already exist)
6. Good luck
29 changes: 29 additions & 0 deletions task1-simple-program/guess_game.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: GPL-2.0+
#include <stdio.h>
#include <stdlib.h>
int get_random_numeric(int user_choice)
{
srand(user_choice);
return rand()%10;
}

int main(void)
{
int user_choice;

printf("User guess [0-9]:");
user_choice = getchar() - '0';
if (user_choice < 0 || user_choice > 9) {
puts("Bad input");
return -1;
}

if (user_choice == get_random_numeric(user_choice)) {
puts("You win");
return 0;
}
puts("You loose");
return 1;
}


9 changes: 9 additions & 0 deletions task2-bash/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Part 2. Bash
The main idea of this task is to increase you level of bash-scripting.

## Task
1. Please write a bash script that is copping all source code of your project form part1 to /tmp/guesanumber. Compress this folder to gzip archive (please google tar command) with same name. Copy gzip archive to “release” subdirectory in project dir. Please, don't forget to divide script on commits.
2. Please write another script, which run program "guess a number" from task1 in infinity loop, and each iteration ask user to press "y" to continue, "n" to exit, or number to set number of runs of tries without asking "y or n". Script counting users success cases and printing it numbers. Also after each success script says "Good job", otherwise "Wish a good luck next time". Please, don't forget to divide script on commits.
3. Make a pull request.
4. If you want, you may use colors to increase readability of script output.
5. Good luck
51 changes: 51 additions & 0 deletions task2-bash/backup_guess_game.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

echo Backup source code

BACKUPDIR="/tmp/guesanumber"
SOURCEDIR="../task1-simple-program"
RELEASEDIR=$PWD/release

echo Backup on $BACKUPDIR

echo "=========="

if [[ -d "$BACKUPDIR" ]]; then
echo "Directory $BACKUPDIR exists."
echo "Clean $BACKUPDIR"
rm -rf $BACKUPDIR/*
else
echo "Directory $BACKUPDIR does not exists."
echo "Create $BACKUPDIR"
mkdir $BACKUPDIR
fi

echo "=========="

echo "Copy project files to $BACKUPDIR"
cp $SOURCEDIR/* $BACKUPDIR/
echo "List of files:"
ls -ld $BACKUPDIR/*

echo "=========="

if [[ -d "$RELEASEDIR" ]]; then
echo "Directory $RELEASEDIR exists."
echo "Clean $RELEASEDIR"
rm -rf $RELEASEDIR/*
else
echo "Directory $RELEASEDIR does not exists."
echo "Create $RELEASEDIR"
mkdir $RELEASEDIR
fi

echo "=========="

echo "GZIP files"
cd $BACKUPDIR
tar -czvf $RELEASEDIR/guess_game.tar.gz *
cd $OLDPWD

echo "=========="

echo "DONE"
65 changes: 65 additions & 0 deletions task2-bash/loop_guess_game.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/bash
# TASK 02: LOOP GUESS GAME

guess_game() {
USER=""
while [[ ! $USER =~ ^[0-9] ]]; do
read -p "Guess a number [0-9] : " -n 1 USER
echo
done

PC=$(($RANDOM % 10))
echo "User choice -" $USER
echo " PC choice -" $PC

if [[ "$USER" == "$PC" ]]; then
echo "You win"
return 0
fi
echo "You loose"
return 1
}

echo "Loop Guess Game"

USER_INPUT=""
NUM_GAMES=""

while true; do

read -p "Are you want play game [y/n/Num games] : " USER_INPUT
echo "Your input is - << $USER_INPUT >>"

NUM_GAMES=0

if ! [[ $USER_INPUT =~ ^[0-9]+$ ]]; then
case $USER_INPUT in
[nN])
break
;;
[yY])
echo "Lets try to play game"
NUM_GAMES=1
;;
*)
echo "Wrong input, try again"
;;
esac
else
echo "You want play $USER_INPUT games?"
NUM_GAMES=$USER_INPUT
fi

for ((gm = 1; gm <= $NUM_GAMES; gm++)); do
echo "Game $gm of $NUM_GAMES start"
guess_game
if [[ $? == "0" ]]; then
echo "Good job"
else
echo "Wish a good luck next time"
fi
done

done

echo "Bye-bye"
Binary file added task2-bash/release/guess_game.tar.gz
Binary file not shown.
15 changes: 15 additions & 0 deletions task3-make/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

# Part 3. Make
The main idea of this task in improve your skills in writing Makefiles.

## Task

1. Please, divide your source code form Task1 into two source file. First one should contains the main() function. Other one contains all other code. Write a Makefile for your project.
2. Implement options to build your project with gcc or clang
3. Implement options to link second files in regular way, static library (.a) or dynamic library (.so).
4. Implement option to check all project code using checkpatch.pl or cppcheck
5. Implement option to include debug information.
6. Implement option to print all warning during compilation.
7. Implement "clean" options.
8. Submit this Makefile with all code to github as pull request. Don't forget commit each step.
9. Good luck