fork download
  1. # your code goes here
  2. b_code = """\
  3. def priority(el, n):
  4. \"\"\"Computes the priority score based on the given tuple and integer.\"\"\"
  5. score = n
  6. in_el = 0
  7. el_count = el.count(0)
  8.  
  9. if el_count == 0:
  10. score += n**2
  11. if el[1] == el[-1]:
  12. score *= 1.5
  13. if el[2] == el[-2]:
  14. score *= 1.5
  15. if el[3] == el[-3]:
  16. score *= 1.5
  17. else:
  18. if el[1] == el[-1]:
  19. score *= 0.5
  20. if el[2] == el[-2]:
  21. score *= 0.5
  22.  
  23. for e in el:
  24. if e == 0:
  25. if in_el == 0:
  26. score *= n * 0.5
  27. elif in_el == el_count - 1:
  28. score *= 0.5
  29. else:
  30. score *= n * 0.5 ** in_el
  31. in_el += 1
  32. else:
  33. score += 1
  34.  
  35. if el[1] == el[-1]:
  36. score *= 1.5
  37. if el[2] == el[-2]:
  38. score *= 1.5
  39.  
  40. return score
  41. """
  42.  
  43. c_code = """\
  44. import numpy as np
  45. import itertools
  46.  
  47. def build_512_cap():
  48. \"\"\"Returns a cap set of size 512 in `n=8` dimensions.\"\"\"
  49. n = 8
  50. V = np.array(list(itertools.product(range(3), repeat=n)), dtype=np.int32)
  51.  
  52. def support(v):
  53. return tuple(i for i in range(n) if v[i] != 0)
  54.  
  55. def reflections(v):
  56. return sum(1 for i in range(1, n//2) if v[i] == v[-i])
  57.  
  58. # Add all 128 weight-8 vectors that have >= 2 reflections.
  59. weight8_vectors = [v for v in V
  60. if np.count_nonzero(v) == 8 # Weight is 8.
  61. and reflections(v) >= 2] # At least 2 reflections.
  62.  
  63. # Add all 128 weight-4 vectors that have specific support.
  64. supports_16 = [(0, 1, 2, 3), (0, 1, 2, 5), (0, 3, 6, 7), (0, 5, 6, 7),
  65. (1, 3, 4, 6), (1, 4, 5, 6), (2, 3, 4, 7), (2, 4, 5, 7)]
  66. weight4_vectors = [v for v in V if support(v) in supports_16]
  67.  
  68. # Add all 128 weight-4 vectors with specific support and 1 reflection.
  69. supports_8 = [(0, 1, 2, 7), (0, 1, 2, 6), (0, 1, 3, 7), (0, 1, 6, 7),
  70. (0, 1, 5, 7), (0, 2, 3, 6), (0, 2, 6, 7), (0, 2, 5, 6),
  71. (1, 2, 4, 7), (1, 2, 4, 6), (1, 3, 4, 7), (1, 4, 6, 7),
  72. (1, 4, 5, 7), (2, 3, 4, 6), (2, 4, 6, 7), (2, 4, 5, 6)]
  73. weight4_vectors_2 = [v for v in V if support(v) in supports_8
  74. and reflections(v) == 1] # Exactly 1 reflection.
  75.  
  76. # Add 128 weight-5 vectors with <= 1 reflections and one more condition.
  77. allowed_zeros = [(0, 4, 7), (0, 2, 4), (0, 1, 4), (0, 4, 6),
  78. (1, 2, 6), (2, 6, 7), (1, 2, 7), (1, 6, 7)]
  79. weight5_vectors = [
  80. v for v in V
  81. if tuple(i for i in range(n) if v[i] == 0) in allowed_zeros
  82. and reflections(v) <= 1 # At most 1 reflection.
  83. and (v[1] != v[7]) % 3 != 1 and (v[2] != v[6]) % 3 != 1
  84. ]
  85.  
  86. return weight8_vectors + weight4_vectors + weight4_vectors_2 + weight5_vectors
  87. """
  88.  
  89. print(b_code)
  90. print(c_code)
  91.  
Success #stdin #stdout 0.11s 14056KB
stdin
Standard input is empty
stdout
def priority(el, n):
    """Computes the priority score based on the given tuple and integer."""
    score = n
    in_el = 0
    el_count = el.count(0)

    if el_count == 0:
        score += n**2
        if el[1] == el[-1]:
            score *= 1.5
        if el[2] == el[-2]:
            score *= 1.5
        if el[3] == el[-3]:
            score *= 1.5
    else:
        if el[1] == el[-1]:
            score *= 0.5
        if el[2] == el[-2]:
            score *= 0.5

    for e in el:
        if e == 0:
            if in_el == 0:
                score *= n * 0.5
            elif in_el == el_count - 1:
                score *= 0.5
            else:
                score *= n * 0.5 ** in_el
            in_el += 1
        else:
            score += 1

    if el[1] == el[-1]:
        score *= 1.5
    if el[2] == el[-2]:
        score *= 1.5

    return score

import numpy as np
import itertools

def build_512_cap():
    """Returns a cap set of size 512 in `n=8` dimensions."""
    n = 8
    V = np.array(list(itertools.product(range(3), repeat=n)), dtype=np.int32)
    
    def support(v):
        return tuple(i for i in range(n) if v[i] != 0)

    def reflections(v):
        return sum(1 for i in range(1, n//2) if v[i] == v[-i])

    # Add all 128 weight-8 vectors that have >= 2 reflections.
    weight8_vectors = [v for v in V 
                        if np.count_nonzero(v) == 8  # Weight is 8.
                        and reflections(v) >= 2]  # At least 2 reflections.

    # Add all 128 weight-4 vectors that have specific support.
    supports_16 = [(0, 1, 2, 3), (0, 1, 2, 5), (0, 3, 6, 7), (0, 5, 6, 7),
                   (1, 3, 4, 6), (1, 4, 5, 6), (2, 3, 4, 7), (2, 4, 5, 7)]
    weight4_vectors = [v for v in V if support(v) in supports_16]

    # Add all 128 weight-4 vectors with specific support and 1 reflection.
    supports_8 = [(0, 1, 2, 7), (0, 1, 2, 6), (0, 1, 3, 7), (0, 1, 6, 7),
                  (0, 1, 5, 7), (0, 2, 3, 6), (0, 2, 6, 7), (0, 2, 5, 6),
                  (1, 2, 4, 7), (1, 2, 4, 6), (1, 3, 4, 7), (1, 4, 6, 7),
                  (1, 4, 5, 7), (2, 3, 4, 6), (2, 4, 6, 7), (2, 4, 5, 6)]
    weight4_vectors_2 = [v for v in V if support(v) in supports_8
                          and reflections(v) == 1]  # Exactly 1 reflection.

    # Add 128 weight-5 vectors with <= 1 reflections and one more condition.
    allowed_zeros = [(0, 4, 7), (0, 2, 4), (0, 1, 4), (0, 4, 6),
                     (1, 2, 6), (2, 6, 7), (1, 2, 7), (1, 6, 7)]
    weight5_vectors = [
        v for v in V
        if tuple(i for i in range(n) if v[i] == 0) in allowed_zeros
        and reflections(v) <= 1  # At most 1 reflection.
        and (v[1] != v[7]) % 3 != 1 and (v[2] != v[6]) % 3 != 1
    ]

    return weight8_vectors + weight4_vectors + weight4_vectors_2 + weight5_vectors