Person of Interest

27

4

Background

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).


Output

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:

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

Social Security Numbers

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

342-98-1613

Example

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.


Scoreboard

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>

Zach Gates

Posted 2015-09-18T05:02:30.010

Reputation: 6 152

How the task is written now, the time delay is obsolete for the output or algorithm to be valid. If anything, it disqualifies a lot of languages... – mınxomaτ – 2015-09-18T05:26:10.717

3Also, what are the valid values for US country codes / area codes? – mınxomaτ – 2015-09-18T05:28:01.500

2I'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 – Zach Gates – 2015-09-18T05:29:42.173

The Output section confuses me little. I've interpreted it as *There are three lines of text [...] 1. [...] 2. [...] followed by a blank line.* Is that correct? – Dennis – 2015-09-18T05:47:35.300

Perhaps you should define "random" more carefully

– Luis Mendo – 2015-09-18T12:21:05.933

1

@LuisMendo there is a consensus on meta about what random means if not fully defined

– FryAmTheEggman – 2015-09-18T12:52:20.373

5Of course, generating the numbers in the format they're actually transmitted by The Machine in the show would be even more complicated... ;) – Mason Wheeler – 2015-09-18T14:40:30.017

"In fact, only 555-0100 through 555-0199 are now specifically reserved for fictional use; the other numbers have been reserved for actual assignment" – DTI-Matt – 2015-09-18T16:00:23.347

1Who ya gonna call? @DTI-Matt – Zach Gates – 2015-09-18T16:15:10.360

Answers

10

CJam, 68 66 64 bytes

Thanks to Dennis for saving 2 bytes!

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

"30*{_5<{iAa*:mr}&}/

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.

Explanation

"..."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

Andrea Biondo

Posted 2015-09-18T05:02:30.010

Reputation: 1 452

I would've never thought of this myself, but it seems to be two bytes shorter in Pyth.

– FryAmTheEggman – 2015-09-18T15:39:18.903

@FryAmTheEggman I should probably learn Pyth, it's often shorter than CJam. You can post that answer if you want :) – Andrea Biondo – 2015-09-18T15:41:49.557

8

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.

xnor

Posted 2015-09-18T05:02:30.010

Reputation: 115 687

6

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))

Beta Decay

Posted 2015-09-18T05:02:30.010

Reputation: 21 478

6

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

type_outcast

Posted 2015-09-18T05:02:30.010

Reputation: 511

1@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. – grc – 2015-09-18T14:50:53.347

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! – type_outcast – 2015-09-18T15:00:53.743

2

Yes, it's customary. If you haven't already, you should check out Tips for golfing in Perl?. It's a great resource.

– Dennis – 2015-09-18T15:20:11.053

5

CJam, 73 71 70 bytes

30{"Crime predicted: x-x-x
Calling: 1-x-555-x
"'x/[ZY4Z4]Aaf*::mr.+N}*

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#

Dennis

Posted 2015-09-18T05:02:30.010

Reputation: 196 637

5

ß, 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.

mınxomaτ

Posted 2015-09-18T05:02:30.010

Reputation: 7 398

Could you provide a link to this language's spec? – LegionMammal978 – 2015-09-19T14:11:07.137

@LegionMammal978 Takes some time to write. In simple terms: Has every feature AutoIt has. – mınxomaτ – 2015-09-19T18:23:22.550

4

Pyth, 66

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

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

FryAmTheEggman

Posted 2015-09-18T05:02:30.010

Reputation: 16 206

4

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

FryAmTheEggman

Posted 2015-09-18T05:02:30.010

Reputation: 16 206

3

CJam, 74 bytes

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

"e%}*

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.

Reto Koradi

Posted 2015-09-18T05:02:30.010

Reputation: 4 870

Woah, I thought you were @DavidCarraher with that avatar! – Beta Decay – 2015-09-18T06:27:21.163

@BetaDecay This? http://codegolf.stackexchange.com/users/3967/david-carraher. Not even the same animal! :) The colors are almost the same, though.

– Reto Koradi – 2015-09-18T06:31:12.100

If we combine our approaches, we can get to 70 bytes: permalink

– Dennis – 2015-09-18T06:31:17.720

@Dennis Feel free to go for it. You have helped me plenty of times. – Reto Koradi – 2015-09-18T06:34:12.810

@RetoKoradi Close enough ;) – Beta Decay – 2015-09-18T06:34:41.707

3

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>

edc65

Posted 2015-09-18T05:02:30.010

Reputation: 31 086

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. – ETHproductions – 2015-09-18T16:18:55.673

@ETHproductions rats! Reverting to previous version! – edc65 – 2015-09-18T17:11:44.543

3

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

Luis Mendo

Posted 2015-09-18T05:02:30.010

Reputation: 87 464

3

Fourier, 166 142 bytes

45~d030(~i67a114a-9a+4a-8a32a112a^^a101ava+5a-6a116a101ava58a32a999roda99roda9999ro10a67a97a108aa-3a+5a-7a58a32a1oda999roda5oooda9999ro10aai^)

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:

45~d

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.

030(...)

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

67a114a-9a+4a-8a32a112a^^a101ava+5a-6a116a101ava58a32a

Print "Crime predicted: ".

999roda99roda9999ro10a

Print a completely random SSN + newline.

67a97a108aa-3a+5a-7a58a32a

Print "Calling: ".

1oda999roda5oooda9999ro

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

10aa

Print two newlines to start over.

jqblz

Posted 2015-09-18T05:02:30.010

Reputation: 2 062

1

Hey, you might be interested that there's now an online interpreter at http://fourier.tryitonline.net (and also https://labs.turbo.run/beta/fourier)

– Beta Decay – 2016-08-10T21:29:39.987

2

Pyth, 67 bytes

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

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

Sok

Posted 2015-09-18T05:02:30.010

Reputation: 5 592

2

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"

Lynn

Posted 2015-09-18T05:02:30.010

Reputation: 55 648

2

R, 151 146 or 144 Bytes

Code

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.

Ungolfed

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

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))))

Mutador

Posted 2015-09-18T05:02:30.010

Reputation: 1 361

2

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{
    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);
    }
}

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

TNT

Posted 2015-09-18T05:02:30.010

Reputation: 2 442

2

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
`.replace(/[2-4]/g,x=>`${Math.random()}`.substr(2,x)))

Try it out:

// redirecting console.log() for this demonstration
console.log=x=>O.innerHTML+=x+'\n';
O.innerHTML='';

for(i=30;i--;)console.log(`Crime predicted: 3-2-4
Calling: 1-3-555-4
`.replace(/[2-4]/g,x=>`${Math.random()}`.substr(2,x)))
<pre id=O>

As always, suggestions welcome!

ETHproductions

Posted 2015-09-18T05:02:30.010

Reputation: 47 880

2

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

",30));

Lern2Golf

Posted 2015-09-18T05:02:30.010

Reputation: 21

2

GolfScript, 91 bytes

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

"}30*

Try it online.

user45178

Posted 2015-09-18T05:02:30.010

Reputation:

2

C#, 280 263 246 bytes

Golfed:

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);}

Indented:

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!

anthonytimmers

Posted 2015-09-18T05:02:30.010

Reputation: 131

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.

– AdmBorkBork – 2015-09-21T19:10:07.047

You're right, I'll fix it now! – anthonytimmers – 2015-09-21T19:33:23.470

Went up to 280 bytes after the fix, then thought of doing the formatting in the delegate handler, reducing it back to 263 bytes. – anthonytimmers – 2015-09-21T19:50:56.667

1

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;}

Expanded:

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;
}

Jacob Misirian

Posted 2015-09-18T05:02:30.010

Reputation: 737

1

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.

AdmBorkBork

Posted 2015-09-18T05:02:30.010

Reputation: 41 581

1

Ruby, 98 characters

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

".tr"D-OQ-T",rand.to_s[2..-1]}

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

manatwork

Posted 2015-09-18T05:02:30.010

Reputation: 17 865

1

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)}))

Peleg

Posted 2015-09-18T05:02:30.010

Reputation: 121

there is already answer in same language with less characters than yours. – Jakuje – 2015-09-18T18:46:11.733

@Jakuje the other answer uses ES6 which isn't widely available yet – Peleg – 2015-09-18T18:47:28.500

Then it is probably ok. Mentioning this in your answer would be good. – Jakuje – 2015-09-18T18:49:11.627

1@Jakuje People can submit whatever they want! It's as much about the challenge as it is about beating others. – ErikE – 2015-09-18T22:54:20.590

1

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.

user70585

Posted 2015-09-18T05:02:30.010

Reputation: 181

1Several errors:1) random parts are not of correct length (and not even trying to) 2) missing "1-". – edc65 – 2015-09-21T00:01:46.373

1

Pyth, 73 bytes

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

Demo

clap

Posted 2015-09-18T05:02:30.010

Reputation: 834

1

Ruby, 90 88 bytes

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

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

Try it online.

user45178

Posted 2015-09-18T05:02:30.010

Reputation:

1No need for string notation, just character ?N is enough. No need for parenthesis, around rand's parameter. – manatwork – 2015-09-21T09:00:07.050

1

Julia, 120 bytes

R(n)=lpad(rand(0:10^n-1),n,0)
for i=1:30 println("Crime Predicted: "R(3)"-"R(2)"-"R(4)"\nCalling: 1-"R(3)"-555-"R(4))end

Ungolfed:

# 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)
end

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

Alex A.

Posted 2015-09-18T05:02:30.010

Reputation: 23 761

0

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....<
^;^6<;<>a,v
   v_@#:-1<

MegaTom

Posted 2015-09-18T05:02:30.010

Reputation: 3 787

0

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.

Zach Gates

Posted 2015-09-18T05:02:30.010

Reputation: 6 152