32

Python 2, 64,515 import sys input = map(str.rstrip, sys.stdin.readlines()) width = (len(input[-1]) + 1) / 2 for i in range(len(input)): indent = len(input) - i - 1 input[i] = [c != " " for c in input[i][indent::2]] input[i] += [False] * (width - indent - len(input[i])) input = [[False] * n for n in range(width - len(input) + 1)] + input ...


25

C++11 Further small update: Do much less adding, and try all numbers of form A*B+C. I believe that, within the time limit, this is fairly close to optimal, assuming you only use +, * and !. I leave other operators to people with more time than me! Small update: Try harder to make use of factorials and numbers like 11....111. Also fixed bug that I wasn't ...


18

Python with Python Does a bunch of stuff including renaming of variables, getting rid of unnecessary whitespace and comments, and putting as much as it can on one line. Doesn't always completely work with fancier python syntax and I'll will be continuing to update with any fixes. Code: import string import keyword import pkgutil builtins = __builtins__....


16

Python 2, 59394 59244 58534 58416 58394 58250 Ok here is my solution. import re import math cache = {0:"<()>"} def find(x,i,j): return i*((x**2+x)/2)+(j+1)*((x**2-x)/2) def solve(x, i, j): a = (i + j + 1)/2. b = (i - j - 1)/2. c = -x return (-b + math.sqrt(b**2 - 4*a*c))/(2*a) def size(i,j=0): return 4*(i+j)+14 def ...


15

In Java, computes a short BF snippet which can convert any number to any other number. Each output byte is generated by either transforming the last output byte or a fresh 0 on the tape. The snippets are generated in three ways. First by simple repetitions of + and - (e.g. ++++ converts 7 to 11), by combining known snippets (e.g. if A converts 5 to 50 and ...


14

My previous question, Print a sinusoidal wave (vertically), qualifies at this moment. I'm posting it here as a solution, also hoping that you guys can come up with some shorter solutions to my original question. As required by Vi., I will post a summary of the question. Print a continuous sinusoidal wave scrolling vertically on a terminal. The program ...


14

Brainfuck, 5 + 540 = 545 bytes 5 bytes of code, 540 from output of given test file (assuming got the count right from my paste of that code). ,[.,] Assuming EOF is 0.


13

BrainFuck - 489 Characters Removes all non executable characters. Respects comments from # to end of line. ,[>--[<++>+++++++]<+[>+>+<<-]>[<+>-]+>[<->[-]]<[[,----------]]<>>--[>+ <++++++]<<--------[>+>+<<-]>[<+>-]+>[<->[-]]<[->>.<<]>>+<<...


13

Well here's about the worst possible solution, although a rather nice looking one in Brainfuck itself: ++++++[>+++++++>+++++++++++++++>+++++++<<<-]>++++>+>+>,[[<.>-]<<<.>.>++.--<++.-->>,] Score is probably the worst we are likely to see without intentionally making it bad. Working on calculating ...


13

><>, 14310665 bytes 601398 for hamlet + 13709267 for genesis This is still a work in progress and takes a lot of time to complete. v 0 >i:0(?;:r-:?!v:0a-)?v v >~:v ~ >:a(?v> :1+?v~'v'o v o'^'~\:0)?v >n vno'+' ^?=1:< ^ o'a'<


13

Brain-Flak, 64664 Try it Online! Here is my annotated code ({}< ((((()()()()()){}){}){}()) #41 >) { (({})[()()()()()()]) ([({}<(())>)](<>)){({}())<>}{}<>{}{}<>(({})){(<{}({}<>)>)}{}({}<>) {((< #IF {} {({}[()]< #FOR ((((()()()()()){}){}){}()) #41 (({})[()]) #40 >...


13

Brain-Flak, 130 bytes {({}<>)<>}<>{((((()()()()()){}){}){}<>)<>{(((((()()()()()){}){}){}<>)())<>({}[()])}<>((((()()()()()){}){}){}())<>{}}<>{({}<>)<>}<> Try it online! Output for <your brain-flak code here>: 5045 bytes (()()()()()()()()()()()()()()()()()()()()()()()()()()(...


12

Perl - 177 (source) + 172 (output) = 349 #!perl -p0 y/-+><.,[] -~/p-w/d;s/(.)\K\1+|rs|wv[^v]*(?=w)/$+&&length$&/ge;$_="eval'r$_'=~".'s/.(\d*)/(qw(--$ ++$ -- ++ print+chr$ $$i=ord+getc; while($$i){ })[$&&v63].q($i;))x($++1)/ger' Counting the shebang as 2 bytes, one for each option. First, each of the eight commands is translated ...


12

Java, 5208 5240 5306 6152 This is a recursive function that edges closer to the target, with base cases for when it gets within 5 (which is often only one step). Basically, you can get (a*b)+(a/2) for (a+b)*2 sticks with a simple pattern. If a is odd, the result will be negative, so that leads to some weird logic. This takes a minute or so for 231-1, ...


12

Python 3, 67 tokens import sys import time class Bunny(): def __init__(self): self.direction = [0, 1] self.coords = [-1, -1] def setCoords(self, x, y): self.coords = [x, y] def rotate(self, dir): directions = [[1, 0], [0, 1], [-1, 0], [0, -1]] if dir == 'L': self.direction = directions[(...


11

Python -> Python, 8 distinct characters def minimal_python(input_code): """Convert Python code to minimal Python code.""" # Create a list of the ordinal numbers of <input_code>'s characters. # '%' signs have to be treated specially and are represented with -1. ords = [] num_escaped_chars = 0 for char in input_code: if ...


11

Python 3, 240 236 bytes import subprocess as s,itertools as i def f(S,T,A,N=0): while 1: for P in i.product(A,repeat=N): try: P="".join(P);open("a","w").write(P) if s.check_output(["py","-3","a"],timeout=T).decode()==S:return P except:1 N+=1 Don't run this. On my computer, at least, I found the program really hard to stop once it started ...


10

GolfScript / GolfScript, score 4 "'',,"\{"'"\","*"',+"}%"''+~" The encoder itself is a GolfScript program which takes the original code on STDIN and transforms it into a sequence of characters ',+~. This output itself is valid GolfScript code which performs the same operations as the original version. The basic method consists of an encoding of the code ...


10

Python 3, will score later from collections import defaultdict from functools import lru_cache import sys NUMERIC_OUTPUT = True @lru_cache(maxsize=1024) def to_befunge_num(n): # Convert number to Befunge number, using base 9 encoding (non-optimal, # but something simple is good for now) assert isinstance(n, int) and n >= 0 if n == 0: ...


10

Python/Zilog Z80 machine code, 11.653 11.488 import math,numpy as np def R(n): if n==0:return [] if n<0:return -R(-n) e=int(math.log(n,2)) if n >= 5/3 * 2**e: return np.append(2**(e+1),-R(2**(e+1)-n)) return np.append(2**e,R(n-2**e)) def strR(n): b = R(n) s = "" if n==0:return s e=max(abs(b)) while e: ...


10

Perl, 59222 59156 58460 characters n() (11322660 characters) (n){}() (64664 characters) ((n)){}{} (63610 characters) ((n)()){}{} (63484 characters) - this is a novel calculation (n){({}[()])}{} (60748 characters) n[m] (62800 characters) (n){m({}[l])}{} (58460 characters) - this is a novel calculation The formula for that last calculation is n(n/l+1)/2+mn/l....


9

GolfScript → GolfScript: (4 + 0 + 0) / 2 = 2 ~1`* Program length: 4 Minimum supported size: 0 Maximum supported size: unbounded All sizes supported: yes This program simply reads an integer n from its input, and outputs an n-digit integer consisting of n 1 digits. For example, the input 5 yields the output 11111. In GolfScript, any integer literal (...


9

There are a few options for some of these, so this 100-char set isn't identical to the previously posted ones. 0 (B<A)<A B<A A A<B B ((A<B)<((B<A)<1))<1 (A<(B<1))<1 A<(B<1) (A<B)<((B<A)<1) B<1 (A<B)<1 A<1 (B<A)<1 ((B<A)<A)<1 1 An easier proof that < is functionally complete ...


9

Python, 14307118 bytes 601216 for Hamlet + 13705902 for Genesis = 14307118 There are definitely some senarios under which this solution is not optimal, such as for 1111, where it will output 1111o as opposed to 11oo. However, I think it is nearly optimal. Edit: Saved a few bytes by improving 0o0o to 0oo. The name of the file containing the input is ...


9

CJam/CJam, 143.263 42.713 28.899 23.901 21.903 20.468 ri [ ['X\2b1>e`{~{"1)*)"*}{_({(')*1\"m<"}{"1)*"*}?}?}/]s "X1)*"/"1)"* "1)1)*"/"1)))"* "X1)m<"/"1)))"* _"1)"/("1):Y"+\'Y*+ ] {,}$0= No bonuses apply. Try it online: sample run | score calculator | verification Example runs 1 X 2 1) 3 1)) 4 1))) 5 1)))) 6 ...


9

Python 3, 17071 11845 from functools import lru_cache import heapq import time cases = r""" Hello, World! pneumonoultramicroscopicsilicovolcanoconiosis .oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo. Hickory, dickory, dock. The mouse ran up the clock. The clock struck 1. The mouse ran down. Hickory, dickory, dock. ...


9

JavaScript (ES6), 488 341 bytes s=>[s.replace(/(.)\1+/g,'$1+'),...[...Array(60)].map((_,i)=>`(${(i+4).toString(2).slice(1)})+`),...[...Array(1536)].map((_,i)=>`${i>>10?(i>>8&1)+(i&2?'+':''):''}(${i&1}${i&4?i>>4&1:i&16?'+':''}${i&8?''+(i>>7&1)+(i&64?i>>5&1:i&32?'+':''):''})+${...


8

Python 3.x Well, I'm not going to win any prizes for the shortest output code but maybe for the program to generate the code... x=input();o='' for i in x: a=ord(i) o+="+"*a+".[-]" print(o) 'Hello, World!\n': ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-]++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++...


8

I'm not sure how good it is, but I had fun writing this. (In Clojure...) (ns bf.core) (def input "Hello world!") (defn abs [x] (if (and (< x 0) (= (type x) (type 1))) (* x -1) x)) (defn sqrt? [x y] (if (= (* y y) x) true false) ) (defn sqrt [x] (for [y (range x) :when (sqrt? x y)] y) ) (defn broot [x] ; Run this using trampoline, e.g., (trampoline ...


8

Score: 4787486 4143940 4086426 (without randomly generated data) (4085639 of that are from Lenna.png. That's 99.98%) I don't get the part with the random data. Don't I need an account which I have to pay for to get the data? Pretty naive. Here's the generated code for "1Aa" (49, 65, 97) with a little documentation: // field 0 and 1 are ...


Only top voted, non community-wiki answers of a minimum length are eligible