22
\$\begingroup\$

As everyone knows, adding inator-3000 to the end of any noun makes it way cooler. But what else can make a word cooler?

Given an ASCII string as input, output the coolness of the word.

Calculating the coolness

There are 4 elements to calculating the coolness of a word.

  • The word itself. The base score is the number of capital letters multiplied by 1000
  • The end number. A number at the end of the word (such as burninator-3000) is added to the base score, but if the number is more than 4 digits, they're being too greedy and the number should be ignored.
  • The connector. A space before the end number adds 1000, while a hyphen adds 2000, any other symbol, or no symbol at all, has no effect.
  • The suffix. If the word ends in ator, double the final score. If it ends in inator, triple the score. These are case insensitive.

So for example Burninator-3000 can be calculated as follows:

1 Capital letter - Base Score: 1000
(1000(base) + 3000(number) + 2000(hyphen)) * 3(suffix) = 18000

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

Scoring

This is , so fewest bytes in each language wins!

\$\endgroup\$
10
  • 3
    \$\begingroup\$ Test case: inator ator hello world-1000 (or similar) \$\endgroup\$ Jul 14 '17 at 8:55
  • \$\begingroup\$ @TheLethalCoder Added \$\endgroup\$
    – Mayube
    Jul 14 '17 at 8:56
  • \$\begingroup\$ @Mr.Xcoder not sure what it covers that hasn't already been covered, but it's funny so I'll add it anyway \$\endgroup\$
    – Mayube
    Jul 14 '17 at 9:13
  • \$\begingroup\$ Ok, now a helpful test case: 9028 and -7282 (Only digits) \$\endgroup\$
    – Mr. Xcoder
    Jul 14 '17 at 9:15
  • 1
    \$\begingroup\$ Isn't burninator 99999 3000 no 1000? Space adds 1000 and tripled for ending in inator. \$\endgroup\$ Jul 14 '17 at 9:25
13
\$\begingroup\$

JavaScript (ES6), 138 133 128 bytes

s=>(([,a,b,,c,d]=s.match(/((in)?ator)?((\D?)(\d+))?$/i),s.split(/[A-Z]/).length-1+(c=='-'?2:c==' '))*1e3+(d<1e4&&+d))*(b?3:2-!a)

How?

The number of capital letters is given by:

s.split(/[A-Z]/).length - 1

All other criteria are deduced from the result of the following regular expression, which is split into 4 variables:

/((in)?ator)?((\D?)(\d+))?$/i     criterion  | code                    | outcome
 \_________/  \___/\___/          -----------+-------------------------+----------
      a         c    d            end number | d < 1e4 && +d           | 0 or +d
  \___/                           connector  | c == '-' ? 2 : c == ' ' | 0, 1 or 2
    b                             suffix     | * (b ? 3 : 2 - !a)      | 1, 2 or 3

Test cases

let f =

s=>(([,a,b,,c,d]=s.match(/((in)?ator)?((\D?)(\d+))?$/i),s.split(/[A-Z]/).length-1+(c=='-'?2:c==' '))*1e3+(d<1e4&&+d))*(b?3:2-!a)

let test = s => console.log((s + ' '.repeat(32)).slice(0, 32), f(s));

test("Burninator-3000")               // -> 18000
test("Burnator3000")                  // -> 8000
test("BurNinator 100")                // -> 9300
test("BuRnInAtOr-7253")               // -> 42759
test("burn")                          // -> 0
test("burn-")                         // -> 0
test("bUrn-1")                        // -> 3001
test("inator-7")                      // -> 6021
test("ator 56")                       // -> 2112
test("burninators 1000")              // -> 2000
test("burn_1000")                     // -> 1000
test("BURNINATOR-9999")               // -> 65997
test("burninator 99999")              // -> 3000
test("burninator_99999")              // -> 0
test("Code Golfinator-3000")          // -> 21000
test("inator ator hello world-1000")  // -> 3000
test("javaiscool_99999")              // -> 0
test("hypen-ated")                    // -> 0
test("1000")                          // -> 1000
test("-1000")                         // -> 3000
test("10000")                         // -> 0
test("-10000")                        // -> 2000
test("BURN1N470R-3000")               // -> 11000

\$\endgroup\$
0
7
\$\begingroup\$

Vanilla C, 447 bytes

(Wrapped for readability)

#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);}

...or even... Friday mood!

(I didn't use any tools for alying the code. Actually, I'm really lucky I picked right column widths without any precalculations. And it even compiles!)

Vanilla 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);}

Original code:

#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);
}

After 1st minimization:

#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);
}

Test cases

#!/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)
    )
\$\endgroup\$
2
\$\begingroup\$

C#, 322 317 bytes

namespace System.Linq{s=>{var m=Text.RegularExpressions.Regex.Match(s,"(.*?)([- ])?(\\d+)$");string t=m.Groups[1].Value.ToLower(),c=m.Groups[2].Value,n=m.Groups[3].Value;return(s.Count(char.IsUpper)*1000+(n.Length>4|n==""?0:int.Parse(n))+(c==" "?1000:c=="-"?2000:0))*(t.EndsWith("inator")?3:t.EndsWith("ator")?2:1);}}

Try it online!

Full/Formatted Version:

namespace System.Linq
{
    class P
    {
        static void Main()
        {
            Func<string, int> f = s =>
            {
                var m = Text.RegularExpressions.Regex.Match(s, "(.*?)([- ])?(\\d+)$");
                string t = m.Groups[1].Value.ToLower(), c = m.Groups[2].Value, n = m.Groups[3].Value;

                return (
                           s.Count(char.IsUpper) * 1000 +
                           (n.Length > 4 | n == "" ? 0 : int.Parse(n)) +
                           (c == " " ? 1000 : c == "-" ? 2000 : 0)
                        )
                        * (t.EndsWith("inator") ? 3 : t.EndsWith("ator") ? 2 : 1);
            };

            string[] testCases =
            {
                "Burninator-3000", "Burnator3000", "BurNinator 100", "BuRnInAtOr-7253",
                "burn", "burn-", "bUrn-1", "inator-7", "ator 56", "burninators 1000",
                "burn_1000", "BURNINATOR-9999", "burninator 99999", "burninator_99999",
                "Code Golfinator-3000", "inator ator hello world-1000", "javaiscool_99999",
                "hypen-ated", "1000", "-1000", "10000", "-10000"
            };

            foreach (string testCase in testCases)
            {
                Console.WriteLine($"{testCase} -> {f(testCase)}");
            }

            Console.ReadLine();
        }
    }
}

Splitting the regex off into it's own method is now 4 bytes longer (unless I missed something) due to only being allowed one lambda. This it comes in at 321 bytes:

namespace System.Linq{string m(string s,int n)=>Text.RegularExpressions.Regex.Match(s,"(.*?)([- ])?(\\d+)$").Groups[1].Value.ToLower();s=>{string t=m(s,1),c=m(s,2),n=m(s,3);return(s.Count(char.IsUpper)*1000+(n.Length>4|n==""?0: int.Parse(n))+(c==" "?1000:c=="-"?2000:0))*(t.EndsWith("inator")?3:t.EndsWith("ator")?2:1);}}
\$\endgroup\$
2
  • \$\begingroup\$ I don't know if this is legal after that last meta post, but you do believe it is. Wouldn't another function like this b=c=>d=>c.Groups[d].Value save a bit? \$\endgroup\$
    – LiefdeWen
    Jul 14 '17 at 12:50
  • \$\begingroup\$ @LiefdeWen After the last meta post I believe I'd have to declare it as a full method. I could do string m(string s,int n)=>Text.RegularExpressions.Regex.Match(s,"(.*?)([- ])?(\\d+)$").Groups[n].Value.ToLower();string t=m(s,1),c=m(s,2),n=m(s,3); But I believe that then makes it 3 bytes more. \$\endgroup\$ Jul 14 '17 at 12:57
2
\$\begingroup\$

Perl, 108 bytes

107 bytes code + 1 for -p.

$\+=1e3*y/A-Z//;s/( |-)?(\d+)$//;$\+=$2*($2<1e4);$\+={$",1e3,"-",2e3}->{$1};s/(in)?ator$//i&&($\*=$1?3:2)}{

Try it online!

\$\endgroup\$
0
\$\begingroup\$

PHP>=7.1, 165 bytes

preg_match("#((in)?ator)?((\D)?(\d+))?$#i",$argn,$m);[,$a,$i,,$c,$d]=$m;echo($d*($d<1e4)+(preg_match_all("#[A-Z]#",$argn)+($c!="-"?$c==" "?:0:2))*1e3)*($a?$i?3:2:1);

Testcases

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.