| Bytes | Lang | Time | Link |
|---|---|---|---|
| 017 | Infinite Golfing | 250512T192429Z | JOrE |
| nan | It seems there's some confusion over whether this is possible | 240209T143039Z | Devsman |
Infinite Golfing, 17 bytes
ŸGoodbye World!Ÿ!
It seems there's some confusion over whether this is possible, so here's an example answer in...
FLEX/C (557 bytes)
%option noyywrap
%{#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#define p(X) printf(X)
#define s(X) strncat(w,X,99)
#define g(X) if(l==1){X}
#define d w[0]='\0';p(t);l=0;
#define t yytext
int l = 0;char *w;
%}
%%
[hH][eE][lL][lL][oO] {l=1;}
[wW][oO][rR][lL][dD] {g(p("goodbye");)p(w);d}
[\r\n\t ] {g(s(t);)else{p(t);}}
. {g(p("hello");)p(w);d}
%%
main(int c,char **a){w=malloc(99);w[0]='\0';if(access("f",F_OK)==0){l=1;remove("f");s("\n");}yylex();if(l==1){FILE* f=fopen("f","w");fclose(f);}else{p("\n");}}
Here's the ungolfed version:
%option noyywrap
%{
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#define FLAG_FILE "goodbye.flg"
int last = 0;
char *whitespace;
%}
%%
[hH][eE][lL][lL][oO] { last = 1; }
[wW][oO][rR][lL][dD] { if (last == 1) { printf("goodbye"); } printf(whitespace); whitespace[0] = '\0'; printf(yytext); last = 0; }
[\r\n\t ] { if (last == 1) { strncat(whitespace, yytext, 100); } else { printf(yytext); } }
. { if (last == 1) { printf("hello"); } printf(whitespace); whitespace[0] = '\0'; printf(yytext); last = 0; }
%%
main(int argc, char **argv)
{
whitespace = malloc(1000);
whitespace[0] = '\0';
if (access(FLAG_FILE, F_OK) == 0)
{
last = 1;
remove(FLAG_FILE);
strncat(whitespace, "\n", 100);
}
yylex();
if (last == 1)
{
FILE* file_ptr = fopen(FLAG_FILE, "w");
fclose(file_ptr);
}
else
{
printf("\n");
}
}
It chooses the abstain option, which as noted in the question, allows it to abstain from printing the last word if the last word in the input is "hello", and then decide on the next run whether to print "hello" or "goodbye" based on whether the following word is "world."