diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..e69de29b diff --git a/task1-simple-program/README.md b/task1-simple-program/README.md new file mode 100644 index 00000000..8b0a402e --- /dev/null +++ b/task1-simple-program/README.md @@ -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 \ No newline at end of file diff --git a/task1-simple-program/guess_game.c b/task1-simple-program/guess_game.c new file mode 100644 index 00000000..d12c2636 --- /dev/null +++ b/task1-simple-program/guess_game.c @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0+ +#include +#include +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; +} + + diff --git a/task2-bash/README.md b/task2-bash/README.md new file mode 100644 index 00000000..265aa56e --- /dev/null +++ b/task2-bash/README.md @@ -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 diff --git a/task2-bash/backup_guess_game.sh b/task2-bash/backup_guess_game.sh new file mode 100755 index 00000000..01b899e4 --- /dev/null +++ b/task2-bash/backup_guess_game.sh @@ -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" diff --git a/task2-bash/loop_guess_game.sh b/task2-bash/loop_guess_game.sh new file mode 100755 index 00000000..f1bce9ea --- /dev/null +++ b/task2-bash/loop_guess_game.sh @@ -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" diff --git a/task2-bash/release/guess_game.tar.gz b/task2-bash/release/guess_game.tar.gz new file mode 100644 index 00000000..c5ab2ae3 Binary files /dev/null and b/task2-bash/release/guess_game.tar.gz differ diff --git a/task3-make/README.md b/task3-make/README.md new file mode 100644 index 00000000..1b43522c --- /dev/null +++ b/task3-make/README.md @@ -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