I simboli contro le lettere


17

I simboli contro le lettere

I caratteri ASCII sono stati nuovamente divisi ! I tuoi set sono Le lettere e I simboli .

Le lettere

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

I simboli

!"#$%&'()*+,-./0123456789:;<=>?@[\]^_`{|}~

Il compito è scrivere due programmi:

  1. Stampa ciascuna delle lettere esattamente una volta senza usarne nessuna nel tuo programma.

  2. Stampa ciascuno dei simboli esattamente una volta senza usarli nel tuo programma.

Regole

  • Gli spazi bianchi possono essere visualizzati nel programma o nell'output.
  • Non sono ammessi caratteri non ASCII.
  • L'output passa allo standard out o ad un file come contenuto o nome del file.
  • Nessun input
  • L'output deve contenere solo caratteri ASCII di un set o dell'altro.
  • I programmi possono essere scritti in diverse lingue o nella stessa lingua con una sola eccezione:
  • La lingua degli spazi bianchi può essere utilizzata solo per uno dei programmi.
  • Si applicano scappatoie standard .

punteggio

# of characters in program 1 +# of characters in program 2 =Score

Il punteggio più basso vince!

Nota:

Per incoraggiare ulteriori invii, è comunque possibile pubblicare una risposta con una soluzione per uno solo dei programmi. Non sarai in grado di vincere, ma sarai comunque in grado di mostrare qualcosa di interessante.

Grazie a Hobby di Calvin per aver ispirato l'idea con la sua domanda precedente .


4
Questo non è possibile nella maggior parte delle lingue ... Ad esempio in Haskell = è inevitabile
— orgoglioso haskeller il

1
@proudhaskeller parte della sfida è scegliere una lingua dove è possibile.
— hmatt1,

(Mi rendo conto che avrei dovuto pensarci mentre la domanda era nella sandbox, ma) dato che la regola "spazi bianchi possono apparire nell'output", questo significa che l'ordine dei (lettere | simboli) non ha importanza?
— FireFly,

@FireFly qualsiasi ordine va bene.
— hmatt1,

È consentito avere caratteri di controllo (punti di codice da 0 a 31 e 127) nel programma?
— FUZxxl,

Risposte:


7

Totale: 53 caratteri

Totale in una sola lingua: 230 caratteri, Pyth

Parte 1: Golfscript, 15

91,65>123,97>++

Uscite:

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

Spiegazione:

91,           Make the list, [0 1 .. 90]
65>           Take elements after the 65th, [65 66 .. 90]
123,97>       Same, but [97 98 .. 122]
+             Add the list above to the newline character that is automatically pushed to 
              the stack. List + str coerces to string by ascii encoding.
+             Same, for the other list.

Parte 2: Pyth , 38

JhCeGLjkmCdbsrCdCPhGsrhCPeGChGsrJhhhhJ

Uscite:

 !"#$%&'()*+,-./0123456789:;<=>?@
[\]^_`
{|}~

Spiegazione:

G = "abcdefghijklmnopqrstuvwxyz"   Implicit.
k = ""                             Implicit.
d = " "                            Implicit.
JhCeG                              J = 1 + chr(end(G))          # J = 123
L                                  def d(b): return
 jk                                                k.join(
   m                                                      map(lambda d:
    Cd                                                                 chr(d),
    b                                                                  b))
s                                  print(s(                    #print is implicit.
 rCd                               range(chr(d),                 # chr(d) = 32
 CPhG                                    chr(upper(head(G))))    # chr("A") = 65
srhCPeGChG                         print(s(range(1+chr(upper(end(G))),chr(head(G)))
srJhhhhJ                           print(s(range(J, 1+1+1+1+J)))

Soluzione bonus:

Parte 1: Pyth, 192

%*$"%\143"$52(65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122

Spiegazione:

$"%\143"$=> "% c". $passa da e verso lo stile di analisi Python e, nell'analisi della stringa Python, \143è la sequenza di escape ottale per c. Questa risposta equivale quindi al seguente codice in stile Python:

("%c" * 52) % (65, 66, 67, ...)

Naturalmente, questo non funziona in Python, perché la stampa in Python lo utilizza print, ma la stampa in Pyth è implicita, quindi funziona.


Le soluzioni Pyth non utilizzano nessuna delle funzionalità aggiunte da quando è stata posta la domanda.


Dove imparo Pyth? Dagli esempi?
— Soham Chowdhury,

@SohamChowdhury Gli esempi sono un buon punto di partenza. La lettura dei documenti è probabilmente il passaggio successivo: doc.txt nella directory principale. Il passo finale è iniziare a giocarci da soli, usando il flag -d (debug). Il software è nuovissimo e quindi non esiste niente di meglio. Per quanto ne so, solo 3 persone l'hanno mai usato e io sono l'unico ad averlo usato regolarmente. Buona fortuna, divertiti.
— isaacg,

23

Python (Simboli, 87 82)

from string import punctuation
from string import digits
print digits
print punctuation

Adoro il modulo di stringa di Python ...

Modificare:

from string import punctuation as p
from string import digits as d
print d
print p

Produzione:

0123456789
!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~

FALSE (Lettere, 21) DUP (Lettere, 20):

Soluzione FALSE:

65[$91\>][$,$32+,1+]#

DUP sollution (1 carattere più corto)

65[$91<][$,$32+,1+]#

Uscita (per entrambi):

AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz

Interprete per FALSO.


Totale: 102


1
Wow carino! Ho visto persone dire che questo non poteva essere fatto in Python, ben fatto.
— hmatt1,

from string import*funziona ugualmente bene e riduce il conteggio dei byte.
— aglasser,

5
@aglasser ... ma l'uso *è proibito in questo contesto ...
— Augıʇǝɥʇuʎs

4
Hai ragione, non riesco a credere che ho dimenticato * era un simbolo ahah. Questo spiega perché non l'hai fatto neanche tu from string import punctuation, digits. Bella soluzione che segue le regole. Scusa per il mio errore!
— aglasser,

13

GolfScript (14 caratteri) + Deadfish x (116 caratteri) = 130 caratteri

91,65>{.32+}%+

e

xxcxxcdddKxKxKxKxKxKxKxKxKxKxKxKxKxKxKxKxKxKxKxKxKxKxKxKxKxKxKxKxKxKxKxKDxxxccxxxxxxxxxxKxKxKxKxKxKDxxxcxxcxxKxKxKxK

2
+1 per essere stato il primo di quattro post finora effettivamente rispondere a entrambe le parti.
— Geobits il

10

Parti 1 e 2 in Ruby 2, 56 + 484 = 540

Parte 1:

__=->_{(91..96)===_||$><<(''<<_);_>121||__[-~_]}
__[65]

Per ulteriori informazioni su questo stile di Ruby, dai un'occhiata a narfnme .

Parte 2 (questo bit è solo Ruby 2.0+, funziona perfettamente con ruby-2.1.0 ma può dare avvisi nelle versioni precedenti):

class Fixnum
def c
String def a
end
end
def b
String def A
end
end
def x
String def z
end
end
def y
String def Z
end
end
def inspect
case chr
when c
when b
when y
p succ
else
print chr
p succ
end
p
rescue
p
end
end
def x
String def z
end
end
def y
String def Z
end
end
class String
def inspect
p size
p
end
end
p String p
class String
def inspect
p ord
p
end
end
p y
class Fixnum
def inspect
case chr
when x
p succ
else
send chr
print chr
p
end
p
rescue
print chr
p succ
p
end
end
p x

Quello è stato difficile. La chiamata di metodi Fixnum integrati come chre succrichiede l'apertura della classe Fixnum e la ridefinizione inspect, poiché posso attivare una chiamata x.inspectcon p x. Ho bisogno di ispezionare per tornare in nilmodo che pstamperà solo una nuova riga, qualsiasi stringa verrà racchiusa tra virgolette. Ma come effetto collaterale, si avvolge. Posso terminare il primo e il secondo loop usando un confronto di stringhe per vedere quando ho raggiunto un intervallo di lettere, ma poiché non riesco a scrivere una stringa letterale, devo ottenerne una chiamando String()il simbolo restituito (in Ruby 2) dalla defparola chiave. Dal momento che questa è una sintassi multilinea e posso solo fare il confronto delle stringhe tramitecase, che non può assumere espressioni multilinea, devo racchiudere il valore letterale in un metodo (dal momento che ovviamente non riesco a svolgere il compito). L'ultimo loop è più difficile da terminare. Ne ho bisogno per fermarmi a ~. Fortunatamente, dei caratteri ASCII in quell'intervallo, per rilevare quando sono alla fine e interrompere il loop.~ è l'unico che può essere chiamato su un Fixnum senza argomenti senza generare un errore, quindi posso usarlo send chr

Non è il miglior punteggio in questa discussione, ma finora l'unico che usa la stessa lingua per entrambe le parti. Yay Ruby.


1
+ Anche prima della tua seconda risposta, perché sapeva che sarebbe arrivato. Rispetto per spingere al limite la flessibilità di Ruby.
— Vectorized

+1 per la prima / unica risposta che fornisce entrambi i programmi nella stessa lingua. Finora questo è il chiaro vincitore dell'IMO. Non ho installato Ruby 2, ma confido che funzioni.
— Trauma digitale

8

Parte 2 in Applescript, 654

aspetta ... dov'è la pagina " suggerimenti per giocare a golf in Applescript "?

global a
global b
global c
global s
on f at n
set end of b to a
end
on g at n
f at a
f at a
end
on h at n
g at a
g at a
end
on i at n
h at a
h at a
end
on j at n
repeat with t in system info
f at a
end
end
on m at n
set end of b to a
set c to count of b
set end of s to ASCII character c
end
on n at n
m at a
m at a
m at a
end
on o at n
repeat with t in system info
m at a
end
end
set a to random number
set b to a as list
j at a
j at a
set c to count of b
set s to ASCII character c
set s to s as list
o at a
n at a
n at a
n at a
n at a
n at a
j at a
i at a
g at a
f at a
n at a
m at a
m at a
j at a
i at a
g at a
n at a
m at a
display dialog s as text

Produzione:

inserisci qui la descrizione dell'immagine


1
Sapevo che ci sarebbe stato un solletico di Apple. Qui, prendi un +1.
— Augıʇǝɥʇuʎs

4

CJam + AlphaBeta , 62 byte


Lettere, CJam , 12 byte

"[{"{,-26>}/

Provalo online!

Produzione

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

Come funziona

"[{"{     }/   For each of the characters "[" and "{",
     ,         push an array of all ASCII characters before it
      -26>     and discard all but the last 26 characters.

Simboli, AlphaBeta , 50 byte

ZaaAccctFUaCLOrEbbCLbCLbCLbCLdddACLbCLbCLgDLgDLgDL

Provalo online!

L'interprete ufficiale C ++ ha un bug che rende impossibili i loop e non riesco a capire come usare l'interprete Lua. Ho corretto quel bug. È possibile verificare che funzioni come previsto eseguendo i programmi di esempio dalla pagina EsoLang.

Produzione

!"#$%&'()*+,-./0123456789:;<=>?@~}|{]\[^_`

Come funziona

Z      Switch register 4 to the position register.
aa     Set registers 1 to 2.
A      Copy the value from register 1 to register 2.
ccc    Add 30 to register 1 (result: 31).
tF     Set register 2 to the product of registers 1 and 2 (result: 64).
U      Add 10 to the position register (result: 10, i.e., the position of the next byte).
aCL    Add 1 to register 1 and print the corresponding ASCII character.
O      If register 1 != register 2, go to the position in the position register.
rEb    Set register 1 to the sum of registers 1 and 2 minus 1 (result: 127).
bCL    Subtract 1 from register 1 and print the corresponding ASCII character.
bCL    Subtract 1 from register 1 and print the corresponding ASCII character.
bCL    Subtract 1 from register 1 and print the corresponding ASCII character.
bCL    Subtract 1 from register 1 and print the corresponding ASCII character.
ddd    Subtract 30 from register 1 (result: 93).
A      Copy the value from register 1 to register 2.
CL     Print the ASCII character corresponding to register 1.
bCL    Subtract 1 from register 1 and print the corresponding ASCII character.
bCL    Subtract 1 from register 1 and print the corresponding ASCII character.
gDL    Add 1 to register 2 and print the corresponding ASCII character.
gDL    Add 1 to register 2 and print the corresponding ASCII character.
gDL    Add 1 to register 2 and print the corresponding ASCII character.

3

Parte 1 in BrainFuck: 80 74 byte

>-[+>+<[+<]>]>+.<<+++++[>+++++[>+.<-]<-]>>+++++++.<<+++++[>+++++[>+.<-]<-]

Potresti aver perso il primo a >causa del rientro del codice mancante. Quindi è reso come una citazione.
— Falko,

@Falko Grazie per averlo notato, mi sono perso.
— spocota il

3

Totale 318 byte

Speravo davvero di trovare una risposta con entrambi i programmi nella stessa lingua, ma finora niente. Ecco invece questo:

Parte 1: bash puro, 129 byte

_0=`$ 2>&1`
_0=${_0##*:}
_1=${_0:5:1}
_5=${_0:1:1}$_1${_0:11:1}
. <($_5<<<_2=\({${_1^}..$_1}\))
_3=${_2[@]:0:26}
$_5<<<$_3${_3,,}

Produzione:

$ ./letsym.sh
A B C D E F G H I J K L M N O P Q R S T U V W X Y Za b c d e f g h i j k l m n o p q r s t u v w x y z
$ 

Parte 2: GNU cc, 189 byte

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzzzzzzzzzzzzzzzzzzzzzzzzzzzPzzPzzPzzPzzPzzPzzBDPBEdPBFPdkvZP

Produzione:

$ dc symlet.dc
!"#$%&'()*+,-./0123456789:;<=>?@[\]^_`{|}~$ 

2

Beh, sai, qualcuno dovrebbe farlo andare avanti.

Parte 1 in BrainFuck: 174 byte

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+++++++
.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.

1

Parte 1: Ruby, 45 byte

_=[*?@...?[,*?`...?{]
_[0],_[27]=*$_
$><<_*''

Spiegazione

  • Un intervallo contenente az ( ?@...?[) e un intervallo contenente AZ ( ?`...?{) diventano gli elementi dell'array_ usando l'operatore splat (* ).
  • Il 0 ° elemento ( "@") e il 27 ° elemento ( "`") dell'array _sono impostati su nil.
  • La matrice _viene unita usando Array#*e stampata su stdout ( $>)

È possibile sostituire *$_sulla seconda riga con p(o []).
— Giordania,
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.