Skip to main content
Bounty Ended with 100 reputation awarded by Beta Decay
added 76 characters in body
Source Link
hyperneutrino
  • 42.6k
  • 5
  • 68
  • 224

Python 2 + xkcd, 82 bytes

Poorly written script

lambda n:eval("'''%s'''"%xkcd.getComic(n).altText.replace(';;',"'''"))
import xkcd

Appends and prepends "''' to the end and start of the string, and then evals it. Works for everything unless it contains double-quotes. Since there are things that contain double quoteswhich, unless the inner regex replaces "..." withtext contains \"...\"''' so it evaluates properly, will not break, even for other quotation marks. HoweverThat is, becauseexcept if the stupid mouseover text also hascontains "...";;, it only works when a curly brace is not in the stringwhich gets replaced with ''' (please tell me if this has false breakageeliminating re). AdditionallyThis only applies for 859, one of the XKCDs also hasand thus this code breaks on '..."859 because Randall Munroe was being dumb. :P

Also, it also replaces aone should never "eval at the end of the string withrandom internet content, because if \"xkcd.getComic(n).altText somehow became '''+__import__('os').system('rm -rf / --no-preserve-root')+''', it would cause many bad things to happen. Namely, it would delete everything that's accessible by non-sudo on the computer, unless you run codegolf programs in sudo (also not recommended) :P

Python 2 + xkcd, 82 bytes

Poorly written script

lambda n:eval("'''%s'''"%xkcd.getComic(n).altText.replace(';;',"'''"))
import xkcd

Appends and prepends " to the end and start of the string, and then evals it. Works for everything unless it contains double-quotes. Since there are things that contain double quotes, the inner regex replaces "..." with \"...\" so it evaluates properly. However, because the stupid mouseover text also has "...", it only works when a curly brace is not in the string (please tell me if this has false breakage). Additionally, one of the XKCDs also has '..." because Randall Munroe was being dumb :P, it also replaces a " at the end of the string with \".

Python 2 + xkcd, 82 bytes

Poorly written script

lambda n:eval("'''%s'''"%xkcd.getComic(n).altText.replace(';;',"'''"))
import xkcd

Appends and prepends ''', which, unless the text contains ''', will not break, even for other quotation marks. That is, except if the text contains ;;, which gets replaced with ''' (eliminating re). This only applies for 859, and thus this code breaks on 859. :P

Also, one should never eval random internet content, because if xkcd.getComic(n).altText somehow became '''+__import__('os').system('rm -rf / --no-preserve-root')+''', it would cause many bad things to happen. Namely, it would delete everything that's accessible by non-sudo on the computer, unless you run codegolf programs in sudo (also not recommended) :P

Python 2 + xkcd, 82 bytes

Poorly written script

lambda n:eval("'''%s'''"%xkcd.getComic(n).altText.replace(';;',"'''"))
import xkcd
lambda n:eval("'''%s'''"%xkcd.getComic(n).altText.replace(';;',"'''"))
import xkcd

Appends and prepends " to the end and start of the string, and then evals it. Works for everything unless it contains double-quotes. Since there are things that contain double quotes, the inner regex replaces "..." with \"...\" so it evaluates properly. However, because the stupid mouseover text also has "...", it only works when a curly brace is not in the string (please tell me if this has false breakage). Additionally, one of the XKCDs also has '..." because Randall Munroe was being dumb :P, it also replaces a " at the end of the string with \".

Python 2 + xkcd, 82 bytes

Poorly written script

lambda n:eval("'''%s'''"%xkcd.getComic(n).altText.replace(';;',"'''"))
import xkcd

Appends and prepends " to the end and start of the string, and then evals it. Works for everything unless it contains double-quotes. Since there are things that contain double quotes, the inner regex replaces "..." with \"...\" so it evaluates properly. However, because the stupid mouseover text also has "...", it only works when a curly brace is not in the string (please tell me if this has false breakage). Additionally, one of the XKCDs also has '..." because Randall Munroe was being dumb :P, it also replaces a " at the end of the string with \".

Python 2 + xkcd, 82 bytes

Poorly written script

lambda n:eval("'''%s'''"%xkcd.getComic(n).altText.replace(';;',"'''"))
import xkcd

Appends and prepends " to the end and start of the string, and then evals it. Works for everything unless it contains double-quotes. Since there are things that contain double quotes, the inner regex replaces "..." with \"...\" so it evaluates properly. However, because the stupid mouseover text also has "...", it only works when a curly brace is not in the string (please tell me if this has false breakage). Additionally, one of the XKCDs also has '..." because Randall Munroe was being dumb :P, it also replaces a " at the end of the string with \".

deleted 36 characters in body
Source Link
hyperneutrino
  • 42.6k
  • 5
  • 68
  • 224

Python 2 + xkcd, 11882 bytes

Poorly written script

lambda n:eval('"%s"'%re.sub(r'([^\\])"$',r'\1\"',re.sub('"([^"{]+)"',r'\"\1\"',xkcd"'''%s'''"%xkcd.getComic(n).altText).replace(';;',"'''"))
import xkcd

Appends and prepends " to the end and start of the string, and then evals it. Works for everything unless it contains double-quotes. Since there are things that contain double quotes, the inner regex replaces "..." with \"...\" so it evaluates properly. However, because the stupid mouseover text also has "...", it only works when a curly brace is not in the string (please tell me if this has false breakage). Additionally, one of the XKCDs also has '..." because Randall Munroe was being dumb :P, it also replaces a " at the end of the string with \".

Python 2 + xkcd, 118 bytes

Poorly written script

lambda n:eval('"%s"'%re.sub(r'([^\\])"$',r'\1\"',re.sub('"([^"{]+)"',r'\"\1\"',xkcd.getComic(n).altText)))
import xkcd

Appends and prepends " to the end and start of the string, and then evals it. Works for everything unless it contains double-quotes. Since there are things that contain double quotes, the inner regex replaces "..." with \"...\" so it evaluates properly. However, because the stupid mouseover text also has "...", it only works when a curly brace is not in the string (please tell me if this has false breakage). Additionally, one of the XKCDs also has '..." because Randall Munroe was being dumb :P, it also replaces a " at the end of the string with \".

Python 2 + xkcd, 82 bytes

Poorly written script

lambda n:eval("'''%s'''"%xkcd.getComic(n).altText.replace(';;',"'''"))
import xkcd

Appends and prepends " to the end and start of the string, and then evals it. Works for everything unless it contains double-quotes. Since there are things that contain double quotes, the inner regex replaces "..." with \"...\" so it evaluates properly. However, because the stupid mouseover text also has "...", it only works when a curly brace is not in the string (please tell me if this has false breakage). Additionally, one of the XKCDs also has '..." because Randall Munroe was being dumb :P, it also replaces a " at the end of the string with \".

added 572 characters in body
Source Link
hyperneutrino
  • 42.6k
  • 5
  • 68
  • 224
Loading
Source Link
hyperneutrino
  • 42.6k
  • 5
  • 68
  • 224
Loading