[Question]
  [
# Task
Given a String as input, your task is to output `42` **only** if the input String happens to be *exactly* the following :
```
abbcccddddeeeeeffffffggggggghhhhhhhhiiiiiiiiijjjjjjjjjjkkkkkkkkkkkllllllllllllmmmmmmmmmmmmmnnnnnnnnnnnnnnoooooooooooooooppppppppppppppppqqqqqqqqqqqqqqqqqrrrrrrrrrrrrrrrrrrsssssssssssssssssssttttttttttttttttttttuuuuuuuuuuuuuuuuuuuuuvvvvvvvvvvvvvvvvvvvvvvwwwwwwwwwwwwwwwwwwwwwwwxxxxxxxxxxxxxxxxxxxxxxxxyyyyyyyyyyyyyyyyyyyyyyyyyzzzzzzzzzzzzzzzzzzzzzzzzzz
```
It may output any other value, produce an error or not output at all, if the input does not equal the aforementioned String.
---
## Winning Criterion
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code in bytes wins!
  
[Answer]
## Golfscript, 20
```
26,{.97+\{.}*}%=42`*
```
with new line, 21 chars (by Nabb)
```
26,{).[96+]*}%n+=42`*
```
Actually Nabb beat mine, here is original solution for with new line, 22 chars
```
26,{.97+\{.}*}%n+=42`*
```
This is simply generating source string and just comparing it against string from stdin.
[Answer]
## Ruby 1.9, ~~46 42~~ 39 characters
```
p (?a..?z).map{|a|a*$.+=1}*""==gets&&42
```
Assumes the input isn't terminated with a newline.
[Answer]
## C program - 78 89
**Edit:** Do not print 42 when there are extra characters.
Assumes input does not have a trailing newline.
```
main(i,j){for(i=1;i<27;i++)for(j=i;j--;getchar()==96+i?0:exit(1));puts("42"+!!gets(&i));}
```
If the prefix does not match, the program exits. If the prefix matches but there is 1-3 or so extra characters, prints 2. Otherwise, produces undefined behavior.
This can be made one character shorter by changing `exit(1)` to `fork()`. Oh, and on an unrelated note, remember to save any open documents in case, for [whatever reason](http://en.wikipedia.org/wiki/Fork_bomb), your system happens to lock up.
[Answer]
## PHP (60)
Assuming the input is provided in the commandline:
```
for(;$i<702;)$s.=chr(96.5+sqrt($i+=2));echo$s!=$argv[1]?:42;
```
**Explanation**: you can view the string as a triangle structure.
```
j     i   val
0     0   a
1   1-2   bb
2   3-5   ccc
3   6-9   dddd
4 10-14   eeeee
5 15-20   ffffff
      ...
```
Line `j` starts at index `i = j*(j+1)/2` (that's the triangular number formula). Solving the quadratic equation results in index `i` being on line `j = int((sqrt(8*i+1)-1)/2)` and therefore containing character `97 + int((sqrt(8*i+1)-1)/2)`. The `0-350` index range allows us to simplify that to `96.5 + sqrt(2*(i+1))`, but that no longer holds true for larger values.
**Edit**: Switched to commandline input as suggested in the comments.  
**Edit**: Uses conditional operator to save a character
[Answer]
## Perl, 35 ~~43~~
```
map$s.=$_ x++$a,a..z;say 42if<>~~$s
```
Needs Perl 5.10 or later (run with `-E`), no newline in input.
I liked my side-effects regex better, but the shorter code has spoken. Here it is as a souvenir. Also intended for Perl 5.10 or later, but only for the advanced/experimental regex features, so only a `p` command-line option is needed.
```
$a=a;$_=/^(??{$b++;$a++."{$b}"}){26}$/&&42
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 7 bytes
```
AƶJQi42
```
[Try it online!](https://tio.run/##dcHXFUAwAADAlfAYwK8/IyQRRO9tMCNYKzqpd4YDoIkpdbfV84ltUQogRAgFB3wKL9EtfpBX8kl/GSNnFZySVwlqUSNpZZ1CrzIojWqTxqyzaO0 "05AB1E – Try It Online")
### Explanation
```
A       push lowercase alphabet
 ƶ      lift every letter, push it and multiply it by its index
  J     join the list
   Qi   does it equal the input?
     42 push 42 and output implicitly
```
Just going through some challenges to learn 05AB1E (and golfing in general). This challenge was marked as active yesterday and I found a short solution, so why not share? :)
[Answer]
## Haskell program - 71 67 64 57
Assumes no trailing newline, and does not output one either.
```
f x|x==[c|c<-['a'..'z'],_<-['a'..c]]="42"
main=interact f
```
Usage:
```
$ echo -n 'abbcccddddeeeeeffffffggggggghhhhhhhhiiiiiiiiijjjjjjjjjjkkkkkkkkkkkllllllllllllmmmmmmmmmmmmmnnnnnnnnnnnnnnoooooooooooooooppppppppppppppppqqqqqqqqqqqqqqqqqrrrrrrrrrrrrrrrrrrsssssssssssssssssssttttttttttttttttttttuuuuuuuuuuuuuuuuuuuuuvvvvvvvvvvvvvvvvvvvvvvwwwwwwwwwwwwwwwwwwwwwwwxxxxxxxxxxxxxxxxxxxxxxxxyyyyyyyyyyyyyyyyyyyyyyyyyzzzzzzzzzzzzzzzzzzzzzzzzzz' | { ./42; echo; }
42
$ echo -n 'something else' | { ./42; echo; }
42: 42.hs:1:0-54: Non-exhaustive patterns in function f
$
```
[Answer]
## J, 29
```
f=:42#~((>:#a.{~97+])i.26)-:]
```
example:
```
f 'oasijfiojasef'
f 23841235
f 'abbccc...'
42
```
[Answer]
# D: 94 Characters
```
void f(S)(S s){S t;foreach(i;0..26)t~=array(repeat(cast(char)(i+'a'),i+1));s==t&&writeln(42);}
```
More Legibly:
```
void f(S)(S s)
{
    S t;
    foreach(i; 0 .. 26)
        t ~= array(repeat(cast(char)(i + 'a'), i + 1));
    s == t && writeln(42);
}
```
[Answer]
## Delphi, 164 132
This one builds a string and just compares it against the first command-line argument. It's shorter and less tricky than my other submission :
```
var s:string;c,i:int8;begin repeat s:=s+Char(c+97);i:=i-1;c:=c+Ord(i<0);if i<0then i:=c;until c=26;Write(42*Ord(s=ParamStr(1)));end.
```
(Note, that this version assumes that the `c` and `i` variables start out initialized at 0, as is the case in my version of Delphi (2010).)
Like my other submission, this one needs less characters if the string-building doesn't take place in a function, like I did before :
## Delphi, 181
```
program a;{$APPTYPE CONSOLE}function s(c,i:byte):string;begin if(i>0)then Exit(Char(c)+s(c,i-1));if(c<122)then Exit(s(c+1,c-95));end;begin if(s(97,1)=ParamStr(1))then Write(42);end.
```
Note that the output doesn't need a newline, so WriteLn() became Write().
[Answer]
## PHP - 45 characters
I'm surprise nobody posted any answer that used hashing. It's a very size effecient way of testing for exact string.
```
echo md5($argv[1],1)!='¯è a@ÛÚƒ:ïT�p'?:42;
```
The data is kind of hard to copy/paste since there is a null-byte in the middle of the code. Here's an hex-dump of the code for testing purposes.
> 
> 65 63 68 6f 20 6d 64 35 28 24 61 72 67 76 5b 31 5d 2c 31 29 21 3d 27 af e8 a0 61 40 db da 7f 11 0f 83 3a ef 54 00 70 27 3f 3a 34 32 3b 
> 
> 
> 
[Answer]
**Scala 79**
```
 if((for(i <- 1 to 26;j<-1 to i)yield(96+i).toChar).mkString==args(0))print(42)
```
[Answer]
# Pyth, 14
```
*42qzsm*dhxGdG
```
Just constructs the necessary string, then compares with the input and multiplies by 42.
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog) (2), 15 bytes, language postdates challenge
```
⊇Ạ∧?o?ọtᵐ~⟦₁+₁₆
```
[Try it online!](https://tio.run/nexus/brachylog2#@/@oq/3hrgWPOpbb59s/3N1b8nDrhLpH85c9amrUBuJHTW3//yslJiUlJyenAEEqCKSBQToEZEBBJgxkwUE2AuQggVxkkIcC8lFBARooRAdFGKAYE5RgAaXYQBlWUI4dVOAAlbhAFU6g9D8KAA "Brachylog – TIO Nexus")
And now for an answer which works on a completely different principle to most seen here. This is a function submission (the question doesn't specify what sort of submission is desired, but functions are permitted by default).
## Explanation
This answer works by defining a sort of string: those which a) contain all lowercase letters of the alphabet, b) are in sorted order, and c) for which taking the number of occurrences of each character in the string produces a sequence of consecutive integers starting from 1. (It should be clear that there are many such strings, but the one we want to special-case is the shortest.) Then if the string fulfils those criteria, we add 16 to the number of distinct characters in the string; this will produce 42 if the string is the one the question asks us to special-case, and at least 43 in all other cases. (If the string fails any of the criteria to belong to the category, the function will end in failure, which is kind-of like throwing an exception.)
Here's how to interpret the source code:
```
⊇Ạ∧?o?ọtᵐ~⟦₁+₁₆
⊇Ạ               {the input} contains all lowercase letters
  ∧              and
   ?o?           the input sorts to itself
                 {and; implied when two conditions overlap}
     ?ọ          the {character, number of occurrences} pairs for the input
       tᵐ        when the second element of each is taken
         ~       create an output that could have been produced by
          ⟦₁     outputting the list of integers from 1 to some input inclusive;
            +₁₆  add 16 to that input {and output it}
```
[Answer]
# R, ~~60~~ 58
~~```
if(readline()==paste0(rep(letters,1:26),collapse=""))cat(42)
```~~
```
if(scan(,"")==paste(rep(letters,1:26),collapse=""))cat(42)
```
Thanks for the suggestion by @giusppe
[Answer]
## Python (84)
Assumes a trailing newline at the end of the input.
```
import sys
if''.join(c*chr(c+96)for c in range(27))+'\n'==sys.stdin.read():print 42
```
[Answer]
## Python - 62 chars
```
print("".join(x*chr(x+96) for x in range(27))==raw_input())*42
```
[Answer]
## Perl, 49 46 characters
to be used in a program, not on the command line
`$..=chr($*+96)x$* for 1..26;$.eq(pop)&&print '42'`
```
join('',map$_ x++$x,'a'..'z')eq pop&&print'42'
```
Regards
rbo
Edit: Idea ripped from Ventero
[Answer]
**PHP  92 88 87 chars**
```
function _($a){for($i=97;$i<123;$i++)for($j=$i-96;$j;$j--)$b.=chr($i);echo($b==$a)*42;}
```
**EDIT**
Replaced `$j<0` with `$j` and `return $b==$a?42:0;` with `echo $b==$a?42:0;`
Replaced `echo $b==$a?42:0;` with `echo($b==$a)*42;`
[Answer]
**ECLiPSe Prolog - 173**
```
c(_,[],_):-!. c(A,M,N):-length(L,N),checklist('='(A),L),append(F,L,M),P is N-1,B is A-1,c(B,F,P). ?- read_string(end_of_file,351,S),string_list(S,L),c(122,L,26),writeln(42).
```
[Answer]
## JavaScript (91 93 94 98 102 116)
Usage: `a('string')`, returns `42` if valid according to spec, or `0`.
```
function a(z){for(i=r='';i++<26;)for(j=i;j--;)r+=String.fromCharCode(i+96);return(z==r)*42}
```
<http://jsfiddle.net/g25M3/6/>
**Edit**: Removed `var` and eliminated two spaces in `for (`.
**Edit 2**: Changed `j>0` to `j`, and 
1. `return (z==r)?42:0;` to
2. `return z==r?42:0`
**Edit 3**: Initialize `i` with `i=''`, change
1. `(z==r)?42:0` to
2. `(z==r)*42`
**Edit 4**: Change
1. `for(;i<27;i++)` to
2. `while(i++<26)`
**Edit 5**: Change
1. `i=r='';while(i++<26)` to
2. `for(i=r='';i++<26;)` and
3. `for(j=i;j;j--)` to
4. `for(j=i;j--;)`
[Answer]
## JavaScript 1.8, 99 chars
```
function c(x)(x.replace(/([a-z])\1*/g,function(m)!(a-m.length)*m.charCodeAt(0)-96-a++,a=1)==0)*a+15
```
I dare you to make sense of it :)
[Answer]
# PHP - 59
Assumes at least 1 input is provided over cli
```
echo md5($argv[1])!='afe8a06140dbda7f110f833aef540070'?:42;
```
It more or less works, except that md5 is can technically have duplications with the hashing algo.
[Answer]
## PowerShell v2+, 47 bytes
```
42*(-join(1..26|%{,[char]($_+96)*$_})-ceq$args)
```
Constructs a range `1..26`, feeds that through a loop with `|%{...}`. Each iteration we use the [comma operator](https://technet.microsoft.com/en-us/library/hh847732.aspx) to construct an array literal of the current `[char]` multiplied by the current loop number. We then `-join` that all together to construct the string `abbcccdddd...` and then use a case-sensitive `-ceq` comparison against our input `$args`, which will result in either `$TRUE` or `$FALSE`. In PowerShell, Boolean values can be implicitly cast as `1` or `0`, respectively, which is what happens here with the `42*`. Will print out `42` iff the input is `abbccc...zzzzzzzzzzzzzzzzzzzzzzzzzz` and will output `0` otherwise.
[Answer]
### K, 26 Bytes
```
{(::;42)x~,/(1+!26)#'.Q.a}
{(::;42)x~,/(1+!26)#'.Q.a}"hello"
{(::;42)x~,/(1+!26)#'.Q.a}"abbcccddddeeeeeffffffggggggghhhhhhhhiiiiiiiiijjjjjjjjjjkkkkkkkkkkkllllllllllllmmmmmmmmmmmmmnnnnnnnnnnnnnnoooooooooooooooppppppppppppppppqqqqqqqqqqqqqqqqqrrrrrrrrrrrrrrrrrrsssssssssssssssssssttttttttttttttttttttuuuuuuuuuuuuuuuuuuuuuvvvvvvvvvvvvvvvvvvvvvvwwwwwwwwwwwwwwwwwwwwwwwxxxxxxxxxxxxxxxxxxxxxxxxyyyyyyyyyyyyyyyyyyyyyyyyyzzzzzzzzzzzzzzzzzzzzzzzzzz"
42
```
Thanks
[Answer]
# VBA 91
There weren't any VBA answers but this works:
```
Function f(t)
    For i = 1 To 26
        o = o & String(i, Chr(i + 96))
    Next
    f = -42 * (t = o)
End Function
```
[Answer]
# [APL (Dyalog)](https://www.dyalog.com/), ~~18~~ 17 bytes
```
42/⍨⍞≡819⌶⎕A/⍨⍳26
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///qKPdMa@4PLXov4mR/qPeFY/6pj7qXGhhaPmoZxuQ7QgW691sZAZSyeWZV1Ba8qhtQvWjruZHPXtBitsmqINFrdQf9W6t/a8ABhAjIcrVPVJzcvLVubDIuBelppZk5qUXY5NVwOIIAA "APL (Dyalog Unicode) – Try It Online")
Four obvious bytes can be saved if we are allowed to use uppercase.
`42` 42
`/⍨` if (lit. replicated by)
`⍞` character input
`≡` is identical to
`819⌶` the lowercased
`⎕A` **A**lphabet
`/⍨` replicated by
`⍳` one through
`26` 26
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 7 bytes
```
AƶJQ42*
```
[Try it online!](https://tio.run/##dcHHFUAwAADQfZzwGMDVzQhJRO@dwYxgreik/q/bABqYEGdbXc8yNUIAhAgh/4BPwSW8RY/4lXzSX0bJaQWjZFWcmtcIWlEn0csMUqPcpDCrLEo7 "05AB1E – Try It Online")
---
Wellp, 05AB1E keeps evolving.
[Answer]
# **Clojure** - 61 chars
```
(fn[a](if(=(mapcat #(repeat%(char(+% 96)))(range 1 27))a)42))
```
Exploits the following facts:
* Clojure can interpret any string automatically as a sequence of chars
* I can use the range of numbers from 1 to 26 to both create the characters and repeat them the correct number or times to generate the "correct" input
[Answer]
## Javascript 144
Probably can be significantly improved, recursion has always been a head far for me.
**Compressed**
```
function r(a,b,d,c){c++;if(b<d)a+=r(a,b+1,d,c);for(i=0;i<c;i++)a=String.fromCharCode(b)+a;return a}function q(a){if(q==r(a,97,122,0))return 42};
```
**Less Compressed**
```
function r(s, c, x, w){        
    w++;
    if(c < x)
        s += r(s, c + 1, x, w);
    for(i = 0; i < w; i++)
        s = String.fromCharCode(c) + s;              
    return s;
}
function q(z){
    if(q==r(z,97, 122, 0))
        return 42;            
}
alert(q("rgrg"));
```
]