Baunilha C, 447 bytes
(Embrulhado para facilitar a leitura)
#include<stdio.h>
int main(int c,char**a){char*v=a[1];while(*v++);int m=0,i=
0,bn=0,s=0,b=0,mul=1;char l[256],*lp=l;v--;while(a[1]<v--)
{if(!m){i=!i?1:(i*10),('0'<=*v&&*v<='9')?(bn=bn+i*(*v-'0')
):m++;}if(m==1){(*v=='-'||*v==' ')?(s+=bn?((*v=='-')?2000:
1000):0,v--):0,m++;}if(m==2){(*v>='A'&&*v<='Z')?(s+=1000,*
v+=32):0,*lp++=*v;}}s+=(bn<10000)?bn:0;for(i=0;i<lp-l;i++)
{if(*(l+i)=="rotani"[i]){mul=(i==5)?3:((i==3)?2:mul);}}s*=
mul;printf("%d\n",s);}
... ou até ... sexta-feira!
(Não usei nenhuma ferramenta para aliar o código. Na verdade, tenho muita sorte de ter escolhido as larguras de coluna corretas, sem pré-cálculos. E até compila!)
Baunilha C, 789 bytes
#include<stdio.h>
int main(int c, char**a){char *v=a[1];while (*v++);int m=0,i=
0,bn=0, s=0, b=0, mul=1 ;char l[256], *lp=l;
v--; while (a[1]< v--) {if(! m){i=!i ?1:(i*
10), ('0' <=*v&& *v<= '9')? (bn=bn+ i*(*v-
'0')):m++;}if( m==1) {(*v== '-'|| *v== ' ')?(s +=bn?(
(*v=='-')?2000 :1000) :0,v-- ):0,m ++;} if(m==2 ){(*v
>='A'&& *v<= 'Z')? (s+= 1000, *v+=32) :0,*lp
++=* v;}}s +=(bn< 10000 )?bn: 0;for(i =0;i<
lp-l; i++){ if(*(l +i)== "rot" "ani"[i] ){mul=
(i==5) ?3: ((i ==3)?2:mul);} } s *= mul; printf("%d\n",s);}
Código original:
#include <stdio.h>
#include <math.h>
int main(int argc, char** argv) {
char *v = argv[1];
while(*v++);
int m=0,i=-1;
int bonus_number=0;
int score=0;
int b=0;
int mul=1;
char letters[256];
char* lp=letters;
v--;
while(argv[1]<v--) {
printf(" * %c %x\n", *v, *v);
if (m == 0) {
if ('0'<=*v&&*v<='9') {
bonus_number=bonus_number+powl(10,++i)*(*v-'0');
printf("Digit, bonus is now %d\n", bonus_number);
} else {
m++;
}
}
if (m == 1) {
if (*v=='-'||*v==' ') {
printf("Dash/space\n");
if (bonus_number) score += (*v=='-') ? 2000 : 1000;
v--;
}
m++;
}
if (m == 2) {
if(*v>='A'&&*v<='Z') {
printf("Upper letter\n");
score += 1000;
*v += 32;
}
*lp++ = *v;
}
}
score += (bonus_number<10000)?bonus_number:0;
for(i=0;i<lp-letters;i++) {
// printf("%d: %c\n\n", i, *(letters+i));
if (*(letters+i) == "rotani"[i]) {
if (i == 3) {
printf("2x!\n");
mul = 2;
}
if (i == 5) {
printf("3x!\n");
mul = 3;
}
}
}
score *= mul;
printf("Score: \n%d\n", score);
}
Após a 1ª minimização:
#include <stdio.h>
int main(int c, char** a) {
char *v = a[1];while(*v++);
int m=0,i=0,bn=0,s=0,b=0,mul=1;
char l[256],*lp=l;
v--;
while(a[1]<v--) {
if (!m) {
i=!i?1:(i*10),
('0'<=*v&&*v<='9') ? (bn=bn+i*(*v-'0')) : m++;
}
if (m == 1) {
(*v=='-'||*v==' ') ? (s += bn ? ((*v=='-') ? 2000 : 1000) : 0, v--):0,m++;
}
if (m == 2) {
(*v>='A'&&*v<='Z') ? (s += 1000, *v += 32):0,
*lp++ = *v;
}
}
s += (bn<10000)?bn:0;
for(i=0;i<lp-l;i++) {
if (*(l+i) == "rotani"[i]) {
mul=(i==5)?3:((i==3)?2:mul);
}
}
s *= mul;
printf("%d\n", s);
}
Casos de teste
#!/usr/bin/env python3
import subprocess
TESTCASES = '''
Burninator-3000 -> 18000
Burnator3000 -> 8000
BurNinator 100 -> 9300
BuRnInAtOr-7253 -> 42759
burn -> 0
burn- -> 0
bUrn-1 -> 3001
inator-7 -> 6021
ator 56 -> 2112
burninators 1000 -> 2000
burn_1000 -> 1000
BURNINATOR-9999 -> 65997
burninator 99999 -> 3000
burninator_99999 -> 0
Code Golfinator-3000 -> 21000
inator ator hello world-1000 -> 3000
javaiscool_99999 -> 0
hypen-ated -> 0
1000 -> 1000
-1000 -> 3000
10000 -> 0
-10000 -> 2000
BURN1N470R-3000 -> 11000
'''
TESTCASES = dict(map(lambda x: x.split(' -> '), filter(None, TESTCASES.split('\n'))))
def process(arg):
return subprocess.Popen(['./a.out', arg], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0].strip().split(b'\n')[-1].decode('utf-8')
for key, value in TESTCASES.items():
assert value == process(key), '"{}" should yield {}, but got {}'.format(
key, value, process(key)
)
inator ator hello world-1000
(ou semelhante) #