esolang

cQuents

A program is the definition of a sequence. The input says which term you want.

Stephen S · Turing complete: unknown · ●●○ moderate · esolangs.org

Tested with 13 known programs · Hello World on Try It Online: identical · Test method

Run it

Expected: Hello, World!

The idea

Stephen S made cQuents to define and query sequences and series in as few bytes as possible. A program is a list of terms, a mode and the input n. =1,1:Z+Y is the Fibonacci numbers; =1,1 gives the first two terms, : is the mode, and Z+Y adds the two terms before. With the input 10 it prints the tenth term, 55. With no input at all it prints the whole sequence, without end.

Read the story

The mode decides what n means. : prints the n-th term, & the first n terms, ; the sum of the first n terms, and ? whether n is in the sequence at all. Text in front of the mode is printed as it is, which is how Hello, World!?0 says hello; the text comes out, and the query mode with no input does nothing else.

The machine

PartDoes
text|sep|end before the modePrinted before, between and after the terms; @ escapes a character
=a,b $a,b #a "First terms, first index and step, default input, digits of the terms in a row
: & ; ? ??n-th term, first n terms, sum of n terms, in the sequence, not in it
$ n k Z Y XThe index, the input, the round, the last three terms
A B CFurther inputs, in front of n on the input line
+ - * / ^ % ~ _/Arithmetic; ~ writes two numbers side by side, _/ divides whole
2$A number or name right after another term multiplies it
#N%3=0)The next N for which the condition holds
p D L f z q sNext prime, digits, length, factorial, divisors, prime factors, sort
a b cCall the first, second or third line as a function

Terms take turns, so :1,2 is 1, 2, 1, 2 and so on. Values are Python's big integers, floats, text and lists. An operator that fails on a list to its right goes over the items of that list.

Example

$$ is the index times itself, so the fifth program asks whether 49 is a square.
Expected: 55
Expected: 1,4,9,16,25
Expected: 5050
Expected: True
Expected: Fib: 1, 1, 2, 3, 5, 8!

$$ is the index times itself, so the fifth program asks whether 49 is a square. The last one prints its own text around the terms; @: is a colon that does not start the mode.

Patterns it teaches

  • Code golf: the loop over the terms, the stopping point and the output format are all in one character, the mode.

Try this

  1. Print the first ten odd numbers.
  2. Print the sum of the first n squares.
  3. Hard: print the n-th prime, using # and the next N.

Further

Also in Golfing

Write your own in Run Convert a program from cQuents

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: cquents.

Command line

shib run cquents -e ';$' --input '100'
shib manual cquents

Source

Module
langs/tio/ports.js
Interpreter
langs/tio/cquents.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org