Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Introduction

Pareidolia: From Ancient Greek; παρα ‎(para, “concurrent, alongside”) + εἴδωλον ‎(eídōlon, “image”). The tendency to interpret a vague stimulus as something known to the observer, such as interpreting marks on Mars as canals, seeing shapes in clouds, or hearing hidden messages in music. Source: Wiktionary.

For example:

enter image description here

Paralogia: From Ancient Greek; παρα ‎(para, “concurrent, alongside”) + λόγος ‎(lógos, “speech, oration, word, ...”). The tendency to perceive words in arbitrary sequences of characters, such as in code golf programs. Source: yeah, I made that up (actually the word means something else, as pointed out by @Martin).

For example:

    df4$/H)hEy_^p2\
    jtK2$)look|x1$

Challenge

Write a program that takes a positive integer as input, produces an integer as output, and includes an English word as part of the code. The input-output relationship must correspond to an integer sequence that can be found in OEIS.

Rules

  • Only words from this list are allowed. This is admittedly arbitrary, but it's essential that we all agree on which words are accepted; and in that regard this list is probably as good as any other.
  • Words need to be formed by concatenating at least two function names or statements. If your language for example has a function called correlation it can't be used as is. The concatenation has to be strict: no other symbols should appear between the parts of the word. For example, bro~ken would not count as a word.
  • Case is unimportant: both valid and vaLiDare acceptable.
  • Words within strings do not count. The letters that make up the word need to be functions or statements in the language of choice, that is, something that is actually executed. For example, the following code would not be allowed: 'deoxyribonucleic'~1, where '...' is a string, ~ discards the previous content, and 1 just prints number 1.
  • Every letter of the word should be necessary. This means that removing a single letter from the word should change the input-output relation. That includes outputting a different sequence, or outputting any other thing(s), or producing no output, or causing an error.
  • Any positive integer should be acceptable as an input, and should produce an output, except for data-type or memory restrictions.
  • The outputs corresponding to inputs 1, 2, 3, ... should correspond to a sequence appearing in OEIS. No other output should be produced; only an integer number, possibly with trailing or leading whitespace.
  • Input and output can be function arguments or stdin/stdout.

Score

The score is computed as total code length minus twice the length of the longest word, in characters. Or equivalently, number of not-in-longest-word characters minus length of longest word.

Lowest score wins.

Examples

Consider an imaginary postfix language that has these functions: c: input a number; At: compute square; $: add 1.

cAt would be a valid program (its output corresponds to the sequence 1, 4, 9, ..., which is A000290), and it would have score −3.

cAt$ would also be valid (sequence 2, 5, 10, ..., which is A002522), with score −2.

c$At would not be valid, because the only word here is "At" and is produced by a single function or statement.

share|improve this question
    
I think this should be a popularity contest. – MCMastery Jan 31 at 1:39
4  
@MCMastery This would not make a good popularity contest. (Most challenges wouldn't.) – Alex A. Jan 31 at 6:21
    
This is essentially limited to golfing languages though. – ericw31415 May 8 at 22:05
up vote 8 down vote accepted

CJam, -20

COUNTErREVOLUTIONARIES],

Outputs the nth element in the sequence A010861.

COUNTE                      e# push values of six preinitialized variables
      r                     e# read a token of input
       REVOLUTIONARIES      e# push values of 15 other preinitialized variables
                      ]     e# wrap whole stack in array
                       ,    e# get length

Removing a character from the word results in a completely different sequence A010860. There is a quite interesting relationship between the two sequences: at every index n, A010860(n) is coprime to A010861(n)! There must be some deep mathematical reason behind this.

Try it here.

share|improve this answer
    
I have discovered another curious mathematical relationship: if you subtract the A010860 sequence from the A010861 sequence, the result always equals 1 at every index! Fascinating... – Doorknob Jan 31 at 4:34
    
This one's going to be hard to beat :-) – Luis Mendo Jan 31 at 4:36
    
Oh, upper case.. Great idea :) – Martin Ender Jan 31 at 8:30

CJam, -5

limpet;

A010051: prints 0 for composite numbers and 1 for primes.

It took me forever to find something that scored a few points and would break at the removal of any letter. Removing anything except m throws an error, and removing m turns the program into the identity function.

li  e# Read input and convert to integer.
mp  e# Check for primality.
et  e# Get current datetime as a list.
;   e# Discard the datetime again.

Try it online.

share|improve this answer
    
Beautiful choice of sequence! :-) – Luis Mendo Jan 31 at 0:07

05AB1E, -4 -11

Code, prints A010869 (constant 30):

ASYNcHRonouSlyI)g

Previous code:

DoGS

Explanation:

D     # Duplicate top of the stack
 o    # Pop a, push 2**a
  G   # For N in range(1, 2**a):
   S  # Push all chars seperate from the top of the stack

Prints the A010879 sequence.

share|improve this answer
    
That's the most interesting sequence so far! – Luis Mendo Jan 30 at 18:57
    
@LuisMendo Thank you! :D – Adnan Jan 30 at 18:58
1  
Crossed out -4 is still regular -4 ;( – ETHproductions Feb 2 at 16:20

Pyth, 1

*QhSatan0000
   Satan

Explanation?

       n00   - 0 != 0 (0) 
      a   0  - abs(^-0) (0, Required so it doesn't print out a random 0)
     t       - ^-1 (-1, required or will output 0 all the time)
    a      0 - abs(^-0) (1, Required so counts in right direction, would also print out a random 0)
   S         - 1-indexed range ([1], required so next command works properly)
  h          - Get the head (if `S` missed, will out 2)
*Q           - Multiply by Q

1, 2, 3, 4, 5...

Sequence A000027

Subliminal messages? Never.

Try it here.

share|improve this answer

Japt, -6

NuLLIFIED)r^

Outputs A004453: nimsum of N and 12 (N XOR 12). Test it online!

Note: the OEIS sequence is 0-indexed, so an input of 0 will result in the first item.

How it works

        // Implicit: N = array of inputs
Nu      // Push the following things to N:
LLIF    // 100, 100, 64, 15,
IED     // 64 again, 14, and 13.
)r^     // Reduce by XORing (using ^ between each pair)
        // The reduction goes as follows: U, U^100, U, U^64, U^79, U^15, U^1, U^12.
share|improve this answer
    
Nice! Any explanation, when you can? – Luis Mendo Jan 30 at 18:55
    
@LuisMendo Sure, done. It's incredibly simple, but I haven't found anything more complex yet. – ETHproductions Jan 30 at 18:56
    
@LuisMendo Updated. This one's a little more interesting. – ETHproductions Jan 30 at 19:42
    
Indeed! But apparently removing the Y produces the same output? (unless I'm doing something wrong) – Luis Mendo Jan 30 at 19:58
    
@Luis Is this better? – ETHproductions Jan 30 at 20:18

MATL, −6

INhale

Try it online!

Produces sequence 1, 2, 3, ... (A000027)

Removing any letter changes the output, or leaves the program expecting a second input which doesn't exist, or produces an error.

Explanation

The program simply inhales a number and, after some fiddling around, exhales it unchanged.

I    % produces number 3
N    % number of elements in stack: produces number 1
h    % concatenates horizontally into array [3, 1]
a    % true if any element is nonzero. So it gives true (or equivalently 1)
l    % produces number 1
e    % triggers implicit input and reshapes into a 1x1 array. So it leaves input unchanged
share|improve this answer

Headsecks, score −4

exit

This maps to the Brainfuck program ,+-., which reads a single character and prints it, calculating A000030. Removing any character will obviously break it.

There's also marshal (,-<>+-.), which is effectively ,-., but that doesn't correspond to any OEIS sequence.

share|improve this answer

x86 machine code, score -4

Hexdump of the code:

53 51 55 41 53 68 69 65 73 74 51 58 83 c4 14 c3

Or, in code page 437:

SQUAShiestQXâ─¶├

Assembly code:

push ebx
push ecx
push ebp
inc ecx
push ebx
push 0x74736569
push ecx
pop eax
add esp, 0x14
ret

A function that adds 1 to its argument.

Removing A turns it into an identity function. Removing any other byte messes up the stack, causing either a crash or bad behavior of the calling function.

I am pretty sure it's possible to improve the score, but it may depend on the interpretation of the requirements. For example, using the word SQUEAMIShness gives a program, that increases and then decreases the ebp register. Does removing any of these cause a crash? A simplest test program doesn't use the ebp register, so maybe it doesn't... To avoid this doubt, I used a shorter word.

share|improve this answer

Ruby, score 3

puts gets.partition''

This computes the identity sequence A000027. Output is surrounded by some whitespace; I hope that's okay.

share|improve this answer
    
Yes, whitespace is fine – Luis Mendo Feb 2 at 7:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.