Skip to content

Instantly share code, notes, and snippets.

@angelysantos
Created September 14, 2022 13:34
Show Gist options
  • Save angelysantos/c67f66f70f0c101e521c5635cbd85f65 to your computer and use it in GitHub Desktop.
Save angelysantos/c67f66f70f0c101e521c5635cbd85f65 to your computer and use it in GitHub Desktop.
def play
turn = 0
@code = Array.new(8,Array.new(4,""))
check = Array.new(8,Array.new(4,""))
while turn < 8
for i in 0..turn do
puts @code[i].join
puts check[i].join
end
puts "Turn #{turn+1}: Insert the guesscode"
loop do
@code[turn]= gets.chomp.upcase.split("")
if @code[turn].length==4
break
else puts "insert four letter code"
end
end
check[turn]= @code[turn]
difference = @code[turn]- @@mastercode
difference.each {|i|
check[turn][check[turn].index(i)] = "." }
check[turn].reduce(0){|i,letter|
if letter.eql?(@@mastercode[i]) == true
check[turn][i]="+"
i += 1
elsif letter!="."
check[turn][i]= "-"
i +=1
end}
turn += 1 ############# HERE @code is equal to check
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment