Code words in integer sequences

15

1

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.

Luis Mendo

Posted 2016-01-30T18:18:26.583

Reputation: 87 464

I think this should be a popularity contest. – MCMastery – 2016-01-31T01:39:54.303

5@MCMastery This would not make a good popularity contest. (Most challenges wouldn't.) – Alex A. – 2016-01-31T06:21:36.130

This is essentially limited to golfing languages though. – ericw31415 – 2016-05-08T22:05:44.710

Answers

11

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.

lirtosiast

Posted 2016-01-30T18:18:26.583

Reputation: 20 331

1I 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 – 2016-01-31T04:34:43.303

This one's going to be hard to beat :-) – Luis Mendo – 2016-01-31T04:36:07.077

Oh, upper case.. Great idea :) – Martin Ender – 2016-01-31T08:30:48.187

10

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.

Martin Ender

Posted 2016-01-30T18:18:26.583

Reputation: 184 808

Beautiful choice of sequence! :-) – Luis Mendo – 2016-01-31T00:07:34.357

8

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.

Adnan

Posted 2016-01-30T18:18:26.583

Reputation: 41 965

That's the most interesting sequence so far! – Luis Mendo – 2016-01-30T18:57:59.483

2Crossed out -4 is still regular -4 ;( – ETHproductions – 2016-02-02T16:20:07.300

6

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

Luis Mendo

Posted 2016-01-30T18:18:26.583

Reputation: 87 464

5

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.

Blue

Posted 2016-01-30T18:18:26.583

Reputation: 26 661

4

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.

ETHproductions

Posted 2016-01-30T18:18:26.583

Reputation: 47 880

Nice! Any explanation, when you can? – Luis Mendo – 2016-01-30T18:55:29.603

@LuisMendo Sure, done. It's incredibly simple, but I haven't found anything more complex yet. – ETHproductions – 2016-01-30T18:56:26.107

@LuisMendo Updated. This one's a little more interesting. – ETHproductions – 2016-01-30T19:42:36.340

Indeed! But apparently removing the Y produces the same output? (unless I'm doing something wrong) – Luis Mendo – 2016-01-30T19:58:04.893

@Luis Is this better? – ETHproductions – 2016-01-30T20:18:30.307

Yes indeed it is! – Luis Mendo – 2016-01-31T04:11:18.967

3

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.

Lynn

Posted 2016-01-30T18:18:26.583

Reputation: 55 648

2

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.

anatolyg

Posted 2016-01-30T18:18:26.583

Reputation: 10 719

1

Math++, score -2

?*sine

Implements A000004.

SuperJedi224

Posted 2016-01-30T18:18:26.583

Reputation: 11 342

1

Ruby, score 3

puts gets.partition''

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

Lynn

Posted 2016-01-30T18:18:26.583

Reputation: 55 648

Yes, whitespace is fine – Luis Mendo – 2016-02-02T07:48:23.463