Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jagill/833eac508959d3f1cf1b to your computer and use it in GitHub Desktop.
Save jagill/833eac508959d3f1cf1b to your computer and use it in GitHub Desktop.
Storage file for bug in atom
{"mode":"editor","version":1,"windowDimensions":{"x":1975,"y":-439,"width":1998,"height":1112,"maximized":false},"grammars":{"deserializer":"GrammarRegistry","grammarOverridesByPath":{}},"project":{"paths":["/Users/jag/euler"],"buffers":[{"text":"# coding: utf8\n\n'''\nTriangle, pentagonal, and hexagonal numbers are generated by the following\nformulae:\n\nTriangle\t \tTn=n(n+1)/2\t \t1, 3, 6, 10, 15, ...\nPentagonal\t \tPn=n(3n−1)/2\t \t1, 5, 12, 22, 35, ...\nHexagonal\t \tHn=n(2n−1)\t \t1, 6, 15, 28, 45, ...\nIt can be verified that T285 = P165 = H143 = 40755.\n\nFind the next triangle number that is also pentagonal and hexagonal.\n'''\n\ndef triangle(n):\n return n*(n+1)/2\n\ndef pentagonal(n):\n return n*(3*n-1)/2\n\ndef hexagonal(n):\n return n*(2*n - 1)\n\n\ncurrentTn = 0\ncurrentT = 0\n\ncurrentPn = 0\ncurrentP = 0\n\ni = 0\nwhile True:\n i += 1\n h = hexagonal(i)\n while currentT < h:\n currentTn += 1\n currentT = triangle(currentTn)\n while currentP < h:\n currentPn += 1\n currentP = pentagonal(currentPn)\n if h == currentT == currentP:\n print \"t, tn:\", currentT, currentTn\n print \"p, pn:\", currentP, currentPn\n print \"h, hn:\", h, i\n if i == 143:\n print \"Found H143\"\n elif i > 143:\n print \"Found next!\"\n break\n","markers":{"markers":{"1":{"id":1,"range":[[0,0],[0,0]],"tailed":false,"reversed":false,"valid":true,"invalidate":"never","persistent":true,"properties":{"type":"selection","editorId":8},"deserializer":"Marker"}},"deserializer":"MarkerManager"},"history":{"undoStack":[],"redoStack":[],"deserializer":"History"},"encoding":"utf8","filePath":"/Users/jag/euler/045.py","modifiedWhenLastPersisted":false,"digestWhenLastPersisted":"b647027096bac7c6ce36ebcf9f3a42e83f2859cf","deserializer":"TextBuffer"},{"text":"# coding: utf8\n\n'''\nThe number, 1406357289, is a 0 to 9 pandigital number because it is made up of\neach of the digits 0 to 9 in some order, but it also has a rather interesting\nsub-string divisibility property.\n\nLet d1 be the 1st digit, d2 be the 2nd digit, and so on. In this way, we note\nthe following:\n\nd2d3d4=406 is divisible by 2\nd3d4d5=063 is divisible by 3\nd4d5d6=635 is divisible by 5\nd5d6d7=357 is divisible by 7\nd6d7d8=572 is divisible by 11\nd7d8d9=728 is divisible by 13\nd8d9d10=289 is divisible by 17\nFind the sum of all 0 to 9 pandigital numbers with this property.\n'''\nfrom collections import defaultdict\n\n# First, let's find all the 3-digit numbers divisible by the bigger primes.\n# Note that 3 digit can include one 0\n\ndivBy7 = []\ndivBy11 = []\ndivBy13 = []\ndivBy17 = []\n\ndef multiples(n, mx=1000):\n \"\"\"Find multiples of n under mx.\n\n Discard any with repeat digits.\n \"\"\"\n current = n\n while current < mx:\n if not has_repeat(current, 3):\n yield current\n current += n\n\ndef has_repeat_char(s):\n \"\"\"Check if a string has a repeated char\"\"\"\n s = ''.join(sorted(s))\n lastChar = None\n for c in s:\n if lastChar is not None and c == lastChar:\n return True\n lastChar = c\n return False\n\ndef has_repeat(n, k):\n \"\"\"Check if n has a repeated digit, considered as a k-digit number.\n\n >>> has_repeat(123, 3)\n False\n >>> has_repeat(1431, 4)\n True\n >>> has_repeat(12, 3)\n False\n >>> has_repeat(12, 4)\n True\n \"\"\"\n # Make the right format\n f = '%%0%dd' % k\n s = f % n\n return has_repeat_char(s)\n\n\ndef find_missing_digits(substring):\n digits = [str(i) for i in range(10)];\n for ch in substring:\n digits.remove(ch)\n return digits\n\nif __name__ == \"__main__\":\n import doctest\n doctest.testmod()\n\n total = 0\n # Let's build things backwards\n for n17 in multiples(17):\n for n13 in multiples(13):\n if n17/10 != n13 % 100:\n continue\n for n11 in multiples(11):\n if n13/10 != n11 % 100:\n continue\n for n7 in multiples(7):\n if n11/10 != n7 % 100:\n continue\n if (n7 / 10) % 5 != 0:\n # Check if second digit is a multiple of 5\n continue\n for n5 in multiples(5):\n if n7/10 != n5 % 100:\n continue\n for n3 in multiples(3):\n if (n3 / 10) % 2 != 0:\n # Check if second digit is a multiple of 2\n continue\n if n5/10 != n3 % 100:\n continue\n # print n3 through n17\n substring = '%02d%03d%03d' % (n3/10, n7, n17)\n if has_repeat_char(substring):\n continue\n # print substring\n missing = find_missing_digits(substring)\n # Either order is valid\n # print '%s%s%s' % (missing[0], missing[1], substring)\n # print '%s%s%s' % (missing[1], missing[0], substring)\n total += int( '%s%s%s' % (missing[0], missing[1], substring) )\n total += int( '%s%s%s' % (missing[1], missing[0], substring) )\n\n\n # answer: 16695334890\n print total\n","markers":{"markers":{"1":{"id":1,"range":[[0,0],[0,0]],"tailed":false,"reversed":false,"valid":true,"invalidate":"never","persistent":true,"properties":{"type":"selection","editorId":12},"deserializer":"Marker"},"2":{"id":2,"range":[[19,0],[19,35]],"tailed":true,"reversed":false,"valid":true,"invalidate":"never","persistent":true,"properties":{},"deserializer":"Marker"}},"deserializer":"MarkerManager"},"history":{"undoStack":[],"redoStack":[],"deserializer":"History"},"encoding":"utf8","filePath":"/Users/jag/euler/043.py","modifiedWhenLastPersisted":false,"digestWhenLastPersisted":"66117b978823463967ed8eb437b2c76d4fb7e8f6","deserializer":"TextBuffer"},{"text":"# coding: utf8\n\n'''\nThe prime 41, can be written as the sum of six consecutive primes:\n\n41 = 2 + 3 + 5 + 7 + 11 + 13\nThis is the longest sum of consecutive primes that adds to a prime below\none-hundred.\n\nThe longest sum of consecutive primes below one-thousand that adds to a prime,\ncontains 21 terms, and is equal to 953.\n\nWhich prime, below one-million, can be written as the sum of the most\nconsecutive primes?\n'''\nimport utils\n\nMAX = 1000000\n\n# First, find primes and their cumulative sum\nprimes, sieve = utils.findPrimes(MAX)\nprimeSums = []\ntotal = 0\nfor p in primes:\n total += p\n primeSums.append(total)\n\n\n# This really creaks at 10^6; what's the right way to speed it up?\nmax_length = len(primes)\nmax_prime = None\n\nfor (i, p) in enumerate(primes):\n for j in range(i+1, len(primes)):\n q = primes[j]\n length = (j-i+1)\n if length <= max_length:\n continue\n total = primeSums[j] - primeSums[i]\n if total >= MAX:\n break\n if sieve[total]:\n max_length = length\n max_prime = total\n\nprint \"Max prime, length\", max_prime, max_length\n\n# 100: Max prime, length 41 6\n# 1000: Max prime, length 953 21\n# 10000: Max prime, length 9521 65\n# 100000: Max prime, length 92951 183\n# 1000000: Max prime, length 997651 543\n","markers":{"markers":{"1":{"id":1,"range":[[0,0],[0,0]],"tailed":false,"reversed":false,"valid":true,"invalidate":"never","persistent":true,"properties":{"type":"selection","editorId":16},"deserializer":"Marker"}},"deserializer":"MarkerManager"},"history":{"undoStack":[],"redoStack":[],"deserializer":"History"},"encoding":"utf8","filePath":"/Users/jag/euler/050.py","modifiedWhenLastPersisted":false,"digestWhenLastPersisted":"d293ab52c945740a8e91f91f28e29ea3fcdcb44f","deserializer":"TextBuffer"},{"text":"# coding: utf8\n\n'''\nThe first two consecutive numbers to have two distinct prime factors are:\n\n14 = 2 × 7\n15 = 3 × 5\n\nThe first three consecutive numbers to have three distinct prime factors are:\n\n644 = 2² × 7 × 23\n645 = 3 × 5 × 43\n646 = 2 × 17 × 19.\n\nFind the first four consecutive integers to have four distinct prime factors.\nWhat is the first of these numbers?\n'''\nimport utils\nimport math\nfrom collections import defaultdict\n\nN = 1000000\nnFactorsDesired = 4\nprimes, _ = utils.findPrimes(int(math.floor(math.sqrt(N))))\nprint \"Found %d primes\" % len(primes)\n\n# map number: factorMap\nallFactors = {}\ndef findFactors(n):\n origN = n\n factors = defaultdict(int)\n sqrtN = int(math.floor(math.sqrt(n)))\n for (i, p) in enumerate(primes):\n if p > sqrtN:\n break\n # We've already done this calculation, just retrieve it\n if n in allFactors:\n storedFactors = allFactors[n]\n # print \"Found stored factors for\", n\n for k, v in storedFactors.items():\n factors[k] += v\n n = 1\n break\n if n % p == 0:\n # print \"Reducing %d by %d\" % (n, p)\n n, count = utils.reduceFactor(n, p)\n sqrtN = int(math.floor(math.sqrt(n)))\n factors[p] = count\n # Might have a remainder, which is a final factor\n if n > 1:\n factors[n] += 1\n\n if origN not in allFactors:\n allFactors[origN] = factors\n # print \"Found old factors for\", origN, factors\n else:\n # print \"Found new factors for\", origN, factors\n pass\n return factors\n\nfor n in range(2, N):\n if len(findFactors(n)) != nFactorsDesired:\n continue\n if len(findFactors(n+1)) != nFactorsDesired:\n continue\n if len(findFactors(n+2)) != nFactorsDesired:\n continue\n if len(findFactors(n+3)) != nFactorsDesired:\n continue\n print \"Found\", n, findFactors(n)\n break\nelse:\n print \"Found no such numbers under %d\" % N\n\n# answer: 134043\n","markers":{"markers":{"1":{"id":1,"range":[[0,0],[0,0]],"tailed":false,"reversed":false,"valid":true,"invalidate":"never","persistent":true,"properties":{"type":"selection","editorId":20},"deserializer":"Marker"}},"deserializer":"MarkerManager"},"history":{"undoStack":[],"redoStack":[],"deserializer":"History"},"encoding":"utf8","filePath":"/Users/jag/euler/047.py","modifiedWhenLastPersisted":false,"digestWhenLastPersisted":"7c5182bd1731d4b3c33f64a6078832c07abed819","deserializer":"TextBuffer"}],"deserializer":"Project"},"workspace":{"paneContainer":{"root":{"id":7,"items":[{"id":8,"softTabs":true,"displayBuffer":{"id":9,"softWrapped":false,"editorWidthInChars":null,"scrollTop":0,"scrollLeft":0,"tokenizedBuffer":{"bufferPath":"/Users/jag/euler/045.py","invisibles":null,"deserializer":"TokenizedBuffer"},"invisibles":null,"deserializer":"DisplayBuffer"},"deserializer":"TextEditor"},{"id":12,"softTabs":true,"displayBuffer":{"id":13,"softWrapped":false,"editorWidthInChars":null,"scrollTop":0,"scrollLeft":0,"tokenizedBuffer":{"bufferPath":"/Users/jag/euler/043.py","invisibles":null,"deserializer":"TokenizedBuffer"},"invisibles":null,"deserializer":"DisplayBuffer"},"deserializer":"TextEditor"},{"id":16,"softTabs":true,"displayBuffer":{"id":17,"softWrapped":false,"editorWidthInChars":null,"scrollTop":0,"scrollLeft":0,"tokenizedBuffer":{"bufferPath":"/Users/jag/euler/050.py","invisibles":null,"deserializer":"TokenizedBuffer"},"invisibles":null,"deserializer":"DisplayBuffer"},"deserializer":"TextEditor"},{"id":20,"softTabs":true,"displayBuffer":{"id":21,"softWrapped":false,"editorWidthInChars":null,"scrollTop":0,"scrollLeft":0,"tokenizedBuffer":{"bufferPath":"/Users/jag/euler/047.py","invisibles":null,"deserializer":"TokenizedBuffer"},"invisibles":null,"deserializer":"DisplayBuffer"},"deserializer":"TextEditor"},{"deserializer":"ReleaseNotesView","uri":"atom://release-notes","releaseNotes":"<h3>\n<a name=\"notable-changes\" href=\"#notable-changes\"></a>Notable Changes</h3>\n\n<ul>\n<li>Fixed an issue where the <code>atom</code> command would fail to launch if <code>Atom.app</code> was installed to a path that had spaces in it.</li>\n<li>Fixed an issue where the editor's redo history was lost if text was selected after an undo</li>\n<li>Fixed several indentation issues in C/C++ files</li>\n<li>Fixed several colorization issues in Sass, Less, and YAML files</li>\n<li>The spec window now has a button on the top right to re-run all the specs</li>\n<li>Several more bundled packages are now free of calls to deprecated APIs</li>\n</ul>","releaseVersion":"0.154.0"}],"activeItemUri":"atom://release-notes","focused":true,"deserializer":"Pane"},"activePaneId":7,"deserializer":"PaneContainer","version":1},"fullScreen":false,"packagesWithActiveGrammars":["language-python","language-hyperlink","language-todo"],"deserializer":"Workspace"},"packageStates":{"fuzzy-finder":{"/Users/jag/euler/045.py":1418099252020,"/Users/jag/euler/043.py":1418099252571,"/Users/jag/euler/050.py":1418099253593,"/Users/jag/euler/047.py":1418099254132},"keybinding-resolver":{"attached":false},"metrics":{"sessionLength":259486},"tree-view":{"directoryExpansionStates":{},"hasFocus":false,"attached":true,"scrollLeft":0,"scrollTop":285,"width":200}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment