Leggere le notizie è noioso. Aiutarmi!


22

Tutti sanno che la notizia è noiosa. Davvero noioso . A meno che non si tratti di politici e dei loro scandali. È divertente! Ma ahimè, i politici possono commettere solo così tanti scandali. Quindi, ti sto assumendo per rendere le notizie più interessanti.

Obiettivo Dato uno snippet HTML, esegui tutte le sostituzioni trovate qui , ovvero in questa immagine:

MA non dovresti modificare alcun tag HTML da solo. Chiamo una parola valida qualsiasi parola che non si trova all'interno di alcun tag HTML o dei loro attributi. Cioè, non dovresti sostituirlo <div class="smartphone">iPhone</div>con <div class="pokedex">iPhone</div>, ma dovresti sostituirlo <div>election</div>con <div>eating contest</div>.

Regole di analisi

  • MODIFICA Dovresti abbinare solo le parole delineate da una non parola. Cioè, dovresti abbinare solo parole piene. (Ad esempio, abbina "Ciao testimone" ma non "Hellowitness", "Hellow itness" o "Witnesspacelection".
  • Se non riesci a digitare il carattere sulla tastiera, dovresti visualizzare l'equivalente più vicino. (Ad esempio, "Smartphone" diventerebbe davvero "Pokedex")
  • Il caso di prima lettera o di tutte le lettere deve essere conservato. (Ad esempio, "Presumibilmente, sono morti" diventa "Kinda probabilmente, sono morti", "Presumibilmente sono morti" diventa "Probabilmente sono morti", e "L'ELEZIONE!" Diventa "IL CONCORSO MANGIANTE!", Mentre "SpAcE" diventa "Spaaace" e "nEW STUDY" diventano "tumblr post")
  • Tutti i casi devono essere abbinati. (Cioè, devi abbinare una parola, indipendentemente dalla sua maiuscola.)
  • Qualsiasi istanza in cui a <vowel>si incontra dovrebbe diventare an <vowel>e viceversa . (Ad esempio, "Un senatore" diventa "Un signore degli elfi") Non devi farlo per ogni caso, ma almeno per i tuoi sostituti.
  • Qualunque plurale deve anche conservare la pluralizzazione nella traduzione (ad esempio, "Smartphone" diventa "pokedex" e "Spaces" diventa "Spaaaces")
  • Qualsiasi cosa in un certo tempo deve rimanere in quel tempo nella traduzione. (Ad esempio, "Ricostruito" diventa "Vendicato", "Ricostruisci" diventa "Vendicato", ecc.)
  • Qualunque cosa al singolare deve rimanere singolare nella traduzione (ad esempio, "leader congressuale" diventa "spirito fluviale")
  • Se la voce comprende più elementi HTML, dovresti comunque abbinarla, ma puoi "buttare via" qualsiasi elemento intermedio. (Ad esempio, S<b>pa</b>acedovrebbe diventare semplicemente "spaaace"). Se la voce è autonoma all'interno di un singolo elemento, deve essere abbinata correttamente e il tag deve essere mantenuto.
  • "I testimoni" dovrebbero diventare "Quei tipi che conosco"
  • "testimone" dovrebbe diventare "Questo tizio che conosco"
  • "Il testimone" dovrebbe diventare "Quel tizio che conosco"
  • "Impossibile ottenere un commento" dovrebbe diventare "È colpevole e tutti lo sanno"
  • "Non può essere raggiunto per un commento" dovrebbe diventare "Sono colpevoli e tutti lo sanno"

bonus

Se incontri un -N%bonus, il tuo new amount = (old amount) * (1 - N/100). Quindi, se hai incontrato un -5%bonus con un codice di 500 byte, il tuo new amount = 500 * (1 - 5/100) = 500 * .95 = 475.

  • -5% di bonus se, per ogni istanza di "spazio" dopo la prima sostituzione, viene aggiunta una "a" aggiuntiva. Quindi, il primo sostituto sarebbe "spaaace", il secondo sarebbe "spaaaace", il terzo sarebbe "spaaaaace", ecc.
  • -5% di bonus se, per ogni numero valido, si sostituisce quel numero con un collegamento al rispettivo fumetto XKCD. (Non deve ancora esistere). Se si va per questo bonus, si dovrebbe abbinare i numeri come 500, 3,000, 4 523, e 5.324. (Puoi scegliere di sostituire, invece, il numero con l'immagine del fumetto. Se lo fai, invece di un -5%bonus, otterrai un -15% bonus. Un altro -15%bonus extra se puoi aggiungere il testo del titolo all'immagine, se presente .)
  • -25% di bonus se puoi sostituire contemporaneamente tutte le istanze sul lato destro dell'immagine con quelle a sinistra. (Ad esempio, "spaaace" diventa "spazio", "gara alimentare" diventa "elezione", ecc.) Se si opta per uno qualsiasi dei bonus, si dovrebbe essere in grado di ripristinare quelli alle rispettive voci. (Ad esempio, http://www.xkcd.com/542dovrebbe diventare "542" e "spaaaaaaaace" dovrebbe diventare "spazio".)
  • Puoi scegliere di effettuare un minimo di 6 sostituzioni, ma per ogni sostituzione non effettuata (al netto delle sostituzioni bonus), riceverai una penalità aggiuntiva del + 10%.

IO di esempio (nessun bonus)

Input: Witnesses allegedly used their smartphones to commit the crime.
Output: These dudes I know kinda probably used their pokedex to commit the crime.

Input: Mayor Golfalot rebuilt the city after the fatal election.
Output: Mayor Golfalot avenged the city after the fatal eating contest.

Input: This <b>new study</b> shows that people in <span class="space">space</span> cannot be reached for comment.
Output: This <b>tumblr post</b> shows that people in <span class="space">spaaace</span> are guilty and everyone knows it.

Input: <b>g</b><i>oo</i><s>g</s><u>le</u> glass is terrible. :(
Output: virtual boy is terrible. :(

Input: Electric SMARTPHONES have been shown to be more productive when not used by Senators and when not used in cars.
Output: Atomic POKEDEX have been shown to be more productive when not used by Elf-lords and when not used in cats.

Input: Homeland Security has been established as an evil foundation, especially in space.
Output: Homestar runner has been established as an evil foundation, especially in spaaace.

Input: The congressional leaders are testy today.
Output: The river spirits are testy today.

Input: SPACE is not a Senator or a cAR.
Output: SPAAACE is not an Elf-lord or a cat.

Input: Mr. Biz is running for reelection.
Output: Mr. Biz is running for reelection.

Input: Google   glass !
Output: Virtual boy !

Input: New (or old) study
Output: New (or old) study

Questo è un , quindi vince il programma più breve in byte.


Cosa dovrebbe diventare "Witnessespace"?
lirtosiast,

@ThomasKwa "Witnessespace". Non abbinare parole incomplete.
Conor O'Brien,


3
Sembra una sfida interessante. Dovrò provarci presto
Sam Weaver,

1
@DomHastings Sì, posso; non ci saranno input non validi e tag non chiusi (ad es. <br/>)
Conor O'Brien,

Risposte:


8

Perl 5 , 850

Molti regex utilizzati o generati.
L'hash% l viene utilizzato per parole ripetute.

%l=qw(A avenge B _be_reached_for_comment C could D dude E pokedex G google_glass I _I_know K river_spirit L congressional_leader P smartphone 4 rebuil N new_stud T tumblr_post V virtual_boy W witness Y _guilty_and_everyone_knows_it);$t="G,V;Ges,Vs;Ps,E;P,E;4d,A;4t,Ad;Nies,Ts;Ny,T;Wes,these DsI;W,this DI;allegedly,kinda probably;cannotB,areY;car,cat;cars,cats;Ls,Ks;L,K;C notB,isY;Cn'tB,isY;election,eating contest;electric,atomic;homeland Security,homestar runner;senator,elf-lord;senators,elf-lords;space,spaaace";$o=$s=$_;$s=~s/\s\s*/ /g;map{$t=~s/$_/$l{$_}/g}keys%l;$t=~s/_/ /g;@L=split/;/,$t;map{my@T=split/,/;push@W,\@T}@L;map{$e=$a=$W[$_][0];$b=$W[$_][1];$U=uc$a;$u=ucfirst$a;$s=~s/(?<![\w"])$U(?![\w"])/\U$b/g;$s=~s/(?<![\w"])$u(?![\w"])/\u$b/g;$s=~s/(?<![\w"])$a(?![\w"])/$b/gi;$e=~s@.@(<.*?>)?$&(</.*?>)?@g;$s=~s/$e /$b /ig;}0..@W;$_=$s.$/

Test

$ cat news.txt |perl -p readingnews.pl
These dudes I know kinda probably used their pokedex to commit the crime.
Mayor Golfalot avenged the city after the fatal eating contest.
This <b>tumblr post</b> shows that people in <span class="space">spaaace</span> are guilty and everyone knows it.
virtual boy is terrible. :(
Atomic POKEDEX have been shown to be more productive when not used by Elf-lords and when not used in cats.
Homestar runner has been established as an evil foundation, especially in spaaace.
The river spirits are testy today.
SPAAACE is not a Elf-lord or a cat.
Mr. Biz is running for reelection.
Virtual boy !
New (or old) study

Congratulazioni per il primo posto!
Conor O'Brien,

9

JavaScript ES6, 954 byte

Pensavo che sarebbe stato molto più semplice di quanto non fosse! Inizialmente usavo JavaScript per poter facilmente scendere solo nei nodi di testo e sostituire il testo lì, ma non era questo il problema, quindi ho finito con questa mostruosità! Passa tutti i casi di test tranne <b>g</b><i>oo</i><s>g</s><u>le</u> glass is terrible. :(quando l'intera stringa ritorna in un <b>tag a causa del bilanciamento dei tag. La maggior parte del codice è la tabella di ricerca e probabilmente mi mancano ancora alcuni casi limite, ma non sono riuscito a trovare un modo migliore per gestire correttamente il tempo e sono sicuro di poterlo comprimere di più, ma sto finendo le idee ... sono sicuro che tornerò su questo più tardi però. Avrei dovuto usare Perl, scelta migliore @LukStorms !

d=document.createElement`div`,u='toUpperCase'
d[i='innerHTML']=prompt``;`the ${w='witness'}es,those dudes I know|${w}es,these dudes I know|the ${w},this dude I know|${w},dude I know|allegedly,kinda probably|new study,tumblr post|new studies,tumblr posts|rebuild,avenge|rebuilt,avenged|space,spaaace|${g='google glass'},virtual boy|${g}es,virtual boys|smartphones,pokédex|smartphone,pokédex|electric,atomic|senator,elf-lord|car,cat|election,eating contest|congressional leader,river spirit|homeland security,homestar runner|could not ${b='be reached for comment'},is${g=' guilty and everyone knows it'}|couldn't be reached for comment,is${g}|cannot be reached for comment,are${g}`[v='split']`|`.map(w=>d[i]=d[i][r='replace'](eval(`/(<[^>]+)?\\b${(w=w[v]`,`)[0][v]``.join`(?:<\\/?[^>]+>)*`[r](/ /g,'\\s+')}(s?)\\b/gi`),(s,q,t)=>[q?s:((!s.match(/[^A-Z]/)?w[1][u]():s.match(/^[A-Z]/)?w[1][r](/^./,q=>q[u]()):w[1])+t),q?0:w[1]=w[1][r](/ce$/,'ace')][0])[r](/\ba(?= [aeiou])/gi,s=>s=="a"?"an":"AN"))
alert(d[i])

Ho applicato un bonus per il 5% di spaaaceottenere un ulteriore adopo ogni partita andata a buon fine. Utilizza alert()come suggerito da @sysreq , grazie!

Esempi

Input: <b>g</b><i>oo</i><s>g</s><u>le</u> glass is terrible. :(
Output: <b>virtual boy is terrible. :(</b>
Input: space. Space? Space! SPACE!
Output: spaaace. Spaaaace? Spaaaaace! SPAAAAAACE!
Input: Smartphones aren't really smart phones, but: SMARTPHONES!
Output: Pokédex aren't really smart phones, but: POKÉDEX!
Input: Senator John Doe was arrested today after attempting to write a new study on the danger of smartphones being used in the car, on his smartphone whilst driving his car. A witness testified to having seen the senator committing the crime. When questioned, Senator Doe "could not be reached for comment". It's unknown if his reputation can be rebuilt and this puts new doubts on the upcoming election. Congressional leaders have yet to comment.
Output: Elf-lord John Doe was arrested today after attempting to write a tumblr post on the danger of pokédex being used in the cat, on his pokédex whilst driving his cat. A dude I know testified to having seen the elf-lord committing the crime. When questioned, Elf-lord Doe "is guilty and everyone knows it". It's unknown if his reputation can be avenged and this puts new doubts on the upcoming eating contest. River spirits have yet to comment.

Bonus: bookmarklet

Esegui questo nella tua console per avere il testo del corpo aggiornato sul posto:

d=document.body;`the ${w='witness'}es,those dudes I know|${w}es,these dudes I know|the ${w},this dude I know|${w},dude I know|allegedly,kinda probably|new study,tumblr post|new studies,tumblr posts|rebuild,avenge|rebuilt,avenged|space,spaaace|${g='google glass'},virtual boy|${g}es,virtual boys|smartphones,pokédex|smartphone,pokédex|electric,atomic|senator,elf-lord|car,cat|election,eating contest|congressional leader,river spirit|homeland security,homestar runner|could not ${b='be reached for comment'},is${g=' guilty and everyone knows it'}|couldn't be reached for comment,is${g}|cannot be reached for comment,are${g}`[v='split']`|`.map(w=>d[i='innerHTML']=d[i][r='replace'](eval('/(<[^>]+)?\\b'+(w=w[v]`,`)[0][v]``.join`(?:<\\/?[^>]+>)*`[r](/ /g,'\\s+')+'(s)?\\b/gi'),(s,q,t)=>[q?s:((s.match(/^[A-Z]+$/)?w[1].toUpperCase():s.match(/^[A-Z]/)?w[1][r](/^./,q=>q.toUpperCase()):w[1])+(t||"")),q?0:w[1]=w[1][r](/ce$/,'ace')][0])[r](/\ba ([aeiou])/gi,(s,t)=>s[0]=="a"?"an "+t:"AN "+t))

2
alertè più corto rispetto console.loga quando viene eseguito in un browser.
gatto

Il <b>tag "problema" è perfettamente accettabile, se non più accettabile. E adoro l'ultimo esempio. Stavo cercando di pensare a uno che incorporasse la maggior parte di essi. Congratulazioni per la prima risposta! Sono sicuro che è competitivo;)
Conor O'Brien,
Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.