The goal of a Rosetta Stone Challenge is to write solutions in as many languages as possible. Show off your programming multilingualism!
Your challenge is to implement a program that will input a list of numbers and output the rule used to generate each successive number in the series, in as many programming languages as possible. You are allowed to use any sort of standard library function that your language has, since this is mostly a language showcase.
What is a "series?"
A series is an ordered list of integers. Each successive number in the series can be generated by applying a simple rule to the previous number in the series. In this challenge, the rule consists of multiplying the number by a constant, and then adding a second constant. Both of the constants can be any integer. The goal of this challenge is to output those two constants.
For the series
2 5 11, the rule can be written as
2 1. This means that each number is the previous number, times 2, plus 1. An important fact is that most series have exactly one rule. Some series have either an infinite number or none at all, but you will not have to deal with this.
Input will be a list of three different integers which are the numbers in the sequence. The numbers can be either space, comma, or newline delimited, but please specify which. I am going to be flexible on this limitation because certain languages may have input restrictions. Here are four examples of input:
0 7 14 2 5 11 2 0 -4 5 -19 77
Output will be two integers which represent the rule used to generate the series. The first number will be the multiplicative constant, while the second number will be the additive constant. The formatting of the output can be space, comma, or newline delimited. I am flexible on this limitation as well. Here are the corresponding examples of output:
1 7 2 1 2 -4 -4 1
The Objective Winning Criterion
As for an objective winning criterion, here it is: Each language is a separate competition as to who can write the shortest entry, but the overall winner would be the person who wins the most of these sub-competitions. This means that a person who answers in many uncommon languages can gain an advantage. Code-golf is mostly a tiebreaker for when there is more than one solution in a language: the person with the shortest program gets credit for that language.
Rules, Restrictions, and Notes
Your program can be written in any language that existed prior to April 9th, 2012. I will also have to rely on the community to validate some responses written in some of the more uncommon/esoteric languages, since I am unlikely to be able to test them.
This section will be periodically updated to show the number of languages and who is leading in each.
- AWK (32) - mellamokb
- bash (38) - mellamokb
- Befunge (29) - Howard
- bc (39) - kernigh
- brainfuck (174) - CMP
- C (78) - l0n3_shArk
- C++ (96) - leftaroundabout
- Common Lisp (88) - kernigh
- csh (86) - kernigh
- Cuda (301) - leftaroundabout
- dc (30) - kernigh
- DOS BATCH (55) - mellamokb
- Element (27) - Howard
- es (95) - kernigh
- Factor (138) - kernigh
- Fortran (90) - Howard
- Go (101) - Howard
- GolfScript (16) - Howard
- Haskell (35) - leftaroundabout
- J (23) - Gareth
- Java (141) - Howard
- Lua (68) - Howard
- Mercury (319) - leftaroundabout
- Nimrod (146) - leftaroundabout
- Owl (22) - r.e.s.
- Pascal (88) - leftaroundabout
- Perl (57) - Gareth
- PHP (62) - mellamokb
- PicoLisp (74) - kernigh
- Piet (82) - CMP
- PostScript (61) - Howard
- Python (40) - Howard
- Q (36) - tmartin
- QBasic (34) - mellamokb
- R (50) - r.e.s.
- Ruby (44) - Howard
- Scala (102) - Gareth
- SQL (57) - Aman ZeeK Verma
- TI-83 BASIC (41) - mellamokb
- Unlimited Register Machine (285) - Paxinum
- VBA (57) - Gaffi
- Whitespace (123) - r.e.s.
- zsh (62) - kernigh
Current User Rankings (courtesy of mellamokb)
Howard (10): Befunge (29),Element (27),Fortran (90),Go (101),GolfScript (16),Java (141),Lua (68),Python (40),Ruby (44),PostScript (61)
kernigh (8): bc (39),Common Lisp (88),csh (86),dc (30),es (95),Factor (138),PicoLisp (74),zsh (62)
leftaroundabout (6): C++ (96),Cuda (301),Haskell (35),Mercury (319),Nimrod (146),Pascal (88)
Gareth (3): J (23),Perl (57),Scala (102)
r.e.s. (3): Owl (22),R (50),Whitespace (123)
CMP (2): brainfuck (174),Piet (82)
l0n3_shArk (1): C (78),
tmartin (1): Q (36)
Paxinum (1): Unlimited Register Machine (285)
Gaffi (1): VBA (57)
Aman ZeeK Verma (1): SQL (57)