| Bytes | Lang | Time | Link |
|---|---|---|---|
| 061 | Zsh | 250109T102842Z | roblogic |
| 070 | Wolfram Language Mathematica | 250109T164340Z | Introduc |
| 149 | Python 2 | 151114T203801Z | The Fift |
| 020 | Perl 6 | 130930T181154Z | Demayl |
| 091 | Python 2 | 151115T065224Z | feersum |
| 036 | PHP 38 37 | 130925T085637Z | lortabac |
| 076 | JavaScript | 130925T214742Z | Math chi |
| 072 | Befunge | 131004T194905Z | FireFly |
| 101 | Haskell | 131004T181502Z | Olathe |
| 033 | Ruby | 130923T212923Z | Doorknob |
| 034 | APLDyalog | 130926T024503Z | TwiN |
| 056 | Javascript 57 | 130924T150659Z | Briguy37 |
| 019 | Perl | 130923T214631Z | Ilmari K |
| 073 | Javascript | 130925T074412Z | C5H8NNaO |
| 040 | Ruby | 130924T010754Z | ap. |
| 040 | In Ruby | 130923T230629Z | Cary Swo |
| 024 | Perl | 130923T192036Z | breadbox |
| 041 | Golfscript | 130923T225357Z | aaaaaaaa |
Zsh, 80 75 61 bytes
(repeat 8 x=$x{a..z}&&eval echo $x|rs 0 1)|head -129052722140
Try it online!
75 bytes
80 bytes
TIO prints up to ~arjh then it times out. Here's a proof of concept that prints up to abc exactly.
Wolfram Language (Mathematica), 70 bytes
Flatten[StringJoin/@Tuples[Alphabet[],#]&/@Range[8]][[;;129052722140]]
Generates all 1 to 8 character combinations and stopping it at the 129052722140 item in the list (where "password" is).
Try it online! for 2 character combinations stopping at "ac"
Python 2 - 153 152 151 149 bytes
from itertools import*;R=range
for l in iter(chain(*[product(*((map(chr,R(65,91)),)*n))for n in R(1,9)]).next,tuple("passwore")):print ''.join(l)
Saved one byte by using UPPERCASE and one by using newlines instead of spaces.
Perl 6, 20 chars
say "a".../password/
You don't need other things
Python 2, 91
b=lambda n:n*' 'and b(n/26-(n%26<1))+chr(~-n%26+97)
i=0
exec"i+=1;print b(i);"*129052722140
PHP 38 37 36 characters
<?for($w=a;$w<passwore;)echo$w++,~ß;
You have to set the encoding to ISO 8859-1 and disable warnings.
JavaScript 80 76
for(i=s=0;s!="password";i++){s=i.toString(36).replace(/[0-9]/,'');console.log(s)}
fiddle - stops at "pa".
however this does repeat things.
Befunge (72)
<_v#:/*2+67\+++88*99%*2+76:
^ >$>:#,_84*+,1+:0\:" Lr$W~"67++**1+***6+`#@_
Prints strings 'a' to 'password' separated by spaces, then exits.
Below is a version that prints only the first 9*9 = 81 words ('a' to 'dd'), for comparison. The 99* is the number of iterations to perform.
<_v#:/*2+67\+++88*99%*2+76:
^ >$>:#,_84*+,1+:0\:99*`#@_
Haskell, 101
main=putStrLn.concat.takeWhile(/="passwore ").tail.concat.iterate(\k->[x:y|x<-['a'..'z'],y<-k])$[" "]
Ruby, 33 chars (optimal but longer version)
?a.upto('password'){|c|$><<c+' '}
I like the 'a'.upto('password'); it tells you exactly what it's doing. Ruby is great and expressive like that. :D
Of course, print c,' ' would also be much clearer, but using $> is two characters shorter.
Ruby, 29 25 chars (slow version)
$><<[*?a..'password']*' '
This one's shorter, but it prints all of the tokens at once, so it takes a long, long time to run!
APL(Dyalog), 46 34
{∇{'PASSWORD '≡⍞←⍵:→⋄⍵}¨⎕A∘.,⍵}' '
Theoretically, it would print until PASSWORD, but I encountered a work space full error after ZZZZ: 5-dimensional array is just too awesome.
EDIT: Must have been too long since I last fiddled with APL. How dare I missed the identity comparision (≡)!!!
Explanation
{...}: Declares a function which...
⎕A∘.,⍵: Takes the outer product over concatenation (Every combination of an element of the left operand concatenated with an element of the right operand, just like Cartesian Product) between the 26 uppercase alpha (⎕A) and the argument (⍵)
{...}¨: And for each element of the resulting set, plug that into a function which...
⍞←⍵: prints it out
'PASSWORD '≡ and compare it with 'PASSWORD '
→: If the comparison returns true (1), then abort the program.
⍵: Else just return the printed string.
∇: Finally, the outer function recurse itself.
(Then you are taking outer product over concat between the 26 alpha and the 26 alpha, which gives all the 2-letter combinations, and then outer product over concat between the 2-letter combinations and the 26 alpha, etc... Until you reach PASSWORD which triggers the abort)
' ': The spark!! That kick-start the recursive function with the space character.
Javascript: 57 56 characters (thanks C5H8NNaO4)
Here's a solution that includes numbers as possible characters ("0", "1", "2", .., "passwor9", "passwora", "passworb", "passworc", "password")
for(i=-1;i++<1982613533017;console.log(i.toString(36)));
Here's a fiddle for testing (with only the last 100 iterations so it doesn't lock up your browser).
Perl, 19 chars
say for a..password
Uses newlines as delimiters, per clarification above. Run with perl -M5.010 (or just perl -E 'say for a..password') to enable the Perl 5.10+ say feature. Per meta, this doesn't count as extra chars.
(If you insist on spaces as delimiters, $,=$";say a..password is only two chars longer. However, it's also very slow and wasteful of memory, to the point of being unusable in practice, since it tries to build the entire list in memory before printing it.)
Javascript, 73
Here is a 73 character version of @Briguys' code, which prints only letter combinations
for(i=s=0;1982613533018>i++;s=i.toString(36))/\d/.test(s)||console.log(s)
Ruby (40 characters)
Interpret a string of a-z letters as a number in base 26, with a = 1, b = 2, ..., z = 26.
So "password" can be thought of as the number N =
16*(26**7) +
1*(26**6) +
19*(26**5) +
19*(26**4) +
23*(26**3) +
15*(26**2) +
18*(26**1) +
4*(26**0)
If we let s = "a" (that is: 1) and we make (N-1) calls to s.succ!, s will be "password" (N). In other words, N = 1 + (N-1).
For an example that will run more quickly, to prove the calculation of N is correct, consider "pass" as the target, where N is
16*(26**3) +
1*(26**2) +
19*(26**1) +
19*(26**0)
and
s = "a"
(N-1).times { s.succ! }
puts s #== "pass"
Since we want to print "a" too, we need
s = "`"
N.times { print(s.succ! + " ") }
So back to the full "password". N = 129052722140, leaving:
s=?`;0x1e0c2443dc.times{$><<s.succ!+" "}
I hunted for a more compact form of 129052722140 == 0x1e0c2443db but couldn't find one.
(Updated to fix the lack of printing "a", thanks to Cary.)
In Ruby, 39 40.
a=&`
0x1e0c2443dc.times{$><<a.succ!+' '}
..or 129052722140. (Edit: formerly I had 129052722. I had lost some digits cutting and pasting. Previous hex (0x7B13032) was for incorrect number.). Borrowed a=?` from @Doorknob to saves a character.
Perl, 33 32 24 characters
A solution in 32 characters:
$_=a;print$_++,$"until/passwore/
Not much to say about this one. I could reduce this to 27 characters if I could use newlines instead of spaces to separate the entries.
Ilmari Karonen points out that .. internally calls ++, so a better solution (25 characters) would be:
print$_,$"for a..password
By taking advantage of Perl's command-line options, here's an equivalent 24-character solution:
perl -l40e 'print for a..password'
The rules for counting perl flags is here, for those who aren't familiar with them.
Of course, Ilmari's 21-character solution is shorter still, but it requires a machine that can allocate an array of 129,052,722,140 strings.
Golfscript 41
For lack of 'z'+1 == 'aa' logic Golfscript can't win this one.
168036262484,(;{27base{96+}%' '+.96?0<*}%
168036262484,create array from 0 to 168036262483(;drop the 0{..}%iterate over array27baseconvert element to base 27 array{96+}%add 96 to each digit' '+convert to string and add a space to the end.96?0<*truncate string to zero if it contains char 96