Git Product home page Git Product logo

algol's Introduction

Algol

Algol é um projeto onde procuro estudar sobre algorítmos aplicando TDD e a linguagem de programação PHP.

Objetivo

Praticar a resolução de problemas utilizando TDD;

Enxergar melhor pontos como performance, clean code etc;

Ajudar ao próximo =)

Dos Exercícios

Os exercícios que serão resolvidos serão retirados de sites como codewars, exercism entre outros.

Vale a pena visitar sites deste gênero pois a maioria dos exercícios possuem uma resolução já postada e comentada por pessoas mais experientes.

algol's People

Contributors

morkhusz avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

algol's Issues

Diagonal Difference

Fonte: Hacker Rank Diagonal Difference
Given a square matrix of size N×N, calculate the absolute difference between the sums of its diagonals.
Input Format
The first line contains a single integer, N. The next N lines denote the matrix's rows, with each line
containing N space-separated integers describing the columns.
Output Format
Print the absolute difference between the two sums of the matrix's diagonals as a single integer.
Sample Input

3
11 2 4
4 5 6
10 8 -12

Sample Output
15
Explanation
The primary diagonal is:

11
      5
            -12

Sum across the primary diagonal: 11 + 5 - 12 = 4
The secondary diagonal is:

            4
      5
10

Sum across the secondary diagonal: 4 + 5 + 10 = 19
Difference: |4 - 19| = 15

Time Conversion

Fonte: HackerRank Time Conversion

Given a time in 12-hour AM/PM format, convert it to military (24-hour) time.

Note: Midnight is 12:00:00AM on a 12-hour clock, and 00:00:00 on a 24-hour clock. Noon is 12:00:00PM on a 12-hour clock, and 12:00:00 on a 24-hour clock.

Input Format

A string s contaning a time in 12-hour format (i.e hh:mm:ssAM or hh:mm:ssPM).

Sample Input
07:05:45PM

Sample Output
19:05:45

Min-Max Sum

Fonte: HackerRank Min-Max Sum

Given five positive integers, find the minimum and maximum values that can be calculated by summing exactly four of the five integers. Then print the respective minimum and maximum values as a single line of two space-separated long integers.

For example, arr = [1,3,5,7,9]. Our minimum sum is 1 + 3 + 5 + 7 = 16 and our maximum sum is 3 + 5 + 7 + 9 = 24.

We would print
16 24

Function Description

It should print two space-separated integers on one line: the minimum sum and the maximum sum of 4 of 5 elements.

miniMaxSum has the following parameter(s):

  • arr: an array of 5 integers

Input Format

A single line of five space-separated integers.

Output Format

Print two space-separated long integers denoting the respective minimum and maximum values that can be calculated by summing exactly four of the five integers. (The output can be greater than a 32 bit integer.)

Sample Input
1 2 3 4 5

Sample Output
10 14

Staircase

Fonte: HackerRank Staircase
Consider a staircase of size n = 4:

   #
  ##
 ###
####

Observe that its base and height are both equal to n, and the image is drawn using # symbols and spaces. The last line is not preceded by any spaces.

Write a program that prints a staircase of size n.

Function Description

It should print a staircase as described above.

staircase has the following parameter(s):

n: an integer

Input Format

A single integer, n, denoting the size of the staircase.

Constraints
0 < n <= 100

Output Format

Print a staircase of size n using # symbols and spaces.

Note: The last line must have 0 spaces in it.

Sample Input
6

Sample Output

     #
    ##
   ###
  ####
 #####
######

Explanation

The staircase is right-aligned, composed of # symbols and spaces, and has a height and width of n = 6.

Fizz Buzz

Write a short program that prints each number from 1 to 100 on a new line.

For each multiple of 3, print "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers which are multiples of both 3 and 5, print "FizzBuzz" instead of the number.

  • Inteiros múltiplos de 3 devem ser substituídos pela palavra Fizz
  • Inteiros múltiplos de 5 devem ser substituídos pela palavra Buzz
  • Inteiros múltiplos tanto de 3 quanto de 5 devem ser substituídos pela palavra FizzBuzz

Exemplo de output resolvido:

1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz

Plus Minus

Fonte: HackerRank Plus Minus
Given an array of integers, calculate the fractions of its elements that are positive, negative, and are zeros.

Print the decimal value of each fraction on a new line.

Note: This challenge introduces precision problems. The test cases are scaled to six decimal places, though answers with absolute error of up to are acceptable.

Output Format

You must print the following lines:

A decimal representing of the fraction of positive numbers in the array compared to its size.
A decimal representing of the fraction of negative numbers in the array compared to its size.
A decimal representing of the fraction of zeros in the array compared to its size.

Grading Students

Fonte: HackerRank Grading Students

HackerLand University has the following grading policy:

  • Every student receives a grade in the inclusive range from 0 to 100.
  • Any grade less than 40 is a failing grade.

Sam is a professor at the university and likes to round each student's grade according to these rules:

  • If the difference between the grade and the next multiple of 5 is less than 3, round up to the next multiple of 5.
  • If the value of grade is less than 38, no rounding occurs as the result will still be a failing grade.

For example, grade = 84 will be rounded to 85 but grade = 29 will not be rounded because the rounding would result in a number that is less than 40.

Function Description

The function should return an integer array consisting of rounded grades.

gradingStudents has the following parameter(s):

  • grades: an array of integers representing grades before rounding

Input Format

The first line contains a single integer, n, the number of students.
Each line i of the n subsequent lines contains a single integer, grades[i], denoting student 's grade.

Constraints

  • 1 <= n <= 60
  • 0 <= grades[i] <= 100

Output Format

For each grades[i], print the rounded grade on a new line.

Sample Input

4
73
67
38
33

Sample Output

75
67
40
33

Birthday Cake Candles

Fonte: HackerRank Birthday Cake Candles

You are in charge of the cake for your niece's birthday and have decided the cake will have one candle for each year of her total age. When she blows out the candles, she’ll only be able to blow out the tallest ones. Your task is to find out how many candles she can successfully blow out.

For example, if your niece is turning 4 years old, and the cake will have 4 candles of height 4, 4, 1, 3, she will be able to blow out 2 candles successfully, since the tallest candles are of height 4 and there are 2 such candles.

Input Format

The first line contains a single integer, n, denoting the number of candles on the cake.
The second line contains n space-separated integers, where each integer i describes the height of candle i.

Output Format

Return the number of candles that can be blown out on a new line.

Apple and Orange

Fonte: HackerRank Apple and Orange

Sam's house has an apple tree and an orange tree that yield an abundance of fruit. In the diagram below, the red region denotes his house, where s is the start point, and t is the endpoint. The apple tree is to the left of his house, and the orange tree is to its right. You can assume the trees are located on a single point, where the apple tree is at point a, and the orange tree is at point b.
image

When a fruit falls from its tree, it lands d units of distance from its tree of origin along the x-axis. A negative value of d means the fruit fell d units to the tree's left, and a positive value of d means it falls d units to the tree's right.

Given the value of d for m apples and n oranges, determine how many apples and oranges will fall on Sam's house (i.e., in the inclusive range [s, t])?

For example, Sam's house is between s = 7 and t = 10. The apple tree is located at a = 4 and the orange at b = 12. There are m = 3 apples and n = 3 oranges. Apples are thrown apples = [2, 3, -4] units distance from a, and
oranges = [3, -2, -4] units distance. Adding each apple distance to the position of the tree, they land at [2 + 4, 3 + 4, -4 + 4] = [6, 7, 0]. Oranges land at [3 + 12, -2 + 12, -4 + 12] = [15, 10, 8]. One apple and two oranges land in the inclusive range 7 - 10 so we print:

1
2

Function Description

The countApplesAndOranges function should print the number of apples and oranges that land on Sam's house, each on a separate line.

countApplesAndOranges has the following parameter(s):

  • s: integer, starting point of Sam's house location.
  • t: integer, ending location of Sam's house location.
  • a: integer, location of the Apple tree.
  • b: integer, location of the Orange tree.
  • apples: integer array, distances at which each apple falls from the tree.
  • oranges: integer array, distances at which each orange falls from the tree.

Input Format

The first line contains two space-separated integers denoting the respective values of s and t.
The second line contains two space-separated integers denoting the respective values of a and b.
The third line contains two space-separated integers denoting the respective values of m and n.
The fourth line contains m space-separated integers denoting the respective distances that each apple falls from point a.
The fifth line contains n space-separated integers denoting the respective distances that each orange falls from point b.

Constraints

  • consultar fonte (não dá pra inserir expoentes aqui)

Ouput Format

Print two integers on two different lines:

  • The first integer: the number of apples that fall on Sam's house.
  • The second integer: the number of oranges that fall on Sam's house.

Sample Input

7 11
5 15
3 2
-2 2 1
5 -6

Sample Output

1
1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.