In materia di password


10

In Keep Talking e Nessuno esplode , i giocatori hanno il compito di disinnescare le bombe in base alle informazioni dei loro "esperti" (altre persone con un manuale). Ogni bomba è composta da moduli, uno dei quali può essere una password, in cui all'esperto viene fornito questo elenco di possibili password, lunghe tutte e cinque le lettere:

about   after   again   below   could
every   first   found   great   house
large   learn   never   other   place
plant   point   right   small   sound
spell   still   study   their   there
these   thing   think   three   water
where   which   world   would   write

E al giocatore viene fornito un elenco di 6 possibili lettere per ogni posto nella password. Date le possibili combinazioni di lettere, emettere la password corretta. L'input può essere in qualsiasi formato ragionevole (array 2D, stringa separata da newline, ecc.) Puoi scartare il codice che usi per comprimere / generare l'elenco / stringa / array / qualunque sia la password. (Grazie @DenkerAffe)

NOTA: le password non fanno distinzione tra maiuscole e minuscole. Si può presumere che l'input risolverà solo per una password.

Esempi / casi di test

L'input qui sarà rappresentato come una matrice di stringhe.

["FGARTW","LKSIRE","UHRKPA","TGYSTG","LUOTEU"] => first
["ULOIPE","GEYARF","SHRGWE","JEHSDG","EJHDSP"] => large
["SHWYEU","YEUTLS","IHEWRA","HWULER","EUELJD"] => still


8
Suggerisco di consentire l'elenco di possibili password come input per il programma. Altrimenti ciò si riduce a quale lingua ha la migliore compressione delle stringhe.
Denker,

5
Va bene se lo cambi; Non mi dispiacerebbe (la maggior parte della mia presentazione rimarrebbe invariata).
Maniglia della porta

4
Sono d'accordo con DenkerAffe: avere le possibili password fornite come input anziché un elenco statico rappresenta una sfida molto più interessante.
Mego,

5
Potrebbe semplificare le cose se usi anche l'elenco delle stringhe come secondo input, poiché chiarisce quali byte contano. Non ero sicuro di contare la <soluzione Bash, ad esempio.
Maniglia della porta

Risposte:


6

Pyth, 13 byte

:#%*"[%s]"5Q0c"ABOUTAFTERAGAINBELOWCOULDEVERYFIRSTFOUNDGREATHOUSELARGELEARNNEVEROTHERPLACEPLANTPOINTRIGHTSMALLSOUNDSPELLSTILLSTUDYTHEIRTHERETHESETHINGTHINKTHREEWATERWHEREWHICHWORLDWOULDWRITE"5

Suite di test.

 #             filter possible words on
:           0  regex match, with pattern
  %        Q   format input as
    "[%s]"     surround each group of letters with brackets (regex char class)
   *      5    repeat format string 5 times for 5 groups of letters

Hai dimenticato di aggiornare il tuo primo blocco di codice: P
Downgoat,

@Downgoat Cosa ho dimenticato di aggiornare? Mi sembra giusto.
Maniglia della porta

Strano, il primo blocco di codice sembra non corrispondere all'esempio (sembra essere una vecchia revisione?)
Downgoat,


6

Bash, 22 byte

grep `printf [%s] $@`< <(echo ABOUTAFTERAGAINBELOWCOULDEVERYFIRSTFOUNDGREATHOUSELARGELEARNNEVEROTHERPLACEPLANTPOINTRIGHTSMALLSOUNDSPELLSTILLSTUDYTHEIRTHERETHESETHINGTHINKTHREEWATERWHEREWHICHWORLDWOULDWRITE | sed 's/...../&\n/g')

Esegui così:

llama@llama:~$ bash passwords.sh FGARTW LKSIRE UHRKPA TGYSTG LUOTEU
FIRST
      printf [%s] $@    surround all command line args with brackets
grep `              `   output all input lines that match this as a regex
                     <  use the following file as input to grep

Non fa alcuna differenza per il tuo punteggio, ma non riesco ancora a resistere a questo golf:fold -5<<<ABOUTAFTERAGAINBELOWCOULDEVERYFIRSTFOUNDGREATHOUSELARGELEARNNEVEROTHERPLACEPLANTPOINTRIGHTSMALLSOUNDSPELLSTILLSTUDYTHEIRTHERETHESETHINGTHINKTHREEWATERWHEREWHICHWORLDWOULDWRITE|grep `printf [%s] $@`
Digital Trauma,

2

JavaScript (ES6), 62 byte

(l,p)=>p.find(w=>l.every((s,i)=>eval(`/[${s}]/i`).test(w[i])))

53 byte su Firefox 48 o precedenti:

(l,p)=>p.find(w=>l.every((s,i)=>~s.search(w[i],"i")))

Sarebbe stato di 49 byte se non per quel requisito di insensibilità al caso:

(l,p)=>p.find(w=>l.every((s,i)=>~s.search(w[i])))


2

Brachylog , 25 byte

:@laL,["about":"after":"again":"below":"could":"every":"first":"found":"great":"house":"large":"learn":"never":"other":"place":"plant":"point":"right":"small":"sound":"spell":"still":"study":"their":"there":"these":"thing":"think":"three":"water":"where":"which":"world":"would":"write"]:Jm.'(:ImC,L:Im'mC)

I byte non conteggiati sono l'array di parole, comprese le parentesi quadre.

Spiegazione

:@laL                          Unifies L with the input where each string is lowercased
     ,[...]:Jm.                Unifies the Output with one of the words
               '(            ) True if what's in the parentheses is false,
                               else backtrack and try another word
                 :ImC          Unify C with the I'th character of the output
                     ,L:Im'mC  True if C is not part of the I'th string of L

2

Rubino, 48 42 39 byte

Ora che è fatto, è molto simile alla soluzione Pyth, ma senza %sformattazione al punto in cui ora è sostanzialmente una porta diretta.

Se si emette solo il risultato con puts, [0]alla fine non è necessario il poiché putssi occuperà di quello per te.

->w,l{w.grep(/#{'[%s]'*l.size%l}/i)[0]}

Con casi di test:

f=->w,l{w.grep(/#{'[%s]'*l.size%l}/i)[0]}

w = %w{about after again below could
every first found great house
large learn never other place
plant point right small sound
spell still study their there
these thing think three water
where which world would write}

puts f.call(w, ["FGARTW","LKSIRE","UHRKPA","TGYSTG","LUOTEU"]) # first
puts f.call(w, ["ULOIPE","GEYARF","SHRGWE","JEHSDG","EJHDSP"]) # large
puts f.call(w, ["SHWYEU","YEUTLS","IHEWRA","HWULER","EUELJD"]) # still

1

JavaScript (ES6), 71 byte

w=>l=>w.filter(s=>eval("for(b=1,i=5;i--;)b&=!!~l[i].indexOf(s[i])")[0])

Uso:

f=w=>l=>w.filter(s=>eval("for(b=1,i=5;i--;)b&=!!~l[i].indexOf(s[i])")[0])
f(array_of_words)(array_of_letters)

1

Python, 64 60 57 byte

Codice per creare un elenco di parole wcome stringa, le parole sono separate da spazio (i byte sono scontati dalla lunghezza del codice della soluzione):

w="about after again below could every first found great house large learn never other place plant point right small sound spell still study their there these thing think three water where which world would write"

Soluzione corrente (57 byte): 3 byte salvati grazie a @RootTwo

import re;f=lambda a:re.findall("(?i)\\b"+"[%s]"*5%a,w)[0]

Questa funzione accetta un tuple(no list!) Esattamente di 5 stringhe che rappresentano le possibili lettere per ciascun carattere della password come input.

Vedi questo codice in esecuzione su ideone.com


Seconda versione (60 byte):

import re;f=lambda a:re.findall("\\b"+"[%s]"*5%a+"(?i)",w)[0]

Questa funzione accetta un tuple(no list!) Esattamente di 5 stringhe che rappresentano le possibili lettere per ciascun carattere della password come input.

Vedi questo codice in esecuzione su ideone.com

Prima versione (64 byte):

import re;f=lambda a:re.findall("\\b["+"][".join(a)+"](?i)",w)[0]

Questa funzione accetta qualsiasi iterabile (ad es. listO tuple) di esattamente 5 stringhe che rappresentano le possibili lettere per ciascun carattere della password come input.

Vedi questo codice in esecuzione su ideone.com


1
Salva tre byte usando questo regex:"(?i)\\b"+"[%s]"*5%a
RootTwo

Certo, che evidente "errore" da parte mia ... Grazie per averlo sottolineato @RootTwo, ho modificato la mia risposta e ti ho dato dei crediti.
Byte Commander,

@ByteCommander Non vedo alcun credito.
Erik the Outgolfer,

@ ΈρικΚωνσταντόπουλος Proprio sotto la w=...riga di codice: " La soluzione effettiva (57 byte, salvati 3 byte grazie a @RootTwo): "
Byte Commander

@ByteCommander Forse avrei visto in anteprima una versione precedente dopo aver svegliato il mio pc dal letargo.
Erik the Outgolfer,

0

Hoon , 125 byte

|=
r/(list tape)
=+
^=
a
|-
?~
r
(easy ~)
;~
plug
(mask i.r)
(knee *tape |.(^$(r t.r)))
==
(skip pass |*(* =(~ (rust +< a))))

Ungolfed:

|=  r/(list tape)
=+  ^=  a
|-
  ?~  r
    (easy ~)
  ;~  plug
    (mask i.r)
    (knee *tape |.(^$(r t.r)))
  ==
(skip pass |*(* =(~ (rust +< a))))

Hoon non ha regex, solo un sistema combinatore parser. Questo rende piuttosto complicato far funzionare tutto: (mask "abc")si traduce approssimativamente in regex [abc], ed è il nucleo del parser che stiamo costruendo.

;~(plug a b)è un legame monadico di due parser sotto ++plug, che deve analizzare il primo e poi il secondo, altrimenti fallisce.

++kneeè usato per costruire un parser ricorsivo; gli diamo un tipo ( *tape) del risultato e un callback da chiamare per generare il parser effettivo. In questo caso, il callback è "chiama nuovamente l'intera chiusura, ma con la coda dell'elenco". Il ?~test delle rune è che l'elenco è vuoto e fornisce (easy ~)(non analizzare nulla e restituisce ~) o aggiunge un altro maske ricomincia.

Dopo aver creato il parser, possiamo iniziare a usarlo. ++skiprimuove tutti gli elementi dell'elenco per i quali la funzione restituisce yes per. ++rusttenta di analizzare l'elemento con la nostra regola, restituendo un unitche è uno [~ u=result]o ~(la nostra versione di Forse di Haskell). Se è ~(Nessuno e la regola non è stata in grado di analizzare o non ha analizzato l'intero contenuto), la funzione restituisce true e l'elemento viene rimosso.

Ciò che resta è un elenco, contenente solo la parola in cui ogni lettera è una delle opzioni nell'elenco indicato. Suppongo che l'elenco delle password sia già nel contesto sotto il nome pass.

> =pass %.  :*  "ABOUT"  "AFTER"   "AGAIN"   "BELOW"   "COULD"
   "EVERY"   "FIRST"   "FOUND"   "GREAT"   "HOUSE"
   "LARGE"   "LEARN"   "NEVER"   "OTHER"   "PLACE"
   "PLANT"   "POINT"   "RIGHT"   "SMALL"   "SOUND"
   "SPELL"   "STILL"   "STUDY"   "THEIR"   "THERE"
   "THESE"   "THING"   "THINK"   "THREE"   "WATER"
   "WHERE"   "WHICH"   "WORLD"   "WOULD"   "WRITE"
   ~  ==  limo
> %.  ~["SHWYEU" "YEUTLS" "IHEWRA" "HWULER" "EUELJD"]
  |=
  r/(list tape)
  =+
  ^=
  a
  |-
  ?~
  r
  (easy ~)
  ;~
  plug
  (mask i.r)
  (knee *tape |.(^$(r t.r)))
  ==
  (skip pass |*(* =(~ (rust +< a))))
[i="STILL" t=<<>>]

0

Python 3, 81 byte

from itertools import*
lambda x:[i for i in map(''.join,product(*x))if i in l][0]

Una funzione anonima che accetta l'input di un elenco di stringhe xe restituisce la password.

L'elenco delle possibili password lè definito come:

l=['ABOUT', 'AFTER', 'AGAIN', 'BELOW', 'COULD',
   'EVERY', 'FIRST', 'FOUND', 'GREAT', 'HOUSE',
   'LARGE', 'LEARN', 'NEVER', 'OTHER', 'PLACE',
   'PLANT', 'POINT', 'RIGHT', 'SMALL', 'SOUND',
   'SPELL', 'STILL', 'STUDY', 'THEIR', 'THERE',
   'THESE', 'THING', 'THINK', 'THREE', 'WATER',
   'WHERE', 'WHICH', 'WORLD', 'WOULD', 'WRITE']

Questa è una semplice forza bruta; Ero interessato a vedere quanto in breve avrei potuto ottenere questo senza regex.

Come funziona

from itertools import*  Import everything from the Python module for iterable generation
lambda x                Anonymous function with input list of strings x
product(*x)             Yield an iterable containing all possible passwords character by
                        character
map(''.join,...)        Yield an iterable containing all possible passwords as strings by
                        concatenation
...for i in...          For all possible passwords i...
i...if i in l           ...yield i if i is in the password list
:[...][0]               Yield the first element of the single-element list containing the
                        correct password and return

Provalo su Ideone

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.