Skip to content

Instantly share code, notes, and snippets.

View youssef3wi's full-sized avatar

Aouichaoui Youssef youssef3wi

  • Kairouan, Tunisie
View GitHub Profile
@youssef3wi
youssef3wi / BoxesCodinGame.java
Created January 21, 2024 17:01
A storage room full of boxes.
import java.util.Scanner;
/**
* You are in a storage room full of boxes. We want to make some room by moving the empty boxes to the end of the room and not moving the other side.
* Given an integer array containing the weights of the boxes, write a function to moves all the empty boxes to the end of the room.
* <p/>
* <b>INPUT: </b>
* <b>Line1: The N weights</b>
* <p/>
* <b>OUTPUT:</b>
@youssef3wi
youssef3wi / TicTacToe.java
Created January 29, 2024 17:17
Tic-tac-toe or noughts and crosses is a childhood game where players take turns playing X's and O's on a 3x3 board.
import java.util.Scanner;
/**
* Tic-tac-toe or noughts and crosses is a childhood game where players take turns playing X's and O's
* on a 3x3 board trying to get three in a row. Here's an example game where O is victorious:
* <p>
* Write a function that takes an NxN game board as input and returns true or false depending on whether it's a valid board.
* The valid states for squares of the board are "X", "O", and "~" (no one has played there yet).<br>
* Examples of valid boards:
* <ol style="margin-top: 0">
/**
* Pour éviter la confusion entre les multiples de 1000 octets et les multiples de
* 1024 octets, les terms "kibioctet", "mébioctet", etc. ont été inventés.
* <ul>
* <li>Un kibioctet (abrégé KiB) correspond à 1024 octets.</li>
* <li>Un mébioctet (MiB) correspond à (1024*1024 = 1048576) octets</li>
* </ul>
* <p>
* Étant donné une quantité d'octets :
* <ul>
/**
* Alors que vous vous promeniez dans les rayons d'une librarie peu recommandable,
* vous trouvez par hasard un carnet de notes écrit par le célèbre savant fou Hubert Zweistein.
* Vous aimeriez connaître son contenu, mais il est écrit en étrange langage codé.
* <p>
* Assez rapidement, vous faites une découverte : les lignes sont groupées 3 par 3,
* et chaque groupe contient le même nombre de lettres. En alternant les lettres
* des différents lignes, un message apparaît !
* <p>
* À partir de trois lignes du livre, alternez les lettres :
@youssef3wi
youssef3wi / DaughterAddition.java
Created February 8, 2024 22:35
My daughter is currently learning addition at school. She sometimes gets things wrong when summing up two digits.
/**
* My daughter is currently learning addition at school. She sometimes gets things
* wrong when summing up two digits.
* <p>
* Given the two initial numbers and her calculated result, you have to check if is
* correct.
* <ul>
* <li>If yes, output the string "ok"</li>
* <li>If no, return the digit index on where she got it wrong (converted to a string).
* Unit digit has the index "0", tens digit has the index "1", etc.</li>
@youssef3wi
youssef3wi / GeneCombinations.adoc
Created February 10, 2024 11:48
You have to list all the gene combinations of two parents, from their blood type and the blood type of one of their children.

Goal

You have to list all the gene combinations of two parents, from their blood type and the blood type of one of their children.

Description

Each person has two blood genes, each of them can be A, B or O.

You do not directly know which person has which genes, but you know their phenotypes (the apparent expression of the genes). The phenotype can be: A, B, AB or O.

@youssef3wi
youssef3wi / MeasureOutcome.java
Created March 30, 2024 16:43
We like to measure the outcome of our activities and the similarities between different projects.
import java.util.Scanner;
import static java.lang.Integer.toBinaryString;
/**
* We like to measure the outcome of our activities and the similarities between
* different projects.
* <p>
* The measure of the similarity between two projects is the number of positions (in their
* binary representation) at which the corresponding bits of their identifiers are different.
@youssef3wi
youssef3wi / ComputeCheckDigit.java
Created May 13, 2024 09:10
Afin de détecter des erreurs dans des identifiants numériques, une clé de contrôle est souvant ajoutée à cet identifiant.
/**
* Afin de détecter des erreurs dans des identifiants numériques, une clé de contrôle est souvant ajoutée à cet identifiant.
* <p>
* Implémentez la méthode {@code computeCheckDigit(identifiantNumber)} qui prend en entrée un identifiant
* (sous la forme d'une chaîne de caractères) et qui retourne la clé de contrôle en utilisant l'algorithme qui suit :
* <ul>
* <li>Faites la somme des chiffres situées à des positions paires (positions 0, 2, 4, etc.).</li>
* <li>Multipliez le résultat par tois.</li>
* <li>Ajoutez à ce nombre la somme des chiffres situés à des positions impaires (positions 1, 3, 5, etc.).</li>
* <li>Prenez le dernier chiffre de ce résultat.</li>
@youssef3wi
youssef3wi / StudentChecker.java
Last active October 12, 2024 10:58
You are tasked with validating student records from an array RecArray, where each element is in the format <name>:<roll_no>:<marks>.
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* <b>Unique Array</b>
* <p>
@youssef3wi
youssef3wi / SmallestInterval.java
Created October 12, 2024 10:58
Implémentez la méthode smallestInterval(numbers) qui retourne le plus petit intervalle positif entre deux éléments du tableau numbers.
import java.security.SecureRandom;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import static java.lang.System.nanoTime;
import static java.util.Arrays.asList;