-6
\$\begingroup\$

Introduction

OnePlus is a Chinese smartphone manufacturer founded in December 2013. Their latest phone, OnePlus 5, was unveiled on June 20, 2017.

I am sure you have seen that the name of the phone can easily be translated to a sum.

OnePlus can be written like 1+ thus OnePlus 2 = (1+ 2) = 3

Input

The name of one OnePlus phone. The above list in the only possible input

OnePlus 1
OnePlus 2
OnePlus X
OnePlus 3
OnePlus 3T
OnePlus 5

Output

The sum of the name (a number not a string)

OnePlus 1 => 2
OnePlus 2 => 3
OnePlus X => an integer
OnePlus 3 => 4
OnePlus 3T => 27 (T = Today = 23 thus 1+3+23=27)
OnePlus 5 => 6 

Rules

The input can be written in different versions. This applies to every names. For example

OnePlus 1
OnePlus1
One+ 1
One+1
1+ 1
1+1
  • The output for OnePlus X is an integer that should be different from the other phones names. Whatever you want except 2,3,4,27,6
  • The T in OnePlus 3T will always be 23 which is the day I am posting this.
  • This is , so the shortest solution (in bytes) wins.
\$\endgroup\$
  • \$\begingroup\$ Is One case-sensitive? What about inputs like One + 1(arbitrary number of spaces between the tokens)? \$\endgroup\$ – officialaimm Jun 23 '17 at 7:46
  • \$\begingroup\$ Do we have to support all different versions? \$\endgroup\$ – Erik the Outgolfer Jun 23 '17 at 7:51
  • \$\begingroup\$ @officialaimm One and Plus are case-sensitive. You only have to rely to the provided format \$\endgroup\$ – Weedoze Jun 23 '17 at 8:28
  • 1
    \$\begingroup\$ Can the being considered advertisement? Or Spam? \$\endgroup\$ – sergiol Jun 23 '17 at 9:29
  • 1
    \$\begingroup\$ @sergiol I am not linked. Sorry for the bad English hehe \$\endgroup\$ – Weedoze Jun 23 '17 at 9:47
1
\$\begingroup\$

05AB1E, 10 bytes

0Uθ.VT26:>

Try it online!

θ has been replaced by ®è on TIO since it hasn't been pulled there yet. Alternatively, ¤ would work too.

Explanation:

0Uθ.VT26:> "Accepts a single line from STDIN"\
0          "Push 0"\
 U         "Assign to X"\
  θ        "(implicit input)"\ "Take the last element"\
   .V      "Eval as 05AB1E code"\
     T     "Push 10"\
      26   "Push 26"\
        :  "Infinitely replace"\
         > "Increment"\
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Though the question is not so clear, in your solution, OnePlus 4T is outputting same as OnePlus 3T \$\endgroup\$ – officialaimm Jun 23 '17 at 8:04
  • 5
    \$\begingroup\$ @officialaimm I don't think we'll ever get such input. \$\endgroup\$ – Erik the Outgolfer Jun 23 '17 at 8:07
3
\$\begingroup\$

Retina, 26 16 bytes

-10 bytes thanks to @MartinEnder

O
1
T
995
.
$*
1

Try it online!

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ The best way to write a test suite is to put %(G` in the header, which simply applies the program to each line individually. You can shorten \D\n\n\d to . and the final stage to a simple 1: tio.run/##K0otycxL/K@q4Z7w35/LkCuEy9LSlEuPS0WLy/D/f/… \$\endgroup\$ – Martin Ender Jun 23 '17 at 8:16
  • \$\begingroup\$ @MartinEnder thanks a lot. \$\endgroup\$ – ovs Jun 23 '17 at 8:26
1
\$\begingroup\$

Perl 5, 21 bytes

20 bytes of code + -p flag.

$_=/\d$/?$&+1:27*/T/

Try it online!

If the input ends with an integer (/\d$/), then we add one to it ($&+1) and outputs it. Otherwise, we output 27*/T/ which is 27 if the inputs contains a T, and 0 otherwise.

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

C# (.NET Core), 138 bytes

using System.Linq;s=>s.Replace("One","1").Replace("Plus","+").Replace("T","+23").Replace("X","9").Split('+').Select(e=>int.Parse(e)).Sum()

Try it online!

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ It's a lot shorter to just check the last character of the input. Is it a digit: output that digit + 1; is it T: output 27; else / is it X: output an unique digit like 0 or 9. \$\endgroup\$ – Kevin Cruijssen Jun 23 '17 at 13:10
0
\$\begingroup\$

Java 8, 79 61 bytes

s->{int x=s.charAt(s.length()-1);return x<58?x-47:x<85?27:9;}

Explanation:

Try it here with all possible test cases.

s->{                             // Method with String parameter and integer return-type
  int x=s.charAt(s.length()-1);  //  Get the last characters of the input
  return x<58?                   //  If it's a digit:
          x-47                   //   Return that digit + 1
         :x<85?                  //  Else if it's a 'T':
          27                     //   Return 27
         :                       //  Else (it's a 'X')
          9;                     //   Return 9 (unique digit other than 2,3,4,6,27)
}                                // End of method
| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

C (gcc), 65 63 48 bytes

f(char*s){s+=strlen(s)-1;s=*s?*s^84?*s-47:27:9;}

Try it online!

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Excel VBA, 87 51 bytes

Anonymous VBE immediate window function that takes input from cell [A1] and outputs OnePlus math to the VBE immediate window

i=Asc(Right([A1],1)):?IIf(i<58,i-47,IIf(i<85,27,9))

Old Version

Anonymous VBE immediate window function that takes input from cell [A1] that and outputs OnePlus math to the VBE immediate window

?Application.Evaluate("="&Replace(Replace(Replace([A1],"One",1),"Plus","+"),"T","+23"))

Input/Output

As a result of the Application.Evaluate call this solution is afforded access to all of the Excel WorkSheet Functions

[A1]="OnePlus 3T"
?Application.Evaluate("="&Replace(Replace(Replace([A1],"One",1),"Plus","+"),"T","+23"))
 23

[A1]="OnePlusPi()"
?Application.Evaluate("="&Replace(Replace(Replace([A1],"One",1),"Plus","+"),"T","+23"))
 4.14159265358979

[A1]="One+Day(Now())"
?Application.Evaluate("="&Replace(Replace(Replace([A1],"One",1),"Plus","+"),"T","+23"))
 26
| improve this answer | |
\$\endgroup\$

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