-
-
Save lbvf50mobile/85f5abb840f3926feb80f7dfe85d2e01 to your computer and use it in GitHub Desktop.
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
"ROTATING [1, 2, 3]is ASC" | |
"rt: 0 ar: [1, 2, 3]is ASC a<b and a<c and a<c" | |
"rt: 1 ar: [2, 3, 1] a<b and a>c and a>c" | |
"rt: 2 ar: [3, 1, 2] a>b and a<c and a>c" | |
"rt: 3 ar: [1, 2, 3]is ASC a<b and a<c and a<c" | |
"ROTATING [3, 2, 1]is DESC" | |
"rt: 0 ar: [3, 2, 1]is DESC a>b and a>c and a>c" | |
"rt: 1 ar: [2, 1, 3] a>b and a<c and a<c" | |
"rt: 2 ar: [1, 3, 2] a<b and a>c and a<c" | |
"rt: 3 ar: [3, 2, 1]is DESC a>b and a>c and a>c" | |
--------------------- | |
[10, 100, 1] | |
"ROTATING [1, 2, 3]is ASC" | |
"rt: 0 ar: [1, 2, 3]is ASC return true if a<b and a<c and a<c" | |
"rt: 1 ar: [2, 3, 1] return true if a<b and a>c and a>c" | |
"rt: 2 ar: [3, 1, 2] return true if a>b and a<c and a>c" | |
"rt: 3 ar: [1, 2, 3]is ASC return true if a<b and a<c and a<c" | |
"ROTATING [3, 2, 1]is DESC" | |
"rt: 0 ar: [3, 2, 1]is DESC return true if a>b and a>c and a>c" | |
"rt: 1 ar: [2, 1, 3] return true if a>b and a<c and a<c" | |
"rt: 2 ar: [1, 3, 2] return true if a<b and a>c and a<c" | |
"rt: 3 ar: [3, 2, 1]is DESC return true if a>b and a>c and a>c" |
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 solve(arr) | |
a = Array_lbvf.new arr | |
p a | |
show_elements | |
return "A" if a.asc_lbvf? | |
return "D" if a.desc_lbvf? | |
return "RA" if a.rasc_lbvf? | |
return "RD" if a.rdesc_lbvf? | |
end | |
def show_elements | |
asc = Array_lbvf.new [1,2,3] | |
Display.new.rotate_it asc | |
desc = Array_lbvf.new [3,2,1] | |
Display.new.rotate_it desc | |
end | |
#-------------------------------------# | |
class Display | |
def rotate_it arr | |
p "ROTATING #{arr.inspect}" | |
for i in 0..3 | |
rotate = arr.rotate(i) | |
p "rt: #{i} ar: #{Array_lbvf.new(rotate).inspect} #{a_b_c rotate}" | |
end | |
end | |
def a_b_c arr | |
"a#{grt_ls(arr[0],arr[1])}b and b#{grt_ls(arr[1],arr[2])}c and a#{grt_ls(arr[0],arr[2])}c" | |
end | |
def grt_ls(a,b) | |
return ">" if a > b | |
"<" | |
end | |
end | |
class Array_lbvf < Array | |
def asc_lbvf? | |
self == self.sort | |
end | |
def desc_lbvf? | |
self == self.sort.reverse | |
end | |
def rasc_lbvf? | |
return rasc_3_lbvf? if self.size == 3 | |
chunks =self.chunk_while{|x,y| x < y}.to_a | |
are_both_chunks_same_order?(chunks) | |
end | |
def rasc_3_lbvf? | |
a,b,c = self[0],self[1],self[2] | |
return true if a < b and b >c and a > c | |
return true if a > b and b < c and a > c | |
false | |
end | |
def rdesc_lbvf? | |
return rdesc_3_lbvf? if self.size == 3 | |
chunks =self.chunk_while{|x,y| x > y}.to_a | |
are_both_chunks_same_order?(chunks) | |
end | |
def rdesc_3_lbvf? | |
a,b,c = self[0],self[1],self[2] | |
return true if a>b and b<c and a<c | |
return true if a<b and b>c and a<c | |
false | |
end | |
def inspect | |
return super + "is ASC" if asc_lbvf? | |
return super + "is DESC" if desc_lbvf? | |
super | |
end | |
private | |
def are_both_chunks_same_order?(chunks) | |
chunk_a = chunks[0] and Array_lbvf.new(chunks[0]).asc_lbvf? | |
chunk_b = chunks[1] and Array_lbvf.new(chunks[1]).asc_lbvf? | |
return true if chunks.size == 2 and chunk_a and chunk_b | |
end | |
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 solve(arr) | |
a = Array_lbvf.new arr | |
p a | |
## show_elements | |
return "A" if a.asc_lbvf? | |
return "D" if a.desc_lbvf? | |
return "RA" if a.rasc_lbvf? | |
return "RD" if a.rdesc_lbvf? | |
end | |
def show_elements | |
asc = Array_lbvf.new [1,2,3] | |
Display.new.rotate_it asc | |
desc = Array_lbvf.new [3,2,1] | |
Display.new.rotate_it desc | |
end | |
#-------------------------------------# | |
class Display | |
def rotate_it arr | |
p "ROTATING #{arr.inspect}" | |
for i in 0..3 | |
rotate = arr.rotate(i) | |
p "rt: #{i} ar: #{Array_lbvf.new(rotate).inspect} #{a_b_c rotate}" | |
end | |
end | |
def a_b_c arr | |
"a#{grt_ls(arr[0],arr[1])}b and a#{grt_ls(arr[1],arr[2])}c and a#{grt_ls(arr[0],arr[2])}c" | |
end | |
def grt_ls(a,b) | |
return ">" if a > b | |
"<" | |
end | |
end | |
class Array_lbvf < Array | |
def asc_lbvf? | |
self == self.sort | |
end | |
def desc_lbvf? | |
self == self.sort.reverse | |
end | |
def rasc_lbvf? | |
return rasc_3_lbvf? if self.size == 3 | |
chunks =self.chunk_while{|x,y| x < y}.to_a | |
are_both_chunks_same_order?(chunks) | |
end | |
def rasc_3_lbvf? | |
a,b,c = self[0],self[1],self[2] | |
return true if a < b and b >c and a > c | |
return true if a > b and b < c and a > c | |
false | |
end | |
def rdesc_lbvf? | |
return rdesc_3_lbvf? if self.size == 3 | |
chunks =self.chunk_while{|x,y| x > y}.to_a | |
are_both_chunks_same_order?(chunks) | |
end | |
def rdesc_3_lbvf? | |
a,b,c = self[0],self[1],self[2] | |
return true if a>b and b<c and a<c | |
return true if a<b and b>c and a<c | |
false | |
end | |
def inspect | |
return super + "is ASC" if asc_lbvf? | |
return super + "is DESC" if desc_lbvf? | |
super | |
end | |
private | |
def are_both_chunks_same_order?(chunks) | |
chunk_a = chunks[0] and Array_lbvf.new(chunks[0]).asc_lbvf? | |
chunk_b = chunks[1] and Array_lbvf.new(chunks[1]).asc_lbvf? | |
return true if chunks.size == 2 and chunk_a and chunk_b | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
"ROTATING [1, 2, 3]is ASC"
"rt: 0 ar: [1, 2, 3]is ASC A<B and B<C and A<C"
"rt: 1 ar: [2, 3, 1] AC and A>C"
"rt: 2 ar: [3, 1, 2] A>B and BC"
"rt: 3 ar: [1, 2, 3]is ASC A<B and B<C and A<C"
"ROTATING [3, 2, 1]is DESC"
"rt: 0 ar: [3, 2, 1]is DESC A>B and B>C and A>C"
"rt: 1 ar: [2, 1, 3] A>B and B<C and A<C"
"rt: 2 ar: [1, 3, 2] AC and A<C"
"rt: 3 ar: [3, 2, 1]is DESC A>B and B>C and A>C"