Author: Not specified Language: text
Description: Not specified Timestamp: 2018-04-19 17:28:49 +0000
View raw paste Reply
  1. // 1
  2. g = TinkerGraph.open().traversal()
  3.  
  4. g.addV("course").property(T.id, 'CS101').addV("course").property(T.id, 'CS201').addV("course").property(T.id, 'CS220').addV("course").property(T.id, 'CS334').addV("course").property(T.id, 'CS400').addV("course").property(T.id, 'CS420').addV("course").property(T.id, 'CS526').addV("course").property(T.id, 'CS681').addE("requires pre-req").from(V('CS201')).to(V('CS101')).addE("requires pre-req").from(V('CS220')).to(V('CS201')).addE("requires pre-req").from(V('CS420')).to(V('CS220')).addE("is a co-req of").from(V('CS420')).to(V('CS220')).addE("requires pre-req").from(V('CS334')).to(V('CS201')).addE("requires pre-req").from(V('CS681')).to(V('CS334')).addE("requires pre-req").from(V('CS400')).to(V('CS334')).addE("requires pre-req").from(V('CS526')).to(V('CS400')).addE("is a co-req of").from(V('CS526')).to(V('CS400'))
  5.  
  6.  
  7. // 2
  8. g.V().as('a').out().as('b').select('a','b').groupCount().unfold().where(select(values).is(2)).select(keys)
  9.  
  10.  
  11. // 3
  12. g.V("CS526").repeat(out().dedup()).until(out().count().is(0)).emit()
  13.  
  14. // 4
  15. g.V("CS101").repeat(__.in().dedup()).until(__.in().count().is(0)).path().count(local).max()
  16.  
  17. // bonus
  18. g = TinkerGraph.open().traversal()
  19. g.addV("node").property(T.id, 1).addV("node").property(T.id, 2).addV("node").property(T.id, 3).addV("node").property(T.id, 4).addE("path").from(V(1)).to(V(2)).addE("path").from(V(1)).to(V(2)).addE("path").from(V(1)).to(V(3)).addE("path").from(V(2)).to(V(3)).addE("path").from(V(2)).to(V(4)).addE("path").from(V(2)).to(V(4)).addE("path").from(V(3)).to(V(4))
  20.  
  21.  
  22. g.V().where(bothE().count().filter{d = it.get(); d % 2 == 1;}).count().is(lte(2)).hasNext()
View raw paste Reply