diff --git a/01_git/scissors/Makefile b/01_git/scissors/Makefile new file mode 100755 index 0000000..d602acc --- /dev/null +++ b/01_git/scissors/Makefile @@ -0,0 +1,14 @@ +# Makefile for Rock-Paper-Scissors game +# Author: ViacheslavHolubnychyi + +C=gcc +OBJS=RockPaperScissors.o + +program: ${OBJS} + ${C} -o program ${OBJS} + +RockPaperScissors.o: RockPaperScissors.c + ${C} -c RockPaperScissors.c + +clean: + rm *.o program diff --git a/01_git/scissors/RockPaperScissors.c b/01_git/scissors/RockPaperScissors.c new file mode 100644 index 0000000..773e75e --- /dev/null +++ b/01_git/scissors/RockPaperScissors.c @@ -0,0 +1,118 @@ +#include +#include +#include +#include + +uint32_t randomize(uint32_t range_min, uint32_t range_max) +{ + uint32_t* ptr1 = (uint32_t*)malloc(4); + uint32_t* ptr2 = (uint32_t*)malloc(4); + uint32_t pos_seed = (uint32_t) ptr1; + uint32_t src_seed = (uint32_t) ptr2; + free(ptr1); + free(ptr2); + uint8_t rshifts_num = pos_seed % (sizeof(src_seed)*8); + uint32_t random_num = (src_seed >> rshifts_num) % (range_max+1 - range_min) + range_min; + return random_num; +} + +uint8_t get_rps_id(char rps_symbol) +{ + switch(rps_symbol) + { + case 'r': + return 0; // rock + case 'p': + return 1; // paper + case 's': + return 2; // scissors + default: + return -1; // error-code + } +} + +char get_rps_symbol(uint8_t rps_id) +{ + switch(rps_id) + { + case 0: + return 'r'; // rock + case 1: + return 'p'; // paper + case 2: + return 's'; // scissors + default: + return 'E'; // error-code + } +} + +char* get_rps_string(uint8_t rps_id) +{ + switch(rps_id) + { + case 0: + return "rock"; // rock + case 1: + return "paper"; // paper + case 2: + return "scissors"; // scissors + default: + return "ERROR"; // error-code + } +} + +bool rps_does_first_win(uint8_t first, uint8_t second) +{ + if (first == 0 && second == 2) + { + return true; + } + else if (first == 2 && second == 0) + { + return false; + } + else + { + if (first >= second) + { + return true; + } + else if ((first == 0) && (second == 2)) // if (first = 'r' && second == 's') + { + return true; + } + else + { + return false; + } + } +} + +int main() +{ + uint8_t random_rps = (uint8_t) randomize(0, 2); + + printf("Welcome to the Rock-Paper-Scissors game.\n"); + printf("Choose:\n r - rock,\n p - paper,\n s - scissors.\n"); + printf("Your option: "); + char symbol = 0; + scanf("%c", &symbol); + uint8_t user_rps = get_rps_id(symbol); + + bool does_user_win = rps_does_first_win(user_rps, random_rps); + printf("My option was: %c.\n", get_rps_symbol(random_rps)); + if (does_user_win) + { + printf("You win: %s beats %s\n", get_rps_string(user_rps), get_rps_string(random_rps)); + } + else + { + printf("I win: %s beats %s\n", get_rps_string(random_rps), get_rps_string(user_rps)); + } + + printf("Try again!"); + + printf("\n\n"); + return 0; +} + diff --git a/02_bash/hwdetect/hwdetect.sh b/02_bash/hwdetect/hwdetect.sh new file mode 100755 index 0000000..b3b8e2e --- /dev/null +++ b/02_bash/hwdetect/hwdetect.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +#colors +YEL='\033[1;33m' +NC='\033[0m' # No Color + +echo -e "${YEL}This computer name: ${NC}" +hostname +echo "" + +echo -e "${YEL}Current directory: ${NC}" +pwd +echo "" + +echo -e "${YEL}Mounted devices: ${NC}" +mount | grep /dev/sd +echo "" + +echo -e "${YEL}USB devices: ${NC}" +lsusb +echo "" + +echo -e "${YEL}Block devices: ${NC}" +lsblk +echo "" +echo -e "${YEL}SCSI devices: ${NC}" +lsblk -S +echo "" + +echo -e "${YEL}Bus devices:${NC}" +sudo lshw -businfo +echo "" + +echo -e "${YEL}PCI devices: ${NC}" +lspci +echo "" + +echo -e "${YEL}I2C devices: ${NC}" + +#part1 +sudo lshw | grep -w "\-pci\|pci" + +#part2 +i2c_num=$(sudo i2cdetect -l | wc -l) # i2c_num = count number of lines in i2c busses list +((max_index= ${i2c_num} - 1)) # max_index = i2c_num - 1; + +echo " - number of i2c busses: $i2c_num" +for i in $(seq 0 ${max_index}) +do + echo " - bus $i:" + sudo i2cdetect -y ${i} + echo "" +done