More experiments with [sourcecode] tags

Here is some code in a [sourcecode] in a post (rather than a comment) – it is a program to solve Enigma 1649. Subsequently editing the post seems to work OK.

def check(a, b):
  # check combinations below 120
  N = 120
  c = [0] * N
  for n in range(0, int(N / a) + 1):
    for m in range(0, int((N - a*n) / b) + 1):
      s = a*n + b*m
      if not(s < N): continue
      c[s] += 1
  if not(c[59] == 1): return
  if c[:60].count(0) < 2: return
  if len([x for x in c[:60] if x > 1]) < 2: return
  if len([x for x in c[60:] if x > 1]) < N - 60: return
  print(a, b, c[:60], c[60:])

# OK, let's assume a < b
for b in range(3, 60):
  for a in range(2, b):
    check(a, b)

Edit: Yes, this is the edited post. The [sourcecode] tags are successfully maintained. (In fact the post editor seems to be somewhat better than the comment editor).

Advertisements

About Jim Randell

Hacking Python for fun.
This entry was posted in Uncategorized. Bookmark the permalink.

2 Responses to More experiments with [sourcecode] tags

  1. jimrandell says:

    This is a comment with some code added in a [sourcecode] tag…

    def check(a, b):
      # check combinations below 120
      N = 120
      c = [0] * N
      for n in range(0, int(N / a) + 1):
        for m in range(0, int((N - a*n) / b) + 1):
          s = a*n + b*m
          if not(s < N): continue
          c[s] += 1
      if not(c[59] == 1): return
      if c[:60].count(0)  1])  1]) < N - 60: return
      print(a, b, c[:60], c[60:])
    
    # OK, let's assume a < b
    for b in range(3, 60):
      for a in range(2, b):
        check(a, b)
    

    Edit: Editing the comment causes the parameters to the [sourcecode] tag to be messed up, resulting in a mangled comment unless it is fixed up manually.

  2. jimrandell says:

    This is the same code without a language parameter to the [sourcecode] tag (and so has no syntax highlighting):

    def check(a, b):
      # check combinations below 120
      N = 120
      c = [0] * N
      for n in range(0, int(N / a) + 1):
        for m in range(0, int((N - a*n) / b) + 1):
          s = a*n + b*m
          if not(s < N): continue
          c[s] += 1
      if not(c[59] == 1): return
      if c[:60].count(0)  1])  1]) < N - 60: return
      print(a, b, c[:60], c[60:])
    
    # OK, let's assume a < b
    for b in range(3, 60):
      for a in range(2, b):
        check(a, b)
    

    Edit: When edited the post remains unmangled.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s