Person of Interest is a crime drama on CBS, and my favorite TV show, as of late.

The show is about a man named Harold Finch, a billionaire programmer, and his partner John Reese, a special forces veteran and ex-CIA operative. This programmer created a sentient AI called "The Machine" that predicts violent crimes before they happen. It tracks every person on Earth at all times by monitoring and analyzing all surveillance cameras and electronic communications across the globe.

Harold built The Machine for the United States government to detect terrorist activity before-the-fact. It divides the crimes that it predicts into lists based on whether or not they are relevant to national security. The relevant cases are handled by the government, while the "irrelevant" list is programmed to be deleted daily.

Harold made a small backdoor for himself in hopes to deal with the "irrelevant" list, himself. This backdoor causes The Machine to call the payphone nearest Harold (once every day or so) and read a Social Security number to him. This SSN belongs to someone whose life is in danger as part of a premeditated crime, or of someone who is planning such a crime.

The Challenge

Write a program that takes no input, and outputs 30 random phone numbers & SSNs (see below).


There are two lines of text that will be printed every "day".

  1. Crime predicted: 555-55-5555
  2. Calling: 1-555-555-5555 followed by a newline

This process should repeat for one "month" (30 "days").

Phone Numbers

Every phone number must have the following elements:

  • Must have the United States country code (the first digit).

  • Must have a random area code (first set of three digits).

  • The first three digits of the phone number itself should be 555, followed then by 4 random digits.

Here is an annotated example:

|  |   |   |
|  |   |   |
|  |   |   +---------->   random four digits
|  |   |
|  |   +-------------->   the set 555
|  |
|  +------------------>   area code
+--------------------->   country code

Social Security Numbers

Every SSN must be 9 random digits in the following format.



Crime predicted: 234-72-8311
Calling: 1-633-555-0188

Crime predicted: 135-77-0910
Calling: 1-202-555-4719

Crime predicted: 722-90-6653
Calling: 1-466-555-1069


Continuing for 27 more cycles.


For your score to appear on the board, it should be in this format:

# Language, Bytes

Strikethroughs shouldn't cause a problem.

function getURL(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function getAnswers(){$.ajax({url:getURL(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),useData(answers)}})}function getOwnerName(e){return e.owner.display_name}function useData(e){var s=[];e.forEach(function(e){var a=e.body.replace(/<s>.*<\/s>/,"").replace(/<strike>.*<\/strike>/,"");console.log(a),VALID_HEAD.test(a)&&s.push({user:getOwnerName(e),language:a.match(VALID_HEAD)[1],score:+a.match(VALID_HEAD)[2],link:e.share_link})}),s.sort(function(e,s){var a=e.score,r=s.score;return a-r}),s.forEach(function(e,s){var a=$("#score-template").html();a=a.replace("{{RANK}}",s+1+"").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SCORE}}",e.score),a=$(a),$("#scores").append(a)})}var QUESTION_ID=58199,ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",answers=[],answer_ids,answers_hash,answer_page=1;getAnswers();var VALID_HEAD=/<h\d>([^\n,]*)[, ]*(\d+).*<\/h\d>/;
body{text-align:left!important}table thead{font-weight:700}table td{padding:10px 0 0 30px}#scores-cont{padding:10px;width:600px}#scores tr td:first-of-type{padding-left:0}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"><div id="scores-cont"><h2>Scores</h2><table class="score-table"><thead> <tr><td></td><td>User</td><td>Language</td><td>Score</td></tr></thead> <tbody id="scores"></tbody></table></div><table style="display: none"> <tbody id="score-template"><tr><td>{{RANK}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SCORE}}</td></tr></tbody></table>

  • 3
    \$\begingroup\$ Also, what are the valid values for US country codes / area codes? \$\endgroup\$ – mınxomaτ Sep 18 '15 at 5:28
  • 2
    \$\begingroup\$ I've removed the time restriction. In regards to your second question, the US country code is explicitly a 1. As for area codes, any three digits will do, for the purposes of this challenge. @minxomat \$\endgroup\$ – Zach Gates Sep 18 '15 at 5:29
  • 1
    \$\begingroup\$ @LuisMendo there is a consensus on meta about what random means if not fully defined \$\endgroup\$ – FryAmTheEggman Sep 18 '15 at 12:52
  • 5
    \$\begingroup\$ Of course, generating the numbers in the format they're actually transmitted by The Machine in the show would be even more complicated... ;) \$\endgroup\$ – Mason Wheeler Sep 18 '15 at 14:40
  • 1
    \$\begingroup\$ Who ya gonna call? @DTI-Matt \$\endgroup\$ – Zach Gates Sep 18 '15 at 16:15

30 Answers 30


CJam, 68 66 64 bytes

Thanks to Dennis for saving 2 bytes!

"Crime predicted: --
Calling: 1--555-


Copypasting won't work since there are a few unprintables (one in place of each random group), so here's an xxd dump:

00000000: 2243 7269 6d65 2070 7265 6469 6374 6564  "Crime predicted
00000010: 3a20 032d 022d 040a 4361 6c6c 696e 673a  : .-.-..Calling:
00000020: 2031 2d03 2d35 3535 2d04 0a0a 2233 302a   1-.-555-..."30*
00000030: 7b5f 353c 7b69 4161 2a3a 6d72 7d26 7d2f  {_5<{iAa*:mr}&}/

To reverse it, paste it into a file and launch xxd -r in_file > out_file. You can also try it online.


"..."30*     Push the string 30 times
{ ... }/     For each character in the string:
_5<{ ... }&    If the ASCII code is < 5:
iAa*             Push an array of as many 10s as the ASCII code
:mr              For each 10, choose a random 0-9 number
  • \$\begingroup\$ I would've never thought of this myself, but it seems to be two bytes shorter in Pyth. \$\endgroup\$ – FryAmTheEggman Sep 18 '15 at 15:39
  • \$\begingroup\$ @FryAmTheEggman I should probably learn Pyth, it's often shorter than CJam. You can post that answer if you want :) \$\endgroup\$ – Andrea Biondo Sep 18 '15 at 15:41

Python 2, 129

from random import*
print''.join([c,`randint(0,9)`][c>'w']for c in'Crime predicted: xxx-xx-xxxx\nCalling: 1-xxx-555-xxxx\n\n'*30)

A naive method. Takes the message

Crime predicted: xxx-xx-xxxx
Calling: 1-xxx-555-xxxx

and copies it 30 times. Then, replaces each x with a random digit randint(0,9), keeping all other characters the same.


Python 2, 151 bytes

Thank the lord (and @Dennis) for %0nd :D

from random import randrange as r
for i in[1]*30:print"Crime predicted: %03d-%02d-%04d\nCalling: 1-%03d-555-%04d\n"%(r(1e3),r(100),r(1e4),r(1e3),r(1e4))

Perl, 85 Bytes, thanks to Dennis and grc!

$_="Crime Predicted: NNN-NN-NNNN 
Calling: 1-NNN-555-NNNN 

"x30;s/N/0|rand 10/eg;print

Original Perl, 91 92 Bytes

print"Crime Predicted: NNN-NN-NNNN
Calling: 1-NNN-555-NNNN

"=~s/N/int rand 10/egr for 1..30
  • 1
    \$\begingroup\$ @Dennis aw, I was about to post that until I saw this answer. I had $_="..."x30;s/_/0|rand 10/eg;print which saves the /r flag. \$\endgroup\$ – grc Sep 18 '15 at 14:50
  • \$\begingroup\$ Thanks @Dennis and @grc! Is it customary to incorporate changes suggested in comments (with attribution of course)? If not I'll revert my edit. But, in any case, thanks! I'd totally forgotten about the 0|rand ... trick and the repetition operator I'm now using to repetitiously slap my head for missing that! \$\endgroup\$ – type_outcast Sep 18 '15 at 15:00
  • 2
    \$\begingroup\$ Yes, it's customary. If you haven't already, you should check out Tips for golfing in Perl?. It's a great resource. \$\endgroup\$ – Dennis Sep 18 '15 at 15:20

CJam, 73 71 70 bytes

30{"Crime predicted: x-x-x
Calling: 1-x-555-x

Try it online in the CJam interpreter.

How it works

30{     e# Repeat 30 times:

e# Push the following string:

"Crime predicted: x-x-x
Calling: 1-x-555-x

'x/     e# Split at x's.
[ZY4Z4] e# Push the array [3 2 4 3 4].
Aaf*    e# For each integer in that array, repeat [10] that many times.
        e# This pushes [[10 10 10][10 10][10 10 10 10][10 10 10][10 10 10 10]].
::mr    e# For each 10, select a random integer between 0 and 9 (inclusive).
.+      e# Vectorized concatenation.
        e# This places the digits at the spots of the x's.
N       e# Push a linefeed.
}*      e#

ß, 121 118 112 bytes

°/N=1°(30°/M°=ß$-ß$$'Crime predicted: 000-00-0000\nCalling: 1-000-555-0000\n\n'),'',3)µ€(M='0')?ß!G0,9,1):M)°)°)

Basically replaces 0 with a random number each and calls itself 30 times.

Test it using the online terminal:

sharps:~$ "<ctrl+v the code here>"                       
Crime predicted: 214-59-4707                              
Calling: 1-850-555-8529                                   

Crime predicted: 722-97-6832                              
Calling: 1-864-555-6965                                   

<and so on...>

Edit (112B): Using $$ (something like sprintf) & ternary operator.

  • \$\begingroup\$ Could you provide a link to this language's spec? \$\endgroup\$ – LegionMammal978 Sep 19 '15 at 14:11
  • \$\begingroup\$ @LegionMammal978 Takes some time to write. In simple terms: Has every feature AutoIt has. \$\endgroup\$ – mınxomaτ Sep 19 '15 at 18:23

Pyth, 66

V30sX"Crime Predicted: v-w-x
Calling: 1-y-555-z

Uses X to translate the last 5 letters of the alphabet (>5G == 'vwxyz') onto the 5 random numbers. Uses the same RNG as Sok found.

Try it online here


Pyth, 62

An implementation of Andrea's fantastic CJam answer.

sm?<Cd5jkmOTCdd*30"Crime Predicted: --
Calling: 1--555-


Note that there are several unprintable characters in the source, and there should not be a trailing ". That was added for SE so that it seems a bit more readable. I have not been able to get a hexdump yet, but the link below works and you should be able to copy-paste out of it.

Try it online here


CJam, 74 bytes

30{[ZY4Z4]{Aa*:mrs}%"Crime predicted: %s-%s-%s
Calling: 1-%s-555-%s


Not a winner, but it's at least somewhat close to what Dennis has so far, and it's using a different approach. So I thought it was worth posting anyway.

This uses the CJam e% operator, which generates output with a printf style format string.

30      Repeat count for whole output.
{       Start loop.
  [ZY4Z4] Build list of random number lengths: [3 2 4 3 4].
  {       Start loop over all random number lengths.
    Aa*     Build list of [10 ... ] with the random number length.
            E.g. for length 3, this will be [10 10 10].
    :mr     Apply the random number operator to the list. This will generate
            a list of random numbers between 0 and 9, with the given length.
    s       Convert it to a string.
  }%      End of loop over random number lengths.
  "..."   Format string, with a %s for each random number.
  e%      Apply printf style formatting.
}*      End of main repeat loop.
  • \$\begingroup\$ Woah, I thought you were @DavidCarraher with that avatar! \$\endgroup\$ – Beta Decay Sep 18 '15 at 6:27
  • \$\begingroup\$ @BetaDecay This? codegolf.stackexchange.com/users/3967/david-carraher. Not even the same animal! :) The colors are almost the same, though. \$\endgroup\$ – Reto Koradi Sep 18 '15 at 6:31
  • \$\begingroup\$ If we combine our approaches, we can get to 70 bytes: permalink \$\endgroup\$ – Dennis Sep 18 '15 at 6:31
  • \$\begingroup\$ @Dennis Feel free to go for it. You have helped me plenty of times. \$\endgroup\$ – Reto Koradi Sep 18 '15 at 6:34
  • \$\begingroup\$ @RetoKoradi Close enough ;) \$\endgroup\$ – Beta Decay Sep 18 '15 at 6:34

Matlab / Octave, 108 172 bytes

disp(sprintf('Crime predicted: %i%i%i-%i%i-%i%i%i%i\nCalling: 1-%i%i%i-555-%i%i%i%i\n\n',randi(10,1,480)-1))

Try it online


JavaScript (ES6), 142

Side note mixmat answer in ß shows a so better way to accomplish this task, and could easily implemented in JS giving a better score. I wish I had thought about it.

Edit Added the missing text (I misread the challenge)

Test running the snippet below in an EcmaScript 6 compliant browser

/* TEST redirect console.log */ console.log=x=>O.innerHTML+=x+'\n'

for(i=30;i--;)console.log(`Crime predicted: ${(R=d=>(1e-9+Math.random()+'').substr(2,d))(3)}-${R(2)}-${R(4)}
Calling: 1-${R(3)}-555-${R(4)}
<pre id=O></pre>

  • \$\begingroup\$ Very nice solution! However, the last part of the phone number occasionally has less than 4 digits; same with the second and third parts of the SSN. \$\endgroup\$ – ETHproductions Sep 18 '15 at 16:18
  • \$\begingroup\$ @ETHproductions rats! Reverting to previous version! \$\endgroup\$ – edc65 Sep 18 '15 at 17:11

Fourier, 166 142 bytes


This has one of the highest byte counts, but I am a huge fan of Fourier and wanted to try my hand at a solution. Not very optimized.

Breaking it down:


Sets the variable d to 45, the ASCII code for a hyphen. This character is printed so much that it saves some bytes to declare it here.


Sets the accumulator to zero and loops inside the parentheses until it reaches 30.


Print "Crime predicted: ".


Print a completely random SSN + newline.


Print "Calling: ".


Print a phone number that follows the guidelines: 1-xxx-555-xxxx


Print two newlines to start over.


Pyth, 67 bytes

V30s.ic"Crime predicted: |-|-|
Calling: 1-|-555-|

The newlines are important, and are included in byte count. Try it out here.

                                Implicit: T=10, k=''
       "..."                    The output string
      c     \|                  Split on '|' placeholders
                     j32434T    32434 to base ten -> [3,2,4,3,4]
              m                 Map for d in the above:
                 mOTd             Generate d random numbers from 0-9
               jk                 Concatenate into string (join on empty string)
    .i                          Interleave segments of output string with random strings
   s                            Concatenate and output
V30                             Perform the above 30 times

Haskell, 150 bytes

import System.Random
p '#'=putChar=<<randomRIO('0','9')
p x=putChar x
main=mapM p$[1..30]>>"Crime predicted: ###-##-####\nCalling: 1-###-555-####\n\n"

JavaScript (ES6), 130 123 bytes

Taking minxomat's ß solution a step further, I've replaced the 0s with the number of 0s that would have been there. The code uses those numbers to pull the correct number of digits off of Math.random(), saving a good bit of bytes in the process.

for(i=30;i--;)console.log(`Crime predicted: 3-2-4
Calling: 1-3-555-4

Try it out:

// redirecting console.log() for this demonstration

for(i=30;i--;)console.log(`Crime predicted: 3-2-4
Calling: 1-3-555-4
<pre id=O>

As always, suggestions welcome!


Java, 246 bytes

import java.util.*;class C{static{Random r=new Random();for(int i=0;i++<30;)System.out.printf("Crime predicted: %s-%s-%s\nCalling: 1-%s-555-%s\n\n",r.nextInt(900)+100,r.nextInt(90)+10,r.nextInt(900)+100,r.nextInt(900)+100,r.nextInt(9000)+1000);}}

With line breaks:

import java.util.*;
class C{
       Random r = new Random();
       for(int i = 0; i++<30;)
           System.out.printf("Crime predicted: %s-%s-%s\nCalling: 1-%s-555-%s\n\n",r.nextInt(900)+100,r.nextInt(90)+10,r.nextInt(900)+100,r.nextInt(900)+100,r.nextInt(9000)+1000);

It's a start. Instead of producing random digits I used random 3-digit or 4-digit numbers.


R, 151 146 or 144 Bytes


for(l in 1:30)cat(sep="","Crime predicted: ",(i=floor(runif(16,,10)))[1:3],"-",i[4:5],"-",i[6:9],"\nCalling: 1-",i[10:12],"-555-",i[13:16],"\n\n")

Test it online.


for(l in 1:30) {
  cat(sep="","Crime predicted: ",
      "\nCalling: 1-",i[10:12],"-555-",

I think there is a lot of room to improve but I am no good messing with strings in R.

Edit 1: changed the runif(16,max=10) to runif(16,,10).

I've done another code (147 144 bytes) with sprintf but I don't think it is much a R-like code.

for(l in 1:30)cat(do.call(sprintf,as.list(c('Crime predicted: %s%s%s-%s%s-%s%s%s%s\nCalling: 1-%s%s%s-555-%s%s%s%s\n\n',floor(runif(16,,10))))))

Another approach (149 bytes):

for(p in 1:30)cat(sep="",replace(s<-strsplit("Crime predicted: '''-''-''''\nCalling: 1-'''-555-''''\n\n","")[[1]],which(s<"-"),floor(runif(16,,10))))

PHP, 144 143 Bytes

<?=preg_replace_callback('/x/',function($x){return chr(rand(48,57));},str_repeat("Crime predicted: xxx-xx-xxxx
Calling: 1-xxx-555-xxxx


GolfScript, 91 bytes

{9rand}+:r;{"Crime Predicted: "{r}3*"-"{r}2*"-"{r}4*"
Calling: 1-"{r}3*"-555-"{r}4*"


Try it online.


C#, 280 263 246 bytes


using System;class C{static string G(){var r=new Random();var s="";n h=x=>r.Next(x).ToString("D"+x);for(int i=0;i++<30;){s+="Crime predicted: "+h(3)+"-"+h(2)+"-"+h(4)+"\nCalling: 1-"+h(3)+"-555-"+h(4)+"\n\n";}return s;}delegate string n(int x);}


using System;
class C
    static string G()
        Random r = new Random();
        string s = "";
        Func<int, string> f = x => r.Next((int)Math.Pow(10, x)).ToString("D" + x);            

        for (int i = 0; i++ < 30;)
            s += "Crime predicted: " + f(3) + "-" + f(2) + "-" + f(4) + "\nCalling: 1-" + f(3) + "-555-" + f(4) + "\n\n";
        return s;

New on Codegolf, tips are welcome!

  • \$\begingroup\$ Welcome to Programming Puzzles & Code Golf! I'm not intimately familiar with C#, but since it's predicated on .NET like PowerShell is, I think the h(999) will generate a number from 000 to 998 inclusive, so that means this doesn't quite hit the spirit of the specifications. I ran into the same issue. \$\endgroup\$ – AdmBorkBork Sep 21 '15 at 19:10
  • \$\begingroup\$ You're right, I'll fix it now! \$\endgroup\$ – anthonytimmers Sep 21 '15 at 19:33
  • \$\begingroup\$ Went up to 280 bytes after the fix, then thought of doing the formatting in the delegate handler, reducing it back to 263 bytes. \$\endgroup\$ – anthonytimmers Sep 21 '15 at 19:50

Hassium, 230 Bytes

func main(){foreach(x in range(1,31){println("Crime predicted: "+r(3)+"-"+r(2)+"-"+r(4));println("Calling: 1-"+r(3)+"-555-"+r(4)+"\n");}}
func r(l){z=new Random();a="";foreach(y in range(1,l))a+=z.next(0,10).toString();return a;}


func main () {
        foreach (x in range(1, 31) {
                println("Crime predicted: " + r(3) + "-" + r(2) + "-" + r(4));
                println("Calling: 1-" + r(3) + "-555-" + r(4) + "\n");
func r (l) {
        z = new Random();
        a = "";
        foreach (y in range(1, l))
                a += z.next(0, 10).toString();
        return a;

Ruby, 98 characters

30.times{puts"Crime Predicted: DEF-GH-IJKL
Calling: 1-MNO-555-QRST


Sample run:

bash-4.3$ ruby -e '30.times{puts"Crime Predicted: DEF-GH-IJKL\nCalling: 1-MNO-555-QRST\n\n".tr"D-OQ-T",rand.to_s[2..-1]}' | head
Crime Predicted: 867-29-2637
Calling: 1-278-555-5424

Crime Predicted: 913-31-6306
Calling: 1-744-555-8188

Crime Predicted: 868-36-4612
Calling: 1-926-555-3576

Crime Predicted: 988-06-1643

JavaScript, 146 141

console.log(Array(30).join("Crime predicted: 3-2-3\nCalling: 1-3-555-4\n\n").replace(/[2-4]/g,function(m){return(m+Math.random()).substr(3,m)}))
  • \$\begingroup\$ there is already answer in same language with less characters than yours. \$\endgroup\$ – Jakuje Sep 18 '15 at 18:46
  • \$\begingroup\$ @Jakuje the other answer uses ES6 which isn't widely available yet \$\endgroup\$ – Peleg Sep 18 '15 at 18:47
  • \$\begingroup\$ Then it is probably ok. Mentioning this in your answer would be good. \$\endgroup\$ – Jakuje Sep 18 '15 at 18:49
  • 1
    \$\begingroup\$ @Jakuje People can submit whatever they want! It's as much about the challenge as it is about beating others. \$\endgroup\$ – ErikE Sep 18 '15 at 22:54

pre-ES6 Javascript, 128

for(i=30;i--;)console.log('Crime predicted: x-x-x\nCalling: x-555-x\n'.replace(/x/g, function(){return 1e3*Math.random()|0}))

I feel like the dashes could be removed somehow, but not sure.

  • 1
    \$\begingroup\$ Several errors:1) random parts are not of correct length (and not even trying to) 2) missing "1-". \$\endgroup\$ – edc65 Sep 21 '15 at 0:01

Pyth, 73 bytes

V30FGPc"Crime predicted: xxx-xx-xxxx\nCalling: 1-xxx-555-xxxx"\xpGpOT)pb"



Julia, 120 bytes

for i=1:30 println("Crime Predicted: "R(3)"-"R(2)"-"R(4)"\nCalling: 1-"R(3)"-555-"R(4))end


# Define a function for returning a random number with a
# specified number of digits
function R(n::Int)
    lpad(rand(0:10^n-1), n, 0)

# Print 30 times
for i = 1:30
    println("Crime Predicted: " R(3) "-" R(2) "-" R(4)
            "\nCalling: 1-" R(3) "-555-" R(4))

Ruby, 90 88 bytes

30.times{puts"Crime predicted: NNN-NN-NNNN
Calling: 1-NNN-555-NNNN

".gsub(?N){rand 10}}

Try it online.

  • 1
    \$\begingroup\$ No need for string notation, just character ?N is enough. No need for parenthesis, around rand's parameter. \$\endgroup\$ – manatwork Sep 21 '15 at 9:00

PowerShell, 120 108 103 102 Bytes

0..29|%{("Crime predicted: XXX-XX-XXXX`nCalling: 1-XXX-555-XXX"-split"X"|%{$_+(Random 10)})-join'';""}

Shortened a few more bytes by setting the split-loop to instead be a code block that outputs to an array @(..) and is re-joined.

Eliminated the @ by remembering that (...) designates a code block executed before the -join'' anyway.

This eliminates needing to assign the $a variable. Also noticed that due to how the -split functionality works, the previous code was spitting out too many digits for the phone number, so got a free byte saving there by shrinking to 1-XXX-555-XXX. That made up for the erroneous Random 9 that actually picks random from 0-8, so we instead need to specify Random 10.

Sooo dang close to double-digits, but I'm not sure where it's possible to golf off another four 3 bytes ...

Previous, 108

0..29|%{$a="";"Crime predicted: XXX-XX-XXXX`nCalling: 1-XXX-555-XXXX"-split"x"|%{$a+="$_$(Random 9)"};$a;""}

Shortened the code a couple bytes by instead splitting a string on X's, then re-looping through the resultant array of strings and concatenating each entry with a Random digit to build our final output string $a. Note that we couldn't do something like "string".replace("x",$(Random 9)) because then the Random would only get called once, so you'd have 1-222-555-2222 for a phone number, for example.

Previous-er, 120

0..29|%{"Crime predicted: "+(Random 1e9).ToString("000-00-0000");"Calling: "+(Random 1e7).ToString("1-000-555-0000");""}

Pretty dang competitive for a verbose language, thanks to generous output specifications (i.e., 000-00-0001 is treated as a valid SSN) and the really robust .ToString() formatting algorithm that PowerShell uses. PowerShell also outputs \r\n after every string output, so the requirement for a newline in between iterations is just a simple "".

Note that this uses an implied Get- in front of Random, so this may be really slow on some platforms/implementations.


Befunge-98, 170

I think this can still be golfed down a bit. But at least I beat C#. Tested at befungius.aurlien.net.

a3*>  82*v>":detciderp emirC">:#,_$...'-,..'-,....av
>1 -:!#;_v^;v,,,"-555-"...,,,,,,,,,,,"Calling: 1-",<
\  ^v< <2?1v,
+    ^;^3<;<,
^ <0?3vv....<

Python 2, 151 150 bytes

from random import*
p="Crime predicted: xxx-xx-xxxx\nCalling: 1-xxx-555-xxxx\n\n"*30
while'x'in p:p=p.replace('x',str(randint(0,9)),1)
print p.strip()

As golfed as I could get this method.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.