This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=begin | |
Run length encodingRun-length encoding (RLE) is a simple form of data compression, where runs (consecutive data elements) are replaced by just one data value and count. | |
For example we can represent the original 53 characters with only 13. | |
"WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB" -> "12WB12W3B24WB" | |
RLE allows the original data to be perfectly reconstructed from the compressed data, which makes it a lossless data compression."AABCCCDEEEE" -> "2AB3CD4E" -> "AABCCCDEEEE" | |
For simplicity, you can assume that the unencoded string will only contain the letters A through Z (either lower or upper case) and whitespace. | |
This way data to be encoded will never contain any numbers and numbers inside data to be decoded always represent the count for the following character. | |
=end | |
# Usage example |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=begin | |
Luhn check | |
The Luhn check is a simple checksum, famously used to check credit card numbers are at least possibly valid. | |
Take this number: | |
4539 3195 0343 6467 | |
The first thing we do is, starting on the right, double every second number and, if that number is greater than 9, subtract 9 from it: | |
4539319503436467 | |
^ ^ ^ ^ ^ ^ ^ ^ | |
8569 6195 0383 3437 | |
The next step is to add all the digits: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=begin | |
Atbash cipher | |
The Atbash cipher is a type of ancient encryption created to encode messages in Hebrew. | |
At its heart is a very simple substitution cipher that transposes all the letters in the alphabet backwards. The first letter in the alphabet is replaced by the the last letter so A -> Z, B -> Y etc. | |
Plain: abcdefghijklmnopqrstuvwxyz | |
Cipher: zyxwvutsrqponmlkjihgfedcba | |
It is obviously a very weak encryption mechanism! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string1 = 'GAGCCTACTAACGGGAT'.chars | |
string2 = 'CATCGTAATGACGGCCT'.chars | |
diff = 0 | |
string1.each_with_index do |character, index| | |
if character != string2[index] | |
diff +=1 | |
end | |
end | |
puts diff |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resistor_colours = ['black', 'brown', 'red', 'orange', 'yellow', 'green', 'blue', 'violet', 'grey', 'white'] | |
input_array = gets.chomp.gsub(' ', '').split('-') | |
puts resistor_colours.find_index(input_array[0]).to_s + resistor_colours.find_index(input_array[1]).to_s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input = gets | |
.chomp | |
.upcase | |
.gsub(/[^A-Z]/i, '') | |
.chars | |
puts "isogram" if input == input.uniq |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scores = { | |
/[AEIOULNRST]/ => 1, | |
/[DG]/ => 2, | |
/[BCMP]/ => 3, | |
/[FHVWY]/ => 4, | |
/[K]/ => 5, | |
/[JX]/ => 8, | |
/[QZ]/ => 10 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Feature: I look through emails | |
Scenario: I look through emails | |
Given I check the email has been recieved | |
And I search for an email with a "subject" of "Notification of application" | |
Then I delete all emails from my inbox | |
And I check the email has been recieved |
NewerOlder