First Upload
This commit is contained in:
93
6/ex2.c
Normal file
93
6/ex2.c
Normal file
@@ -0,0 +1,93 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#define N 30
|
||||
#define CUBE 6
|
||||
#define INDEX_PlAYER 24
|
||||
#define ZERO 0
|
||||
#define ONE 1
|
||||
#define TWO 2
|
||||
#define ABS(x) (x) * (((2 * (x)) + 1) % 2)
|
||||
#define BOOLEAN unsigned short
|
||||
|
||||
//---------------------------------------------------------------------------------------
|
||||
// NumBBiggerThenNumA
|
||||
// ------------------
|
||||
//
|
||||
// General : Checks if the second number (B) is greater than the first number (A).
|
||||
//
|
||||
// Parameters :
|
||||
// number1 - first number (int)
|
||||
// number2 - second number (int)
|
||||
//
|
||||
// Return value : If the second number (B) is greater than the first number (A) (BOOLEAN).
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Programmer : Cohen Idan
|
||||
// Student No : None
|
||||
// Date : 21.10.2019
|
||||
//---------------------------------------------------------------------------------------
|
||||
BOOLEAN NumBBiggerThenNumA(int a, int b)
|
||||
{
|
||||
int sub = a - b + ONE;
|
||||
BOOLEAN answer = (ONE / (ABS(sub) + (sub) + ONE));
|
||||
return answer;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------
|
||||
// ChangeBool
|
||||
// ----------
|
||||
//
|
||||
// General : Boolean variable inverse.
|
||||
//
|
||||
// Parameters :
|
||||
// bool1 - Boolean variable (BOOLEAN)
|
||||
//
|
||||
// Return value : Boolean variable (BOOLEAN).
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Programmer : Cohen Idan
|
||||
// Student No : None
|
||||
// Date : 21.10.2019
|
||||
//---------------------------------------------------------------------------------------
|
||||
BOOLEAN ChangeBool(BOOLEAN bool1)
|
||||
{
|
||||
BOOLEAN answer = ++bool1 % TWO;
|
||||
return answer;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Exercise 2
|
||||
// ----------
|
||||
//
|
||||
// General : The program checks the amount of cube flips for which the player
|
||||
// can advance his tool forward.
|
||||
//
|
||||
// Input : None.
|
||||
//
|
||||
// Process : The program counts the number of zeros on the board to position 6
|
||||
// after the player's position on the board.
|
||||
//
|
||||
// Output : The amount of cube throws for which the player can advance
|
||||
// his tool (unsigned short).
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Programmer : Cohen Idan
|
||||
// Student No : 211675038
|
||||
// Date : 23.10.2019
|
||||
//---------------------------------------------------------------------------------------
|
||||
void main(void)
|
||||
{
|
||||
unsigned short board[N] =
|
||||
{0,1,0,1,0,1,0,0,1,1,1,0,0,0,1,1,0,1,0,1,0,0,0,0,0,1,1,1,1,0};
|
||||
|
||||
unsigned short sum = ZERO,
|
||||
counter = INDEX_PlAYER,
|
||||
last_step = counter + CUBE;
|
||||
|
||||
for (++counter; NumBBiggerThenNumA(counter, last_step); counter++)
|
||||
{
|
||||
sum += ChangeBool(board[counter]);
|
||||
}
|
||||
|
||||
printf("Sum: %hu\n", sum);
|
||||
}
|
||||
Reference in New Issue
Block a user