Usando recursividade
def print(times: 1, msg:)
puts msg
times += 1
print(times: times, msg: msg) unless times > 50
end
A matchstick factory has to put n matchsticks in boxes. The factory has the following three types of boxes:
A big box holds 50 matchsticks A medium box holds 20 matchsticks A small box holds five 5 matchsticks The boxes can’t have fewer matchsticks than they can hold; they must be full.
Implement the boxes/1 function in the MatchstickFactory module. The boxes/1 function returns the number of boxes of each size needed to accommodate all the matchsticks and the number of remaining matchsticks as a map (The map is included in the started code). It should work like this:
In your command-line run the following commands:
brew doctor
brew update
#################################### | |
# Pilares da Orientação a Objetos: # | |
#################################### | |
# 👍 Abstração. | > | |
# 👍 Encapsulamento | > > Composição 🙌 | |
# 👍 Polimorfismo | > | |
# 👎 Herança |
def generate_crystal_code(class_name, method_name, parameter_type, parameter_name) | |
code = <<~CRYSTAL | |
# Generated Crystal code | |
module MyModule | |
class #{class_name} | |
def initialize(#{parameter_name} : #{parameter_type}) | |
@#{parameter_name} = #{parameter_name} | |
end | |
def #{method_name} |
class CrystalDSL | |
attr_reader :code | |
def initialize(&block) | |
@code = '' | |
instance_eval(&block) if block_given? | |
end | |
def generate(&block) | |
instance_eval(&block) if block_given? |
list = [1, 2, 3, 4, 5, 6, 7, 30, 32, 12, 21, 22, 56, 70, 62] | |
list = list.sort | |
find = 21 | |
list.each do |item| | |
puts "The number #{find} is here!" if item == find | |
end |
def binary_search(list, item) | |
end |
Solved that problem running these first:
sudo apt update sudo apt install git zsh -y Then the curl:
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
cat ~/.bash_history | awk '{print ": '`date +%s`':0;" $0}' >> ~/.zsh_history |