Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Dec 7th, 2018 72 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. const (
  2.     x_y int8 = iota
  3.     x_star
  4.     star_y
  5.     star_star
  6. )
  7.  
  8. type cell func([]string, []string)bool
  9.  
  10. func matchXY(a, b []string) bool {
  11.     return a[0] == b[0] && a[1] == b[1]
  12. }
  13.  
  14. func matchX(a, b []string) bool {
  15.     return a[0] == b[0]
  16. }
  17.  
  18. func matchY(a, b []string) bool {
  19.     return a[1] == b[1]
  20. }
  21.  
  22. func yes(a, b []string) bool {
  23.     return true
  24. }
  25.  
  26. func no(a, b []string) bool {
  27.     return false
  28. }
  29.  
  30. var (
  31.     rules [4][4]cell = [4][4]cell {
  32.         [4]cell{matchXY, matchX, matchY, yes},
  33.         [4]cell{matchX, matchX, no, yes},
  34.         [4]cell{matchY, no, matchY, yes},
  35.         [4]cell{yes, yes, yes, yes},
  36.     }
  37. )
  38.  
  39. func kind(in []string)int8 {
  40.     switch {
  41.         case in[0] == "*" && in[1] == "*" : return star_star
  42.         case in[0] == "*" : return star_y
  43.         case in[1] == "*" : return x_star
  44.         default : return x_y
  45.     }
  46.     return x_y
  47. }
  48.  
  49. func match(required, provided string) (ok bool) {
  50.     reqParts, provParts := strings.Split(required, "/"), strings.Split(provided, "/")
  51.     if len(reqParts) == 2 && len(provParts) == 2{
  52.         ok = rules[kind(reqParts)][kind(provParts)](reqParts,provParts)
  53.     }
  54.     return
  55. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top