It's Not 2015 Anymore!

3

2

The Rules

  • Each submission must be a full program or a function.
  • The program must take all instances of the string 2015 from the input (1 string), replace it with <s>2015</s>* (with <s> or <strike>). At the end, if there has been at least one 2015 in the string, you must add a newline and this string: *2016. I'm a year early!
  • The program must not write anything to STDERR.
  • The input will not contain <s>2015</s> or <strike>2015</strike>.

    Note that there must be an interpreter so the submission can be tested.

  • Submissions are scored in bytes, in an appropriate (pre-existing) encoding, usually (but not necessarily) UTF-8. Some languages, like Folders, are a bit tricky to score - if in doubt, please ask on Meta.
  • This is , so shortest code wins

Examples

Input:

Hello! The date is 2015-12-24.

Output:

Hello! The date is 2015*-12-24.
*2016. I'm a year early!

Input:
foo bar baz quux

Output:

foo bar baz quux

Input:

12320151203205120151294201511271823

Output:

1232015*120320512015*12942015*11271823
*2016. I'm a year early!

Input:

 Hello. The year is 2015...
2015.5...

Output:

 Hello. The year is 2015*...
2015*.5...
*2016. I'm a year early!

The Snippet

The Stack Snippet at the bottom of this post generates the catalogue from the answers a) as a leaderboard and b) as a list of winners per language.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

## Language Name, N bytes

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

## Ruby, <s>104</s> <s>101</s> 96 bytes

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

## Perl, 43 + 2 (-p flag) = 45 bytes

You can also make the language name a link which will then show up in the snippet:

## [><>](http://esolangs.org/wiki/Fish), 121 bytes

var QUESTION_ID=68372,OVERRIDE_USER=45162;function answersUrl(e){return"http://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"http://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(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){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?([\d.]+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<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="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>

ev3commander

Posted 2016-01-02T01:14:34.143

Reputation: 1 187

Can we use <strike>? – Downgoat – 2016-01-02T01:21:26.337

I'm not sure if that would allow you to make it shorter. – ev3commander – 2016-01-02T01:23:22.257

@BlockCoder1392 It might. "asdf".strike() is javascript. – Conor O'Brien – 2016-01-02T01:27:33.827

Hmm... sure. I'll add it to the post – ev3commander – 2016-01-02T01:29:33.930

Can the input contain <s>2015</s>*? – Martin Ender – 2016-01-02T01:30:43.973

No. The input will not contain <s>2015</s> or <strike>2015</strike>. – ev3commander – 2016-01-02T01:33:33.863

1@downvoters what is wrong with this challenge? – ev3commander – 2016-01-02T01:41:10.000

15I find the challenge boring. It's a find-replace followed by a conditional concatenated string. Also, I don't like when functions are disallowed for no particular reason. – xnor – 2016-01-02T01:45:39.217

@xnor ... To quote NBZ, "Because there are not enough simple code-golf challenges" – ev3commander – 2016-01-02T01:47:24.733

8Yes, but a challenge can be simple without being straightforward. Replacement or regex is a built-in in most langs. It means that's likely just the way to do it. – xnor – 2016-01-02T01:49:16.457

2Can we have any trailing whitespace? – Downgoat – 2016-01-02T02:30:51.900

4Not everyone agrees with @NBZ on that. And there are certainly more than enough trivial questions. If you post questions which have a negative score in the sandbox, don't be surprised to see them downvoted. – Peter Taylor – 2016-01-02T14:57:50.260

@Doᴡɴɢᴏᴀᴛ No trailing whitespace. – ev3commander – 2016-01-02T17:00:31.707

Will the input have newlines – Downgoat – 2016-01-02T19:39:48.660

Your code has to accept new lines. – ev3commander – 2016-01-02T19:43:09.783

instead of "replace it with <s>2015</s> (with <s> or <strike>)and put an asterisk to the right of it" you could just say "replace it with <s>2015</s>* – Cyoce – 2016-01-02T20:14:16.630

Answers

1

Stax, 36 bytes

ç┼↕+∙n7↔Qq┼╩↓╣ÇÖú];ⁿX£╞bëi⌐ñ▼Z♀φ6╛(<

Run and debug it

Unpacked, ungolfed, and commented, it looks like this.

_               push all of standard input
2015X           push 2015 and store it in the x register
$/c             split string on "2015", and copy the result
"<s>`x</s>*"*P  join with "<s>2015</s>*" and print
D!C             stop executing if split resulted in more than 1 element
'*p             print "*" without newline
|Xp             increment x register and print without newline
                print unterminated compressed literal ". I'm a year early!"
`Q_RUWZ)O-C!

Run this one

recursive

Posted 2016-01-02T01:14:34.143

Reputation: 8 616

13

JavaScript ES6, 84 76 75 bytes

s=>(q=s.replace(/2015/g,"<s>$&</s>*"))+(s<q?`
*2016. I'm a year early!`:"")

This is pretty well golfed for JavaScript imo.


This works by taking the input and replacing all instances of 2015 with <s>$&</s>* where $& is the value matched, but in this case, that's always 2015. Then, if the input is different from q, it'll add the *2016... string, otherwise, It'll add a blank string (nothing).

Downgoat

Posted 2016-01-02T01:14:34.143

Reputation: 27 116

I think you can do (q!=s&&`\n*2016. I'm a year early!`) – Conor O'Brien – 2016-01-02T02:21:47.703

@CᴏɴᴏʀO'Bʀɪᴇɴ That seems to add "false" to the string when the condition is false :( – Downgoat – 2016-01-02T02:28:59.167

Oh, dangit. That's bad :P – Conor O'Brien – 2016-01-02T02:30:02.827

1

Very interesting. Never knew about $& or any of the other special replacement patterns.

– rink.attendant.6 – 2016-01-02T04:11:58.227

5

Ruby, 69 bytes

$><<gets.gsub(/2015/,'<s>\&</s>*')
puts"*2016. I'm a year early!"if$&

daniero

Posted 2016-01-02T01:14:34.143

Reputation: 17 193

4

Jolf, 60 bytes

Two parts, again.

oHρi"2015"+pd"s'$&'*"
oH                    set H
  ρi"2015"             to input string, replaced all 2015 with
           pd"s'$&'    $& crossed out. (pd is an apply tag function)
          +        *" append an asterisk

    v-- unprintable
+H|&?=Hi+S"*2016. I\'m a year early!'"
+H|&?=Hi                            '" add ↓ to H if H != i; otherwise add empty string ('")
        +S"*2016. I\'m a year early!'  a newline plus that string
                                       implicit printing

Try it here! Bonus points for actually crossing out the text and conforming to the output examples? :3

Conor O'Brien

Posted 2016-01-02T01:14:34.143

Reputation: 36 228

Technically against the rules. +1. – wizzwizz4 – 2016-01-02T17:29:57.087

3

Python, 97 bytes

a=raw_input();b=a.replace('2015','<s>2015</s>*');print a;
if a!=b:print"*2016. I'm a year early!"

This takes input from stdin, replaces any instances of 2015 with a strike, and prints the 2016 message if the two strings don't match.

Zizouz212

Posted 2016-01-02T01:14:34.143

Reputation: 272

couldn't you use a<b instead of a!=b? – Cyoce – 2016-01-02T20:22:49.020

2

05AB1E, 42 40 bytes

Ž7ç©åi®®"<s>ÿ</s>*".:®>“*ÿ. I'm€…‚Œ‰€!“»

Try it online!

-2 thanks to Grimy

Explanation

Ž7ç©åi®®"<s>ÿ</s>*".:®>“*ÿ. I'm€…‚Œ‰€!“» Full Program
Ž7ç©                                     Pushes 2015 and copies it to the register
    å                                    Checks if 2015 occurs in the input
     i                                   If yes, do the following steps, else
                                          finish and output the input
      ®®"<s>ÿ</s>*"                      Pushes 2015 and "<s>2015</s>*"
                   .:                    Replaces all instances of 2015 by 
                                          </s>2015</s> in the input
                     ®>“*ÿ. I'm€…‚Œ‰€!“  Push "*2016. I'm a year early!"
                                       » Concatenate both strings with a newline in between

Black Owl Kai

Posted 2016-01-02T01:14:34.143

Reputation: 980

1The » is not needed when there is no replacement, so you can just drop the } for -1. – Grimmy – 2019-05-28T21:15:36.367

2

40: Ž7ç©åi®®"<s>ÿ</s>*".:®>“*ÿ. I'm€…‚Œ‰€!“»

– Grimmy – 2019-05-28T21:37:20.760

2

Mathematica, 98 bytes

a="2015";StringReplace[#,a->"<s>2015</s>*"]<>If[#~StringCount~a>0,"
*2016. I'm a year early!",""]&

Once again, Mathematica's string processing uses many bytes...

LegionMammal978

Posted 2016-01-02T01:14:34.143

Reputation: 15 731

2

Pyth, 52 51 50 bytes

I-
:z"2015""<s>2015</s>*"z." ytµbðï«»±é¢þnl¶Vû

Test Suite.

Maltysen

Posted 2016-01-02T01:14:34.143

Reputation: 25 023

2

, 49 chars / 93 bytes

a=ïę ḟ*ṁ,`<s>$&</s>*”)+(a≠ï?ɘƂ联Ӏఈ쁬Πā␎䁛␐줄쁰ꖈᲠ䉠耀#:⬯

Try it here (Firefox only).

Really straightforward. a=ïę ḟ*ṁ,'<s>$&</s>*”) nests all instances of 2015 (represented here as the result of 31*65) in strikethrough tags. Then, append the last string ('compressed' here) accordingly.

Mama Fun Roll

Posted 2016-01-02T01:14:34.143

Reputation: 7 234

2

TeaScript, 59 bytes

(q=xg2015,"<s>$&</s>*"))+(x<q?`
*2016. I'm a year early!`:u

Try it online

Explanation

(q=        // Assign `q` to...
   xg      // input.replace
     2015  // 2015 with.
     "..." // The string
)) +       // Add to..

(x<q?      // If the input is different from replacement
     "..." // Add string to the end
    :u     // Otherwise empty string

Downgoat

Posted 2016-01-02T01:14:34.143

Reputation: 27 116

Downvote reason? This answer is perfectly valid, wth? – Downgoat – 2016-01-02T03:51:30.347

They'll always downvote downgoat! – wizzwizz4 – 2016-01-02T17:31:25.637

@wizzwizz4 :( Maybe Upgoat is having better luck

– Downgoat – 2016-01-02T17:32:24.913

How legal are sockpuppet accounts? – wizzwizz4 – 2016-01-02T17:34:18.960

@wizzwizz4 I don't use them for evil, >:) just chatbots so it's fine. – Downgoat – 2016-01-02T17:36:26.157

2

Japt, 51 bytes

Y=Ur2015"<s>$&</s>*")¥U?U:Y+`
*2016. I'm a ye e§!

Try it online!

nicael

Posted 2016-01-02T01:14:34.143

Reputation: 4 585

1

PowerShell, 81 79 bytes

-2 bytes thanks to mazzy

param($n)($z=$n-replace2015,'<s>$&</s>*')+"
*2016. I'm a year early!"*($z-ne$n)

Try it online!

Just a replace on the input and a conditional append with the 2016 line. You don't need many quotes or spaces in PowerShell either.

Veskah

Posted 2016-01-02T01:14:34.143

Reputation: 3 580

179 bytes :) – mazzy – 2019-05-28T18:10:15.680

1

(f)lex, 104 bytes

File 2015.l:

 int n=0;
%%
"2015" ++n+puts("<s>2015</s>*");
%%
main(){yylex();n&&puts( "*2016. I'm a year early!\n");}

...no trailing newline.

Build:

$ flex -o 2015.c 2015.l
$ gcc 2015.c -o 2015 -lfl

Run:

$ ./2015 <<<'Hello! The date is 2015-12-24.'
Hello! The date is <s>2015</s>*-12-24.
*2016. I'm a year early!
$ ./2015 <<<'foo bar baz quux'
foo bar baz quux
$ ./2015 <<<'12320151203205120151294201511271823'
123<s>2015</s>*12032051<s>2015</s>*1294<s>2015</s>*11271823
*2016. I'm a year early!

I ran this using flex and gcc on Debian8, but I see no reason why it should fail in other environments using lex and/or a different C compiler.

user19214

Posted 2016-01-02T01:14:34.143

Reputation:

Note it may bail out due to integer overflow. – Krzysztof Szewczyk – 2019-08-01T10:45:34.013

1

C#, 152 bytes

class A{static void Main(string[]a){System.Console.Write(a[0].Replace("2015","<s>2015</s>*")+(a[0].Contains("2015")?"\n*2016. I'm a year early!":""));}}

Basic solution. Takes the string as the first argument.

LegionMammal978

Posted 2016-01-02T01:14:34.143

Reputation: 15 731

1

Gema, 57 bytes

2015=<s>$0</s>*@set{a;*2016. I'm a year early\!}
\Z=${a;}

Sample run:

bash-4.3$ gema -f not-2015.gema <<< 'Hello! The date is 2015-12-24.'
Hello! The date is <s>2015</s>*-12-24.
*2016. I'm a year early!

bash-4.3$ gema -f not-2015.gema <<< 'foo bar baz quux'
foo bar baz quux

bash-4.3$ gema -f not-2015.gema <<< '12320151203205120151294201511271823'
123<s>2015</s>*12032051<s>2015</s>*1294<s>2015</s>*11271823
*2016. I'm a year early!

manatwork

Posted 2016-01-02T01:14:34.143

Reputation: 17 865

1

Retina, 49 45 64 61 60 54 bytes

s`2015.+
$&¶*2016. I'm a year early!
\`2015
<s>$&</s>*

After numerous attempts I think this is the shortest Retina solution


The first line matches 2015, the second line replaces the previous match (2015) with <s>$&</s>* where $& is the match's value or in this case, 2015.

The \ removes the trailing newline from the output. The ` starts the regex. $ matches the end specifying we're trying to add a string to the end. The last line simply adds the string where becomes a newline. Retina uses the ISO-8859-1 encoding in which the is one byte

Try it online

Downgoat

Posted 2016-01-02T01:14:34.143

Reputation: 27 116

1

ROOP, 110 bytes

 1I
 CW
 |%|
 V !
H
' "<s>2015</s>*"
2R !
0 #V
1 G #
5V #"\n*2016. I'm a year early!"
'| M #
 -V #

  #W
   O#

This uses the R operator to replace all occurrences of the string 2015 in the input to <s>2015</s>*.Then, there is a comparison -- if the input string and the new one are different, then 1 is returned. Otherwise, 0 is returned. Then, M repeats the string \n*2016. I'm a year early that many times, i.e. if there are no changes, the string is blank, otherwise, the string is \n*2016. I'm a year early. Then, the strings are printed and the program terminates.

Above there is a 1 which is moved to the left and then falls to the operator H, which ends the program.

DarkPhantom

Posted 2016-01-02T01:14:34.143

Reputation: 191

It should print "*2016. I'm a year early!" only once – ev3commander – 2016-01-03T23:27:41.687

That's what it does. – DarkPhantom – 2016-01-03T23:29:51.780

Oh. I misinterpreted the usage of M. – ev3commander – 2016-01-03T23:32:44.050

Use 1 or 0, sorry, English is not my native language. Feel free to improve the text if necessary. – DarkPhantom – 2016-01-03T23:35:43.760

0

Python 3.8 (pre-release), 80 bytes

lambda x:(b:=x.replace('2015','<s>2015<s>*'))+"\n*2016. I'm a year early!"*(b>x)

Try it online!

Saved 8 bytes thanks to squid

MilkyWay90

Posted 2016-01-02T01:14:34.143

Reputation: 2 264

Unless I've missed a way that this breaks it, 84 bytes

– Reinstate Monica – 2019-05-28T18:03:24.660

80 bytes – Reinstate Monica – 2019-05-28T19:08:35.073

@squid Okay, thanks! – MilkyWay90 – 2019-05-28T22:18:31.287

0

Perl 5 -p, 53 bytes

$\="\n*2016. I'm a year early!"if s|2015|<s>$&</s>*|g

Try it online!

Xcali

Posted 2016-01-02T01:14:34.143

Reputation: 7 671

Literal newline instead of "\n" saves a byte – Grimmy – 2019-05-28T21:46:55.883