Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active November 28, 2017 07:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lbvf50mobile/85f5abb840f3926feb80f7dfe85d2e01 to your computer and use it in GitHub Desktop.
Save lbvf50mobile/85f5abb840f3926feb80f7dfe85d2e01 to your computer and use it in GitHub Desktop.
"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"
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
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
@lbvf50mobile
Copy link
Author

"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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment