Do not use the same code again

-1

I want to give a task. The main rule is not to use the same code again, it means no loops, no jumps, no goto, no recursion, if you declare procedure it can be called only once and etc. Also if you call some standart function it should meet the requirements inside.

The main point of this task is to write the shorter code which prints the longest output.

NOTE: printing functions, for example printf probably do not meat requirements but it is allowed to use this kind of functions.

EDIT: after reading some comments I have to tell that output needs to be longer then input. Also you cannot use the same function twice because it means you are using the same code, sorry for not very clear requirements.

ST3

Posted 2013-09-27T11:01:27.337

Reputation: 1 279

Question was closed 2013-09-27T14:36:38.153

2This seems to be asking for code which produces output longer than itself with no looping of any kind, even if hidden. This is simply impossible, so it's not at all clear what you're asking for. – Peter Taylor – 2013-09-27T11:10:12.480

1can we use string concatentaion? Also, what's the primary objective winning criterion? Code length with output having to be longer than input? output/input length ratio? – John Dvorak – 2013-09-27T11:34:24.150

After the edit - does my golfscript solution (1 character) qualify? – John Dvorak – 2013-09-27T14:20:07.463

@JanDvorak I'm not into golfscript but I think version 1->2 meets requirements, but the way you got n->2^n doesn't meet requirements. – ST3 – 2013-09-27T14:24:14.467

@ST3 does my C++ solution qualify? But if the focus is on code length rather than output length, then the golfscript solution - if it qualifies - is better anyways. – John Dvorak – 2013-09-27T14:30:32.560

javascript alert(Math.random()+''+Math.random()+''+Math.random()+''+Math.random()+''+Math.random()+''+Math.random()+''+Math.random()+''+Math.random()+''+Math.random()+''+Math.random()+''+Math.random()+''+Math.random()+''+Math.random()+''+Math.random()+''+Math.random()+''+Math.random()+''+Math.random()+''+Math.random()+''+Math.random()+''+Math.random()) - cant put a answer b/c this is on hold. – Math chiller – 2013-09-29T07:18:24.790

@tryingToGetProgrammingStraight it would illegal answer anyway, because you call random more then once – ST3 – 2013-09-30T11:12:21.873

@ST3 would outputting a error count? if so a = ReferenceError: a is not defined [Break On This Error] a – Math chiller – 2013-09-30T11:21:12.543

@tryingToGetProgrammingStraight that would count, it is output anyway. – ST3 – 2013-09-30T12:12:18.923

Answers

2

Python: 11 characters → 857 characters

import this

Sample run:

>>> import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

manatwork

Posted 2013-09-27T11:01:27.337

Reputation: 17 865

2Or I could write python -c 'import sys;help(sys)': 20 → 12106 characters. But then someone would come up with man zshall: 10 → 1668174 characters. (Or man -t zshall: 13 → 2224815 characters.) So we better skip displaying documentations. – manatwork – 2013-09-27T11:40:48.087

2

Golfscript, 1 -> 2

`

if the requirement is to produce the shortest code with an output longer than input, this is the winner (unless we count error messages of languages where an empty source is invalid program). Backtick means "inspect/uneval". Since the empty string (input) happens to be already present on the stack, this produces a string containing only two double quotes, which is then printed out.

C++, 22 -> 2^31-1 (= 2147483647)

printf("%*i",~0u>>1,0)

It's hard to argue that string concatenation or infinite precision arithmetic doesn't loop internally. In such case, we are restricted to built-in finite precision data types. However, the best place for a large value is the output precision, not the value to be printed. In C++, the variable precision type is int, so we can print with no more than 2^31-1 digits of precision. Sure, the printing routine will loop a bit, but printing routines are allowed to. But, if built in operators (but not library functions) are allowed to loop as well,

J, (extreme growth)

!9
!!9
!!!9
!!!!9

the factorial of an n-digit number has in the order of e^n digits for some small e. This means the sequence factorial of (factorial of(factorial of ... (factorial of 9) ...))) grows very quickly.

It's unclear what "same code twice" exactly means, but I'll assume that two invocations of the same system function are allowed as long as the function itself is allowed. "if you declare procedure it can be called only once"

Of course, if function exponentiation doesn't count as iteration, we can grow much more quickly than that:

!^:(!^:]9)9

this will apply factorial to nine nine times, then use that as the number of applications of factorial to (another) nine. Of course, these can be nested ad lib. Say, we could take the factorial of !^:9]9 !^:9]9 times. We'll also shorten !^:9]9 to just !^:]9.

!^:]!^:]9

Ninth composition of !^:] can be shortened to !^:]^:9. The argument'th composition is !^:]^:]. Unfortunately, function power cannot be applied to conjunctions like function power, so let's stop here for now (arg compositions of (arg compositions of (arg compositions of ... factorial))):

!^:]^:]^:]^:]

We could apply "eval" here, but we're way so far off the realm of definitely not iterating I better stop here and not get to stuff like string multiplication and evaluation in order to crank up this immense number even higher.

Golfscrcript, n -> theta(2^n)

````````````...

Languages without built-in infinite precision arithmetic can still achieve exponential growth via string concatenation (twofold increase in two characters). Or, we could inspect the inspection of the inspection of ... yielding twofold increase in just a single char.

John Dvorak

Posted 2013-09-27T11:01:27.337

Reputation: 9 048

1Even better. Use the empty program in GolfScript which will give you a newline. This is a growth factor of 1/0. ;-) – Howard – 2013-09-27T15:40:39.993

@Howard why so? I don't see that in the spec, is that an interpreter feature? – John Dvorak – 2013-09-27T15:43:40.093

It's not explicitely in the spec, but implementations use puts aka {print n print}:puts;. – Howard – 2013-09-27T16:06:23.283

1

My code is: help and it is Windows batch script. Output is:

For more information on a specific command, type HELP command-name
ASSOC          Displays or modifies file extension associations.
ATTRIB         Displays or changes file attributes.
BREAK          Sets or clears extended CTRL+C checking.
BCDEDIT        Sets properties in boot database to control boot loading.
CACLS          Displays or modifies access control lists (ACLs) of files.
CALL           Calls one batch program from another.
CD             Displays the name of or changes the current directory.
CHCP           Displays or sets the active code page number.
CHDIR          Displays the name of or changes the current directory.
CHKDSK         Checks a disk and displays a status report.
CHKNTFS        Displays or modifies the checking of disk at boot time.
CLS            Clears the screen.
CMD            Starts a new instance of the Windows command interpreter.
COLOR          Sets the default console foreground and background colors.
COMP           Compares the contents of two files or sets of files.
COMPACT        Displays or alters the compression of files on NTFS partitions.
CONVERT        Converts FAT volumes to NTFS.  You cannot convert the
               current drive.
COPY           Copies one or more files to another location.
DATE           Displays or sets the date.
DEL            Deletes one or more files.
DIR            Displays a list of files and subdirectories in a directory.
DISKCOMP       Compares the contents of two floppy disks.
DISKCOPY       Copies the contents of one floppy disk to another.
DISKPART       Displays or configures Disk Partition properties.
DOSKEY         Edits command lines, recalls Windows commands, and 
               creates macros.
DRIVERQUERY    Displays current device driver status and properties.
ECHO           Displays messages, or turns command echoing on or off.
ENDLOCAL       Ends localization of environment changes in a batch file.
ERASE          Deletes one or more files.
EXIT           Quits the CMD.EXE program (command interpreter).
FC             Compares two files or sets of files, and displays the 
               differences between them.
FIND           Searches for a text string in a file or files.
FINDSTR        Searches for strings in files.
FOR            Runs a specified command for each file in a set of files.
FORMAT         Formats a disk for use with Windows.
FSUTIL         Displays or configures the file system properties.
FTYPE          Displays or modifies file types used in file extension 
               associations.
GOTO           Directs the Windows command interpreter to a labeled line in 
               a batch program.
GPRESULT       Displays Group Policy information for machine or user.
GRAFTABL       Enables Windows to display an extended character set in 
               graphics mode.
HELP           Provides Help information for Windows commands.
ICACLS         Display, modify, backup, or restore ACLs for files and 
               directories.
IF             Performs conditional processing in batch programs.
LABEL          Creates, changes, or deletes the volume label of a disk.
MD             Creates a directory.
MKDIR          Creates a directory.
MKLINK         Creates Symbolic Links and Hard Links
MODE           Configures a system device.
MORE           Displays output one screen at a time.
MOVE           Moves one or more files from one directory to another 
               directory.
OPENFILES      Displays files opened by remote users for a file share.
PATH           Displays or sets a search path for executable files.
PAUSE          Suspends processing of a batch file and displays a message.
POPD           Restores the previous value of the current directory saved by 
               PUSHD.
PRINT          Prints a text file.
PROMPT         Changes the Windows command prompt.
PUSHD          Saves the current directory then changes it.
RD             Removes a directory.
RECOVER        Recovers readable information from a bad or defective disk.
REM            Records comments (remarks) in batch files or CONFIG.SYS.
REN            Renames a file or files.
RENAME         Renames a file or files.
REPLACE        Replaces files.
RMDIR          Removes a directory.
ROBOCOPY       Advanced utility to copy files and directory trees
SET            Displays, sets, or removes Windows environment variables.
SETLOCAL       Begins localization of environment changes in a batch file.
SC             Displays or configures services (background processes).
SCHTASKS       Schedules commands and programs to run on a computer.
SHIFT          Shifts the position of replaceable parameters in batch files.
SHUTDOWN       Allows proper local or remote shutdown of machine.
SORT           Sorts input.
START          Starts a separate window to run a specified program or command.
SUBST          Associates a path with a drive letter.
SYSTEMINFO     Displays machine specific properties and configuration.
TASKLIST       Displays all currently running tasks including services.
TASKKILL       Kill or stop a running process or application.
TIME           Displays or sets the system time.
TITLE          Sets the window title for a CMD.EXE session.
TREE           Graphically displays the directory structure of a drive or 
               path.
TYPE           Displays the contents of a text file.
VER            Displays the Windows version.
VERIFY         Tells Windows whether to verify that your files are written
               correctly to a disk.
VOL            Displays a disk volume label and serial number.
XCOPY          Copies files and directory trees.
WMIC           Displays WMI information inside interactive command shell.

For more information on tools see the command-line reference in the online help.

I didn't count size of output because it is my own question and I'm not willing to win.

ST3

Posted 2013-09-27T11:01:27.337

Reputation: 1 279

1

Mathematica

RandomInteger[{10^980, 10^990}]

randominteger

DavidC

Posted 2013-09-27T11:01:27.337

Reputation: 24 524

1

Ruby, 13 chars, 599994 char output, ~46153:1 ratio

999999**99999

Simply raises a very large number to the power of another very large number. Takes about ten seconds to run. I could increase the numbers, but that would make the running time even longer.

Doorknob

Posted 2013-09-27T11:01:27.337

Reputation: 68 138

Do you think ** has no jumps, no loops as required? ;-) – Howard – 2013-09-27T12:32:57.050

2@Howard Well by that logic @ manatwork's solution is invalidated since it uses loops behind-the-scenes, the OP's solution is invalidated as help probably uses loops too, and @ David's solution is invalidated because RandomInteger probably uses loops. :P – Doorknob – 2013-09-27T12:34:42.827

Of course you're right. Maybe an indication of a not well-formed challenge? – Howard – 2013-09-27T12:36:43.130

@Howard correct. Yet, for some reason the question didn't manage to get five closevotes yet. – John Dvorak – 2013-09-27T13:20:44.950