<file_sep>def day_trader(day_prices)
    benefit_h = {}

    day_prices.combination(2) { |c| benefit_h[ c[1] - c[0] ] = c }

    buy_day = day_prices.index(benefit_h.max.flatten[1]) + 1
    sell_day = day_prices.index(benefit_h.max.flatten[2]) + 1

    "<NAME>! Vous avez intéret à acheter le jour #{buy_day} et à vendre le jour #{sell_day}!"
end<file_sep>def cipher_one_letter(letter, key)
    
    univ_key = key.remainder(26)

    if letter =~ /[A-Z]/
        (letter.ord + univ_key) > 90 ? (letter.ord + univ_key - 26).chr : 
        (letter.ord + univ_key) < 65 ? (letter.ord + univ_key + 26).chr : (letter.ord + univ_key).chr
    elsif letter =~/[a-z]/
        (letter.ord + univ_key) > 122 ? (letter.ord + univ_key - 26).chr : 
        (letter.ord + univ_key) < 97 ? (letter.ord + univ_key + 26).chr : (letter.ord + univ_key).chr
    elsif letter.class != String
        "Please give me a string!"
    else
        letter
    end
end

def ceasar_cipher(string, key)
    string.split("").map { |character| cipher_one_letter(character, key) }.join("")
end<file_sep>require_relative '../lib/ceasar_cipher'

describe 'the cipher_one_letter method' do
    it 'ciphers a letter into another *key* rank later in the alphabet given the *key*' do
        expect(cipher_one_letter('a',5)).to eq('f')
        expect(cipher_one_letter('m',0)).to eq('m')
        expect(cipher_one_letter('x',4)).to eq('b')
        expect(cipher_one_letter('d',-1)).to eq('c')
        expect(cipher_one_letter('d',-6)).to eq('x')
    end

    it 'Capitalized letters stay capitalized through ciphering' do
        expect(cipher_one_letter('A',5)).to eq('F')
        expect(cipher_one_letter('M',0)).to eq('M')
        expect(cipher_one_letter('X',4)).to eq('B')
        expect(cipher_one_letter('D',-1)).to eq('C')
        expect(cipher_one_letter('D',-6)).to eq('X')
    end

    it 'leaves the ponctuation unchanged' do
        expect(cipher_one_letter('!',0)).to eq('!')
        expect(cipher_one_letter('!',4)).to eq('!')
        expect(cipher_one_letter('.',-1)).to eq('.')
        expect(cipher_one_letter(',',-6)).to eq(',')
    end

    it 'only takes strings as input' do
        expect(cipher_one_letter(5,5)).to eq("Please give me a string!")
    end

end

describe 'the ceasar_cipher method' do
    it 'ciphers a string into another where each letter is mapped using the key argument. it keeps capitalization and punctuation' do
        expect(ceasar_cipher("What a string!", 5)).to eq("Bmfy f xywnsl!")
    end

    it 'only takes strings as input' do
        expect(cipher_one_letter(5,5)).to eq("Please give me a string!")
    end
    
end<file_sep>require_relative '../lib/jean_michel_trader'

# faire toutes les combinaisons de soustractions possibles / selectionner la plus grande qui respecte jour achat avant jour vente / sortir les jours
describe 'the day_trader method' do
    it 'takes an array of prices and returns the best days to buy and sell' do
        expect(day_trader([17, 3, 6, 9, 15, 8, 6, 1, 10])).to eq("<NAME>! Vous avez intéret à acheter le jour 2 et à vendre le jour 5!")
        expect(day_trader([29, 3, 1, 9, 6, 8, 6, 1, 2])).to eq("<NAME>! Vous avez intéret à acheter le jour 3 et à vendre le jour 4!")
        expect(day_trader([2, 3, 6, 9, 15, 8, 28, 1, 10])).to eq("<NAME>! Vous avez intéret à acheter le jour 1 et à vendre le jour 7!")     
    end
end
        <file_sep>def is_multiple_of_3_or_5?(current_number)
    current_number % 3 == 0 || current_number % 5 == 0 ? true : false
end

def sum_of_3_or_5_multiples(final_number)
    if final_number.class == Integer && final_number >= 0 
        (1...final_number).reduce(0) { |sum , num| is_multiple_of_3_or_5?(num) ? sum + num : sum } 
    else
        'Yo ! Je ne prends que les entiers naturels. TG'
    end
end<file_sep>def word_counter(string, dictionnary)
    matching_h = {}
    for i in (0...dictionnary.length)
    matching_h[string.scan(/#{dictionnary[i]}/i).uniq.join.downcase] = string.scan(/#{dictionnary[i]}/i).size
    end
    matching_h.delete("")
    matching_h
end<file_sep>dictionnary = ["the", "of", "and", "to", "a", "in", "for", "is", "on", "that", "by", "this", "with", "i", "you", "it", "not", "or", "be", "are"]
shakespeare_lifes_work = File.read("./lib/shakespeare.txt")
bad_words = File.read("./lib/bad_words.txt").split("\n")

def count_words(string, dictionnary)
    matching_h = {}
    for i in (0...dictionnary.length)
    matching_h[string.scan(/#{dictionnary[i]}/i).map { |elt| elt.downcase }.uniq.join] = string.scan(/#{dictionnary[i]}/i).size
    end
    matching_h.delete("")
    matching_h
end

puts count_words(shakespeare_lifes_work, bad_words)
puts count_words(shakespeare_lifes_work, dictionnary)<file_sep># projet_20_04
Some ruby exercices
