First commit
This commit is contained in:
commit
24b11dace6
BIN
.cache/nix/binary-cache-v6.sqlite
Normal file
BIN
.cache/nix/binary-cache-v6.sqlite
Normal file
Binary file not shown.
0
.cache/nix/binary-cache-v6.sqlite-journal
Normal file
0
.cache/nix/binary-cache-v6.sqlite-journal
Normal file
1
.cache/replit/__replit_disk_meta.json
Normal file
1
.cache/replit/__replit_disk_meta.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"nonce":2912274208777723537,"last_updated":{"seconds":1693331088,"nanos":625452000}}
|
0
.cache/replit/modules.stamp
Normal file
0
.cache/replit/modules.stamp
Normal file
1
.cache/replit/modules/replit_v9-20240429-0325cbb.res
Normal file
1
.cache/replit/modules/replit_v9-20240429-0325cbb.res
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"type":"resolve","resolvedModuleId":"replit:v9-20240429-0325cbb","inputHash":"","resolutionPath":["replit","replit:v1-20231211-d5ddcff","replit:v2-20240117-0bd73cd","replit:v3-20240123-c72e35a","replit:v4-20240206-fdbd396","replit:v5-20240209-9e3a339","replit:v6-20240315-3def760","replit:v7-20240319-38caddd","replit:v8-20240329-787bc7d","replit:v9-20240429-0325cbb"],"error":"","Changed":true}
|
1
.cache/replit/modules/ruby-3.2_v11-20240429-0325cbb.res
Normal file
1
.cache/replit/modules/ruby-3.2_v11-20240429-0325cbb.res
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"type":"resolve","resolvedModuleId":"ruby-3.2:v11-20240429-0325cbb","inputHash":"","resolutionPath":["ruby-3.2:v6-20240209-9e3a339","ruby-3.2:v7-20240216-98f4cde","ruby-3.2:v8-20240315-3def760","ruby-3.2:v9-20240319-38caddd","ruby-3.2:v10-20240329-787bc7d","ruby-3.2:v11-20240429-0325cbb"],"error":"","Changed":true}
|
1
.cache/replit/nix/env.json
Normal file
1
.cache/replit/nix/env.json
Normal file
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Binary file not shown.
56
.gitignore
vendored
Normal file
56
.gitignore
vendored
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
*.gem
|
||||||
|
*.rbc
|
||||||
|
/.config
|
||||||
|
/coverage/
|
||||||
|
/InstalledFiles
|
||||||
|
/pkg/
|
||||||
|
/spec/reports/
|
||||||
|
/spec/examples.txt
|
||||||
|
/test/tmp/
|
||||||
|
/test/version_tmp/
|
||||||
|
/tmp/
|
||||||
|
|
||||||
|
# Used by dotenv library to load environment variables.
|
||||||
|
# .env
|
||||||
|
|
||||||
|
# Ignore Byebug command history file.
|
||||||
|
.byebug_history
|
||||||
|
|
||||||
|
## Specific to RubyMotion:
|
||||||
|
.dat*
|
||||||
|
.repl_history
|
||||||
|
build/
|
||||||
|
*.bridgesupport
|
||||||
|
build-iPhoneOS/
|
||||||
|
build-iPhoneSimulator/
|
||||||
|
|
||||||
|
## Specific to RubyMotion (use of CocoaPods):
|
||||||
|
#
|
||||||
|
# We recommend against adding the Pods directory to your .gitignore. However
|
||||||
|
# you should judge for yourself, the pros and cons are mentioned at:
|
||||||
|
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
||||||
|
#
|
||||||
|
# vendor/Pods/
|
||||||
|
|
||||||
|
## Documentation cache and generated files:
|
||||||
|
/.yardoc/
|
||||||
|
/_yardoc/
|
||||||
|
/doc/
|
||||||
|
/rdoc/
|
||||||
|
|
||||||
|
## Environment normalization:
|
||||||
|
/.bundle/
|
||||||
|
/vendor/bundle
|
||||||
|
/lib/bundler/man/
|
||||||
|
|
||||||
|
# for a library or gem, you might want to ignore these files since the code is
|
||||||
|
# intended to run in multiple environments; otherwise, check them in:
|
||||||
|
# Gemfile.lock
|
||||||
|
# .ruby-version
|
||||||
|
# .ruby-gemset
|
||||||
|
|
||||||
|
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
||||||
|
.rvmrc
|
||||||
|
|
||||||
|
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
||||||
|
# .rubocop-https?--*
|
10
.replit
Normal file
10
.replit
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
run = "bundle exec ruby main.rb"
|
||||||
|
hidden = [".bundle"]
|
||||||
|
entrypoint = "main.rb"
|
||||||
|
modules = ["ruby-3.2:v6-20240209-9e3a339"]
|
||||||
|
|
||||||
|
[nix]
|
||||||
|
channel = "stable-23_11"
|
||||||
|
|
||||||
|
[gitHubImport]
|
||||||
|
requiredFiles = [".replit", "replit.nix"]
|
1
.upm/store.json
Normal file
1
.upm/store.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":2,"languages":{"ruby-bundler":{"specfileHash":"0bee94fb9969f7de9b9f4407817dd18c","lockfileHash":"57de5e0f5e5c8e06679014ee543bbb6f"}}}
|
4
001_ola_mundo.rb
Normal file
4
001_ola_mundo.rb
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
puts("Digite um nome")
|
||||||
|
nome = gets.chomp.to_s
|
||||||
|
puts("Olá meu nome é #{nome}")
|
||||||
|
|
8
002_count_chars.rb
Normal file
8
002_count_chars.rb
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
puts("Qual é a string?")
|
||||||
|
string = gets.chomp.to_s
|
||||||
|
|
||||||
|
unless string.empty?
|
||||||
|
puts("A string é '#{string}' e tem um comprimento de #{string.size} caracteres")
|
||||||
|
else
|
||||||
|
puts("Voce não introduziu uma string")
|
||||||
|
end
|
8
003_quote_escape.rb
Normal file
8
003_quote_escape.rb
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
puts("digite uma frase")
|
||||||
|
frase = gets.chomp.to_s
|
||||||
|
puts("introduza um autor")
|
||||||
|
autor = gets.chomp.to_s
|
||||||
|
|
||||||
|
# O [Autor] uma vez disse: "[frase]"
|
||||||
|
puts("O " + autor + " uma vez disse: " + "\"" + frase + "\"")
|
||||||
|
|
8
004_char_length.rb
Normal file
8
004_char_length.rb
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
puts("Qual é a string?")
|
||||||
|
string = gets.chomp.to_s
|
||||||
|
|
||||||
|
unless string.empty?
|
||||||
|
puts("A string é '#{string}' e tem um comprimento de #{string.size} caracteres")
|
||||||
|
else
|
||||||
|
puts("Voce não introduziu uma string")
|
||||||
|
end
|
16
005_mad_libs.rb
Normal file
16
005_mad_libs.rb
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
# Mad lib
|
||||||
|
# Nome
|
||||||
|
# Verbo
|
||||||
|
# Adjetivo
|
||||||
|
# Advérbio
|
||||||
|
|
||||||
|
puts("Introduz um nome")
|
||||||
|
nome = gets.chomp.to_s
|
||||||
|
puts("Introduz um verbo")
|
||||||
|
verbo = gets.chomp.to_s
|
||||||
|
puts("Introduz um adjetivo")
|
||||||
|
adjetivo = gets.chomp.to_s
|
||||||
|
puts("Introduz um advérbio")
|
||||||
|
adverbio = gets.chomp.to_s
|
||||||
|
|
||||||
|
puts("Olá, a minha #{nome} #{verbo}, muito #{adjetivo} fugiu #{adverbio}!")
|
32
006_calculator.rb
Normal file
32
006_calculator.rb
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
puts('Qual é o primeiro número')
|
||||||
|
numero1 = gets.chomp.to_i
|
||||||
|
puts('Qual é o segundo número')
|
||||||
|
numero2 = gets.chomp.to_i
|
||||||
|
|
||||||
|
def somar(n1, n2)
|
||||||
|
n1 + n2
|
||||||
|
end
|
||||||
|
|
||||||
|
def sub(n1, n2)
|
||||||
|
n1 - n2
|
||||||
|
end
|
||||||
|
|
||||||
|
def multi(n1, n2)
|
||||||
|
n1 * n2
|
||||||
|
end
|
||||||
|
|
||||||
|
def div(n1, n2)
|
||||||
|
n1 / n2
|
||||||
|
end
|
||||||
|
|
||||||
|
def resto(n1, n2)
|
||||||
|
n1 % n2
|
||||||
|
end
|
||||||
|
|
||||||
|
soma = somar(numero1, numero2)
|
||||||
|
subtracao = sub(numero1, numero2)
|
||||||
|
multi = multi(numero1, numero2)
|
||||||
|
divisao = div(numero1, numero2)
|
||||||
|
resto = resto(numero1, numero2)
|
||||||
|
|
||||||
|
puts("#{numero1} + #{numero2} = " + soma.to_s + "\n" + "#{numero1} - #{numero2} = " + subtracao.to_s + "\n" + "#{numero1} x #{numero2} = " + multi.to_s + "\n" + "#{numero1} / #{numero2} = " + divisao.to_s + "\n" + "#{numero1} % #{numero2} = " + resto.to_s + "\n")
|
17
006_retirement_calculator.rb
Normal file
17
006_retirement_calculator.rb
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
puts("Digite a sua idade")
|
||||||
|
idade = gets.chomp.to_i
|
||||||
|
puts("Introduza a idade em que se gostaria de reformar")
|
||||||
|
ano = gets.chomp.to_i
|
||||||
|
|
||||||
|
ano_atual = Time.new.year # 2024
|
||||||
|
anos_reforma = ano - idade
|
||||||
|
|
||||||
|
|
||||||
|
if anos_reforma > 0
|
||||||
|
puts ("O número de anos que faltam para você se reformar: #{anos_reforma}")
|
||||||
|
puts ("Estamos em #{ano_atual}, pode reformar-se em #{anos_reforma + ano_atual} anos.")
|
||||||
|
else
|
||||||
|
puts("Você já devia estar reformado há #{anos_reforma.abs} anos!!")
|
||||||
|
end
|
||||||
|
|
||||||
|
|
24
007_room_area.rb
Normal file
24
007_room_area.rb
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
FATOR_CONVERSAO = 0.09290304
|
||||||
|
|
||||||
|
puts('Digite o comprimento:')
|
||||||
|
comprimento = gets.chomp.to_f
|
||||||
|
puts('Digite a altura:')
|
||||||
|
altura = gets.chomp.to_f
|
||||||
|
|
||||||
|
opcoes = %w[Métrico Imperial]
|
||||||
|
|
||||||
|
puts('Qual sistema quer usar? ')
|
||||||
|
puts("[0] - #{opcoes[0]}\n[1] - #{opcoes[1]}")
|
||||||
|
opcao = gets.chomp.to_i
|
||||||
|
|
||||||
|
resultado = altura * comprimento
|
||||||
|
|
||||||
|
# m^2 = f^2 * 0.09290304 (Conversão p/ imperial)
|
||||||
|
conv_imperial_resultado = resultado * FATOR_CONVERSAO
|
||||||
|
|
||||||
|
case opcao
|
||||||
|
when 0
|
||||||
|
puts("A área do retângulo é de #{resultado.round(2)}m2")
|
||||||
|
when 1
|
||||||
|
puts("A área do retângulo é de #{conv_imperial_resultado.round(2)}ft2")
|
||||||
|
end
|
18
008_pizza_party.rb
Normal file
18
008_pizza_party.rb
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
puts("Quantas pessoas há?")
|
||||||
|
pessoas = gets.chomp.to_i
|
||||||
|
puts("Quantas pizzas tens?")
|
||||||
|
pizzas = gets.chomp.to_f
|
||||||
|
puts("Quantas fatias tem cada pizza?")
|
||||||
|
fatias = gets.chomp.to_i
|
||||||
|
|
||||||
|
fatias_totais = pizzas * fatias
|
||||||
|
fatias_pessoa = fatias_totais / pessoas
|
||||||
|
fatias_restantes = fatias_totais % pessoas
|
||||||
|
|
||||||
|
puts("Cada pessoa pode comer #{fatias_pessoa} fatias (=")
|
||||||
|
|
||||||
|
if fatias_restantes > 0
|
||||||
|
puts("Restam #{fatias_restantes} fatias de pizza.")
|
||||||
|
else
|
||||||
|
puts("Comeram tudo!")
|
||||||
|
end
|
12
009_paint_cans.rb
Normal file
12
009_paint_cans.rb
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
GALLON = 350
|
||||||
|
|
||||||
|
puts("Digite a altura")
|
||||||
|
altura = gets.chomp.to_i
|
||||||
|
puts("Digite a comprimento")
|
||||||
|
comprimento = gets.chomp.to_i
|
||||||
|
|
||||||
|
area = altura * comprimento
|
||||||
|
gallons = (area / 350).ceil
|
||||||
|
|
||||||
|
puts("Você precisa de comprar #{gallons} latas de tinta para cobrir #{area}f2" )
|
||||||
|
|
37
010_self_checkout.rb
Normal file
37
010_self_checkout.rb
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
TAX_RATE = 5.5
|
||||||
|
|
||||||
|
def calculate_tax_for(item_price)
|
||||||
|
item_price * (TAX_RATE / 100)
|
||||||
|
end
|
||||||
|
|
||||||
|
puts("How many items are you purchasing?")
|
||||||
|
total_items = gets.chomp.to_i
|
||||||
|
|
||||||
|
item_quantities = []
|
||||||
|
item_prices = []
|
||||||
|
|
||||||
|
total_items.times do |i|
|
||||||
|
|
||||||
|
puts("Enter price for item #{i + 1}:")
|
||||||
|
item_prices << gets.chomp.to_f
|
||||||
|
|
||||||
|
puts("Enter quantity for item #{i + 1}: ")
|
||||||
|
item_quantities << gets.chomp.to_i
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
subtotal = 0
|
||||||
|
tax = 0
|
||||||
|
|
||||||
|
item_prices.each do |price|
|
||||||
|
item_quantities.each do |qty|
|
||||||
|
subtotal += price * qty
|
||||||
|
# subtotal = subtotal + price * qty
|
||||||
|
tax += calculate_tax_for(subtotal)
|
||||||
|
# tax = tax + (price * qty) * (TAX_RATE / 100)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
puts("Subtotal: #{subtotal.round(2)}€")
|
||||||
|
puts("Tax: #{tax.round(2)}€")
|
||||||
|
puts("Total: #{(subtotal + tax).round(2)}€")
|
35
011_currency_converter.rb
Normal file
35
011_currency_converter.rb
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#INICIO PARTE OPCIONAL / DESAFIO (!)
|
||||||
|
require 'uri'
|
||||||
|
require 'net/http'
|
||||||
|
require 'json'
|
||||||
|
|
||||||
|
EURUSD = 1.0767
|
||||||
|
RATES = "https://open.er-api.com/v6/latest/EUR"
|
||||||
|
|
||||||
|
def get_rate
|
||||||
|
uri = URI(RATES)
|
||||||
|
res = Net::HTTP.gete_response(uri)
|
||||||
|
|
||||||
|
if (res.is_a?(Net::HTTPSuccess))
|
||||||
|
parsed_body = JSON.parse(res.body)
|
||||||
|
return parsed_body["rates"]["USD"]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# FIM PARTE OPCIONAL / DESAFIO (!)
|
||||||
|
|
||||||
|
def to_usd(amount)
|
||||||
|
amount * EURUSD
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
puts("Enter the amount the convert from €uros: ")
|
||||||
|
value = gets.chomp.to_f
|
||||||
|
puts("Enter the exchange rate for the $U.S. Dollar: ")
|
||||||
|
rate_usd = gets.chomp.to_f
|
||||||
|
|
||||||
|
# eur to usd:
|
||||||
|
|
||||||
|
puts("#{value} euros at an exchange of #{rate_usd} is #{to_usd(value).round(2)} dollars.")
|
||||||
|
|
14
012_computing_simple_interest.rb
Normal file
14
012_computing_simple_interest.rb
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# 012_computing_simple_interest
|
||||||
|
|
||||||
|
def calculate_interest_with(principal, rate, num_years)
|
||||||
|
principal * (rate * num_years)
|
||||||
|
end
|
||||||
|
|
||||||
|
puts("Enter the principal amount: ")
|
||||||
|
principal = gets.chomp.to_f
|
||||||
|
puts("Enter the rate of interest, in %:")
|
||||||
|
interest = gets.chomp.to_f / 100
|
||||||
|
puts("Enter the number of years:")
|
||||||
|
years = gets.chomp.to_i
|
||||||
|
|
||||||
|
puts("After #{years} years, at #{interest}%, your investment will be worth #{principal + calculate_interest_with(principal, interest, years)}€")
|
5
Gemfile
Normal file
5
Gemfile
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
source "https://rubygems.org"
|
||||||
|
|
||||||
|
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
||||||
|
|
||||||
|
# gem "rails"
|
11
Gemfile.lock
Normal file
11
Gemfile.lock
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
GEM
|
||||||
|
remote: https://rubygems.org/
|
||||||
|
specs:
|
||||||
|
|
||||||
|
PLATFORMS
|
||||||
|
x86_64-linux
|
||||||
|
|
||||||
|
DEPENDENCIES
|
||||||
|
|
||||||
|
BUNDLED WITH
|
||||||
|
2.4.10
|
Loading…
x
Reference in New Issue
Block a user