def validSolution(board)
return false if board.flatten.include?(0)
board.map {|a| a.uniq.count == 9}.include?(false) ? false : board
square_of_3 = board.map { |a| a.each_slice(3).to_a }
s1=square_of_3[0][0].zip(square_of_3[1][0],square_of_3[2][0])
s2=square_of_3[0][1].zip(square_of_3[1][1],square_of_3[2][1])
s3=square_of_3[0][2].zip(square_of_3[1][2],square_of_3[2][2])
s4=square_of_3[3][0].zip(square_of_3[4][0],square_of_3[5][0])
ruby
def perimeter(n)
num = [0,1]
i = 0
until i == n do
num << num[i] + num [i+1]
i += 1
end
This file contains 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
def split_and_add(arr, n) | |
n.times { arr.length.odd? ? arr.unshift(0) : arr | |
arr = arr.each_slice(arr.length/2).to_a.transpose.map { |x| x.sum } | |
} | |
arr | |
end |
This file contains 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
def min_min_max(array) | |
sorted = array.sort | |
sorted_all=[*sorted.first..sorted.last] | |
[sorted.first, (sorted_all-sorted).min, sorted.last] | |
end |
This file contains 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
function pyramid(n) { | |
return Array(n).fill(1).map((elemeent, index) => Array(index + 1).fill(1)); | |
} |
This file contains 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
def pyramid(numbers) | |
Array.new(numbers) { |i| [1] * (i + 1) } | |
end |
OlderNewer