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 (31) - Peter Taylor
- Befunge (29) - Howard
- bc (39) - kernigh
- brainfuck (174) - CMP
- C (78) - l0n3_shArk
- C++ (96) - leftaroundabout
- Common Lisp (88) - kernigh
- Cray Chapel (59) - Kyle Kanos
- csh (86) - kernigh
- Cuda (301) - leftaroundabout
- dc (30) - kernigh
- DOS BATCH (54) - mellamokb
- Element (27) - Howard
- es (95) - kernigh
- Factor (138) - kernigh
- Felix (86) - kirbyfan64sos
- Fortran (44) - Kyle Kanos
- Go (101) - Howard
- GolfScript (16) - Howard
- Golflua (44) - Kyle Kanos
- Haskell (35) - leftaroundabout
- J (23) - Gareth
- Java (141) - Howard
- Julia (71) - M L
- Lua (51) - Howard
- Mercury (319) - leftaroundabout
- MoonScript (48) - kirbyfan64sos
- Nimrod (146) - leftaroundabout
- Owl (22) - r.e.s.
- Pascal (88) - leftaroundabout
- Perl (57) - Gareth
- PHP (61) - mellamokb
- PicoLisp (72) - kernigh
- Piet (56) - M L
- 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 (25) - mellamokb
- Unlimited Register Machine (285) - Paxinum
- VBA (57) - Gaffi
- Whitespace (123) - r.e.s.
- zsh (62) - kernigh
Current User Rankings
Equal ranks are sorted alphabetically.
Howard (9): Befunge (29), Element (27), Go (101), GolfScript (16), Java (141), Lua (51), PostScript, (61) Python, (40) Ruby (44)
kernigh (8): bc (39), Common Lisp (88), csh (86), dc (30), es (95), Factor (138), PicoLisp (72), zsh (62)
leftroundabout (6): C++ (96), Cuda (301), Haskell (35), Mercury (319), Nimrod (146), Pascal (88)
Gareth (3): J (23), Perl (57), Scala (102)
Kyle Kanos (3): Cray Chapel (59), Fortran (44), Golflua (44)
r.e.s. (3): Owl (22), R (50), Whitespace (123)
kirbyfan64sos (2): Felix (86), MoonScript (48)
M L (2): Julia (71), Piet (56)
Aman Zeek verma (1): SQL (57)
CMP (1): brainfuck (174)
Gaffi (1): VBA (57)
l0n3_shArk (1): C (78)
Paxinum (1): Unlimited Register Machine (285)
Peter Taylor (1): bash (31)
tmartin (1): Q (36)