Skip to content

Instantly share code, notes, and snippets.

View rhaseven7h's full-sized avatar
🙊

Gabriel Medina rhaseven7h

🙊
View GitHub Profile
@rhaseven7h
rhaseven7h / a_prefix_compression.hs
Created July 23, 2016 06:35
HackerRank.com - Functional Programming - Prefix Compression - Haskell
slv n "" _ = n
slv n _ "" = n
slv n a b
| fa == fb = slv (n + 1) (tail a) (tail b)
| otherwise = n
where fa = head a
fb = head b
main = do
raw <- readFile "input.txt"
@rhaseven7h
rhaseven7h / a_compute_the_area_of_a_polygon.hs
Created July 23, 2016 08:49
HackerRank.com - Functional Programming - Haskell - Compute The Area Of A Polygon
main = do
raw <- getContents -- readFile "input.txt"
let toInts a = map (\e -> read e :: Int) a
noded = map toInts $ map words $ tail $ lines raw
nodec = length noded
xdata = map head noded
ydata = map last noded
sum1x = xdata
sum1y = (tail ydata) ++ [head ydata]
sum2x = (tail xdata) ++ [head xdata]
@rhaseven7h
rhaseven7h / README.md
Created July 26, 2016 22:00
HackerRank.com - Functional Programming - Haskell - Captain Prime

Captain Prime

Captain Prime is going on a trip to Primeland and needs support of his troops to make this voyage successful. To prevent the wrath of evil spirits, he has to throw out some people from his troop into the sea. This decision will depend on the identification number of the troop member.

His ship is divided into three parts: Left, right, and central. Every person on the ship is assigned an identification number (referred as id), and according to their id they get to work in one part of the ship, or end up getting thrown out of the ship.


A person's fate depends on the following conditions:

@rhaseven7h
rhaseven7h / README.md
Last active July 28, 2016 00:47
HackerRank.com - Functional Programming - Haskell - Sequence Full Of Colors

Sequence Full Of Colors

You are given a sequence of N balls in 4 colors: red, green, yellow and blue. The sequence is full of colors if and only if all of the following conditions are true:

  • There are as many red balls as green balls.
  • There are as many yellow balls as blue balls.
  • Difference between the number of red balls and green balls in every prefix of the sequence is at most 1.
  • Difference between the number of yellow balls and blue balls in every prefix of the sequence is at most 1.

Your task is to write a program, which for a given sequence prints True if it is full of colors, otherwise it prints False.

@rhaseven7h
rhaseven7h / README.md
Created July 28, 2016 03:10
HackerRank.com - Functional Programming - Haskell - Filter Elements

Filter Elements

Given a list of N integers A = [a1, a2, ..., aN], you have to find those integers which are repeated at least K times. In case no such element exists you have to print -1.

If there are multiple elements in A which are repeated at least K times, then print these elements ordered by their first occurrence in the list.

Let's say A = [4, 5, 2, 5, 4, 3, 1, 3, 4] and K = 2. Then the output is

4 5 3
@rhaseven7h
rhaseven7h / README.md
Created July 28, 2016 06:15
HackerRank.com - Functional Programming - Haskell - Super Digit

Super Digit

We define super digit of an integer x using the following rules:

  • If x has only 1 digit, then its super digit is x.
  • Otherwise, the super digit of x is equal to the super digit of the digit-sum of x. Here, digit-sum of a number is defined as the sum of its digits.

For example, super digit of 9875 will be calculated as:

@rhaseven7h
rhaseven7h / PS1.sh
Created July 28, 2016 08:23
PS1 Setup with nvm and git branch
export PS1="┏ \[$(tput bold)\]\[$(tput setaf 2)\]\u\[$(tput setaf 7)\]\[$(tput bold)\]@\[$(tput setaf 6)\]\H \[$(tput setaf 3)\][\w]\[$(tput sgr0)\]\n┃ \[$(tput bold)\]\[$(tput setaf 7)\]\d :: \t :: nvm=\$(nvm current) :: branch=\$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo not-a-git-repo) :: Cmd #\!\[$(tput sgr0)\] \n┗ \[$(tput bold)\]\[$(tput setaf 3)\]\\$ \[$(tput sgr0)\]\[$(tput sgr0)\]"
@rhaseven7h
rhaseven7h / README.md
Created July 29, 2016 01:03
HackerRank.com - Functional Programming - Haskell - Concave Polygon

Concave Polygon

You are given the cartesian coordinates of a set of points in a 2D plane (in no particular order). Each of these points is a corner point of some Polygon, P, which is not self-intersecting in nature. Can you determine whether or not is a concave polygon?

Input Format

The first line contains an integer, N, denoting the number of points. The N subsequent lines each contain 2 space-separated integers denoting the respective x and y coordinates of a point.

Constraints

@rhaseven7h
rhaseven7h / README.md
Created July 29, 2016 01:20
HackerRank.com - Functional Programming - Haskell - String Compression

String Compression

Joseph and Jane are making a contest for apes. During the process, they have to communicate frequently with each other. Since they are not completely human, they cannot speak properly. They have to transfer messages using postcards of small sizes. To save space on the small postcards, they devise a string compression algorithm:

  • If a character, ch, occurs n (>1) times in a row, then it will be represented by {ch}{n}, where {n} is the value of n. For example, if the substring is a sequence of 'a' ("aaaa"), it will be represented as "a4".
  • If a character, ch, occurs exactly one time in a row, then it will be simply represented as {ch}. For example, if the substring is "a", then it will be represented as "a".

Help Joseph to compress a message, msg.

@rhaseven7h
rhaseven7h / main.go
Created May 24, 2017 18:38
Crop and Resize a Directory with Images with Golang (Go)
package main
import (
"fmt"
"log"
"path/filepath"
"github.com/disintegration/imaging"
)