Mixed Number to an Improper Fraction

19

1

Mixed Number to an Improper Fraction

In this challenge you will be converting a mixed number to an improper fraction.

Because improper fractions use fewer numbers, your code will need to be as short as possible.


Examples

4 1/2
9/2

12 2/4
50/4

0 0/2
0/2

11 23/44
507/44

Specification

You may assume the denominator of the input will never be 0. The input will always be in the format x y/z where x,y,z are arbitrary nonnegative integers. You do not need to simplify the output.


This is so shortest code in bytes wins.

Downgoat

Posted 2015-12-17T18:02:34.693

Reputation: 27 116

1Related. Related. Related. (More or less. These are all about mixed fractions.) – Martin Ender – 2015-12-17T18:10:22.717

5You should add the tag "parsing". I'm sure most answers will spend more bytes on parsing the input and formatting the output than on doing the math. – nimi – 2015-12-17T18:31:32.517

3Can the output be a rational number type or does it have to be a string? – Martin Ender – 2015-12-17T18:33:00.807

@nimi Parsing isn't the primary goal of the challenge though. – Alex A. – 2015-12-17T18:33:40.077

2@AlexA.: ... but a large part of the challenge. According to it's description the tag should be used in such cases. – nimi – 2015-12-17T18:38:26.003

7Can x, y and z be negative? – Dennis – 2015-12-17T19:21:28.913

@Dennis no, it can't – Downgoat – 2015-12-17T22:50:14.163

Is it okay to output 0 for the third test case? – LegionMammal978 – 2015-12-17T23:10:05.290

1Is the output format strict, or is the numerator on one line and the denominator on another line acceptable (i.e., instead of a / between, it's a newline)? – AdmBorkBork – 2015-12-18T13:39:56.547

Can we take the input as an array of ASCII values? (This is basically what strings are in C). – Esolanging Fruit – 2017-07-13T06:14:08.097

@Challenger5 If your language is natively uses pointers for strings, you can take it in as a null-terminated string (array of ascii-values) – Downgoat – 2017-07-13T06:15:13.230

@Downgoat Well it's not actually a C submission, I just added that as justification for why it should be allowed. – Esolanging Fruit – 2017-07-13T06:16:06.087

@Challenger5 If your language is JS/Python/Java/one which has a native string datatype a string is a string so you can't take an array of integers for example in those languages. – Downgoat – 2017-07-13T06:16:57.077

@Downgoat Mine has no string datatype, only arrays and numbers. – Esolanging Fruit – 2017-07-13T06:33:07.120

@Downgoat Actually, can I assume it's null terminated anyways? (This is a stretch but it's helpful for golfing) – Esolanging Fruit – 2017-07-13T07:11:36.713

2Based on the challenge I'm assuming it is, but is the input format "x y/z" mandatory, or can the space be a new-line, and/or the x,y,z be separated inputs? Most answers are assuming the input format is indeed mandatory to be x y/z, but some aren't, hence this question to have a definitive answer. – Kevin Cruijssen – 2018-06-15T13:04:22.037

@KevinCruijssen Well, the question body does mention The input will always be in the format x y/z, so I think it's mandatory (although that's not very recommended). – Erik the Outgolfer – 2018-06-16T23:01:02.067

Answers

1

Japt, 10 bytes

Woohoo, currently beating CJam!

U*W+V+'/+W

Try it online!

How it works

       // Implicit: [U,V,W] = eval(input). This automatically discards the slash.
U*W+V  // Calculate the new numerator: (whole part * denominator) + numerator.
+'/+W  // Add the slash and the denominator.
       // Implicit: output last expression

ETHproductions

Posted 2015-12-17T18:02:34.693

Reputation: 47 880

I spent a good bit of time yesterday trying to figure out how I had earned 15 rep off of an answer, until I realized: my first green checkmark! \o/ – ETHproductions – 2015-12-21T22:40:29.777

8

LabVIEW, 29 LabVIEW Primitives

Eumel

Posted 2015-12-17T18:02:34.693

Reputation: 2 487

7

CJam, 16 15 14 bytes

l'/']er~:Xb'/X

or

l'/']er~_@b'/@

Test it here.

Explanation

l      e# Read input.
'/']er e# Replace the "/" with a "]".
~      e# Evaluate the string as code. If the input was "i n/d", this pushes [i n] d.
:X     e# Store the denominator in X.
b      e# Treat [i n] as base-d digits. This effectively computes i*d + n.
'/     e# Push a slash.
X      e# Push the denominator.

The other version avoids using a variable by using a bit more stack shifting.

Martin Ender

Posted 2015-12-17T18:02:34.693

Reputation: 184 808

I really need to start using base conversion in CJam more. – Esolanging Fruit – 2017-07-13T07:15:06.037

An alternate version: '//~\S/1$b'/@, this is 13 bytes. Edit: oh I forgot the input l. – Chromium – 2018-06-15T02:40:00.010

4

Mathematica, 58 bytes

ToExpression@StringReplace[#," "->"+"]~ToString~InputForm&

This returns the simplified result. If outputting a rational number instead of a string is fine, we can save 19 bytes:

ToExpression@StringReplace[#," "->"+"]&

Martin Ender

Posted 2015-12-17T18:02:34.693

Reputation: 184 808

4

PowerShell, 47 44 42 Bytes

Crossed out 44 is still regular 44 ;(

$l,$n,$d=$args-split'\D';"$(+$l*$d+$n)/$d"

Golfed a couple bytes by using regex -split. Golfed a couple more thanks to TessellatingHeckler by swapping the regex.

The $args-split'\D' takes our input argument and splits on non-digit characters. Here it performs two splits, one on whitespace, the other on the / character. The results are then stored in the three variables using a simultaneous assignment. We then formulate the string output as (the $left number times the $denominator plus the $numerator) executed as a code block, a / slash, and then the $denominator again.

AdmBorkBork

Posted 2015-12-17T18:02:34.693

Reputation: 41 581

Hi, I think you can do -split ' |/' to save one character with a "match either this|or that" regex, or use -split '\D' to split on anything which isn't a digit and s(h)ave two characters. If @Downgoat is willing to be slightly flexible on the output format, '{0}*{2}+{1};{2}'-f($args-split'\D')|iex is 40 bytes and has much cooler output because the numbers are even one above the other! – TessellatingHeckler – 2015-12-18T03:03:07.113

1@TessellatingHeckler Thanks for the regex assist. I've asked Downgoat for input. But $l,$n,$d=$args-split'\D';+$l*$d+$n;$d is shorter yet at 37, and logically follows the same pattern as here. – AdmBorkBork – 2015-12-18T13:48:39.667

Oh yeah, just math! (That would be enough to beat a Perl answer, too) – TessellatingHeckler – 2015-12-18T14:35:56.803

3

Java with Ten Foot Laser Pole 1.03, 79+25 (import) = 104 bytes

Requires import sj224.tflp.math.*;

String m(String[]a){return ""+new BigRational(a[0]).add(new BigRational(a[1]));}

This will almost certainly work with 1.04 as well, but so far I've only tested it with 1.03 because I already happened to have a java project set up with 1.03 in the build path.

SuperJedi224

Posted 2015-12-17T18:02:34.693

Reputation: 11 342

3

JavaScript (ES6), 44 41 bytes

m=>([x,y,z]=m.match(/\d+/g),+y+x*z+"/"+z)

Saved 3 bytes thanks to @ETHproductions!

Explanation

Very simple.

m=>
  ([x,y,z]=m.match(/\d+/g), // x, y and z = numbers from input
    +y+x*z                  // numerator
    +"/"+z                  // denominator
  )

Test

Test is without destructuring assignment to work in most browsers.

var solution = m=>+(p=m.match(/\d+/g))[1]+p[0]*p[2]+"/"+p[2]
<input type="text" id="input" value="11 23/44" />
<button onclick="result.textContent=solution(input.value)">Go</button>
<pre id="result"></pre>

user81655

Posted 2015-12-17T18:02:34.693

Reputation: 10 181

Nice! You can use [p,q,r]= in place of p=, then replace p[0], p[1], and p[2] with p, q, and r, respectively. After this change, I get 41:m=>([p,q,r]=m.match(/\d+/g),+q+p*r+"/"+r) – ETHproductions – 2015-12-18T02:37:01.367

@ETHproductions Thanks for the tip! I actually did consider using a destructuring assignment but they don't work in Chrome and I didn't have Firefox on hand to test it. :P – user81655 – 2015-12-18T03:03:22.753

My first crossed out 44! :D – user81655 – 2015-12-18T03:04:08.317

You can use m.split(/\W/g) instead to save a byte – user41805 – 2018-06-11T14:08:01.210

2

Haskell, 74 67 63 bytes

r=read
f x|(a,(c,s:d):_)<-lex<$>lex x!!0=show(r a*r d+r c)++s:d

Try it online!

Explanation

As H.PWiz figured out we can use Haskell's lexer here to break up the string into it's parts. (Earlier I was using span(>'/')) And Laikoni pointed out that <$> works just like mapSnd from Data.Tuple.

The pattern guard breaks up our code into the three numbers we want using lex. lex invokes haskell's lexer to break off the first token. It returns a list with each element representing a possible way to parse the string. These elements are tuples with the first element being the first token and the rest of the string being the second element. Now since the input format is very regular we are only ever going to have exactly one parse, so we can always take the first one. The first thing we do is invoke lex on the input

lex x

Then we unwrap it from it's list giving us a 2-tuple

lex x!!0

The first token will be the whole part of the mixed fraction leaving the fraction prepended by a space to still parse. Then since tuples are Functors we can use (<$>) an alias for fmap to apply lex to the second element of the tuple.

lex<$>lex x!!0

This eats through the space and breaks off the next token, the numerator of our fraction. Now we bind this to a pattern match using <-. Our pattern is

(a,(c,s:d):_)

a grabs the whole part of the fraction, our first token. :_ unwraps the list resulting from our second lex. c grabs the second token we lexed, that is the numerator of the fraction. Everything that remains is bound to s:d which splits it into its first character, guaranteed by the format to be a / and the remainder which will be the denominator.

Now that we have parsed the input we do the actual computation:

show(r a*r d+r c)++s:d

Where r is the read function we bound earlier.

It is important to note that lex returns a list empty if it fails and non-empty if it succeeds. Why this is not a Maybe I do not know.

Post Rock Garf Hunter

Posted 2015-12-17T18:02:34.693

Reputation: 55 382

167 bytes – H.PWiz – 2018-06-15T02:01:53.717

@H.PWiz That is a great use of lex. – Post Rock Garf Hunter – 2018-06-15T02:03:14.390

lex is just a handy, rarely used function that splits a string into the first token and the rest. It returns as a list, so it can fail with [] – H.PWiz – 2018-06-15T02:04:48.713

@H.PWiz Do you know why it doesn't return a Maybe? – Post Rock Garf Hunter – 2018-06-15T02:05:24.533

No, I don;t know a whole lot about it. It uses Reads, which I am somewhat ignorant of – H.PWiz – 2018-06-15T02:13:16.713

Ok, thanks for the tip, I'll snoop around to find out for myself. I do think ReadS is just a type alias btw. – Post Rock Garf Hunter – 2018-06-15T02:14:46.863

2

65 bytes: Try it online!

– Laikoni – 2018-06-15T05:19:44.293

2

You should be able to save another 2 by matching on the /

– H.PWiz – 2018-06-15T09:38:21.697

159 bytes – H.PWiz – 2018-07-09T05:17:56.623

bump ^ .-.-.-.-.- – H.PWiz – 2018-07-24T22:43:27.543

@H.PWiz tbh, I think that could be it's own answer. – Post Rock Garf Hunter – 2018-07-25T02:50:15.473

2

Bash + coreutils, 28

dc<<<${@/\// }sarla*+n47Plap

$@ expands to all command-line parameters, so ${@/\// } expands to all command-line parameters with / replaced with , which is put on dc's stack. The rest is simple stack manipulation and arithmetic.

Digital Trauma

Posted 2015-12-17T18:02:34.693

Reputation: 64 644

2

Julia, 58 50 bytes

s->eval(parse((r=replace)(r(s," ","+"),"/","//")))

This is an anonymous function that accepts a string and returns a Rational type object. To call it, give it a name, e.g. f=s->....

We can take advantage of the fact that the input can be manipulated slightly to be an expression that evaluates to a rational. In particular, an integer plus a rational is a rational, and rationals are denoted with double slashes. So if we turn 4 1/2 into 4+1//2, the evaluated result will be 9//2.

Ungolfed:

function f(s::AbstractString)
    # Replace the space in the input with a plus
    r1 = replace(s, " ", "+")

    # Replace the / with //
    r2 = replace(r1, "/", "//")

    # Parse the resulting expression as a rational
    return eval(parse(r2))
end

Alex A.

Posted 2015-12-17T18:02:34.693

Reputation: 23 761

2

Smalltalk – 76 characters

The input exactly matches the array delimiter and inherent fraction representation of Smalltalk. If it just weren't so verbose, it could have been a serious contender!

Compiler evaluate:'|p|p:=0.#(',FileStream stdin nextLine,')do:[:q|p:=p+q].p'

It's too bad simplification wasn't a requirement, Smalltalk does it automatically!

user15259

Posted 2015-12-17T18:02:34.693

Reputation:

1

05AB1E, 17 15 bytes

#`'/¡R`Š©*+®'/ý

-2 bytes thanks to @MagicOctopusUrn.

Try it online or verify all test cases.

Explanation:

#`         # Split input by spaces and push all items to the stack
           #  i.e. "4 1/2" → "4" and "1/2"
  '/¡      # Push the second item by "/"
           #  i.e. "1/2" → [1,2]
     R`    # Revert the list, and also push all items to the stack
           #  i.e. [1,2] → [2,1] → 2 and 1
Š          # Triple-swap the stack
           #  [4,2,1] → [1,4,2]
 ©         # Store the 2 in the register
  *        # Multiple the top two items
           #  4 and 2 → 8
   +       # Add the top two items
           #  1 and 8 → 9
®          # Push the 2 from the register to the stack again
 '/ý       # Join the two items by "/"
           #  9 and 2 → "9/2"

With flexible input- and output-format, taking the integers in the order x,z,y and outputting the nominator and denominator on separated lines it would be 4 bytes (which is why I added the -tag to the challenge..):

*+²»

Try it online or verify all test cases.

Explanation:

*        # Multiply the first two inputs (x and z)
         #  i.e. 4 and 2 → 8
 +       # Add the third input (y)
         #  i.e. 8 and 1 → 9
  ²      # Take the second input again (z)
   »     # Join the stack by newlines and implicitly print it

Kevin Cruijssen

Posted 2015-12-17T18:02:34.693

Reputation: 67 575

@MagicOctopusUrn Thanks, but the input-format is different than in the challenge description. Apparently the format (as single string) 4 1/2 is mandatory for this particular challenge. Otherwise I would have used my 4-byte version (or if output was mandatory, but input flexible I would use this 6-byter: *+'/²J)

– Kevin Cruijssen – 2018-06-15T13:02:31.963

115-bytes – Magic Octopus Urn – 2018-06-15T13:05:59.883

@MagicOctopusUrn Oh, didn't even knew about "Push all the items of a into the stack".. o.Ô Exactly what I needed for this challenge! And smart with the join by "/". Thanks! :) – Kevin Cruijssen – 2018-06-15T13:16:25.030

I hate using the "Push all items of a into the stack" command because it's "`" and it can't be tamed by inline code-tags. – Magic Octopus Urn – 2018-06-15T13:17:31.880

@MagicOctopusUrn yeah, it's also a bit annoying in comments (which is why I quoted "Push all the items of a into the stack" instead of using '`'.. – Kevin Cruijssen – 2018-06-15T13:18:59.217

@MagicOctopusUrn Using ' instead of tile it would be: ''>'<''. Unfortunately it doesn't work with just a tile and spaces, so it has to be surrounded by other text to use the double-tile. – Kevin Cruijssen – 2018-06-15T13:20:06.587

''Oh man, yesss, I've needed this like 10 times'' – Magic Octopus Urn – 2018-06-15T13:20:28.147

1

ARBLE, 13 bytes

a*c+b.."/"..c

Try it online!

ATaco

Posted 2015-12-17T18:02:34.693

Reputation: 7 898

I'm pretty sure the input format "x y/z" is mandatory for this particular challenge, but just in case I've asked OP to verify. – Kevin Cruijssen – 2018-06-15T13:05:58.150

1

Perl 5 with -la -Mfeature=say, 32 bytes 25 bytes

m|/|;say$_*$'+$F[1],"/$'"

Try it online!

(-7 bytes thanks to Dom Hastings)

$_ is the whole input x y/z, which evaluates the value of x in numeric contexts (like the * here). $' is the regex post-match string, which here contains whatever comes after / - so, z. To get the y value, we use the -a flag which splits the input on spaces and places them in the @F array. So here, @F = ("x", "y/z"), which means $F[1]="y/z" which evaluates in y in numeric contexts (since y is the initial contiguous sequence of digits with $F[1]).

sundar - Reinstate Monica

Posted 2015-12-17T18:02:34.693

Reputation: 5 296

You do not have to count the -p flag in your byte count; instead you count the language as Perl 5 with -p flag, 32 bytes. See this meta post for the current consensus.

– Giuseppe – 2018-06-16T10:53:44.703

Nice approach! I just had a little go at this and managed to make a 25 byte version: Try it online!. Using $' was the only real difference there really!

– Dom Hastings – 2018-06-21T20:48:56.420

The combination of using both regex-$' and -a-$F[n] to get parts of the string is a pretty good idea, I have to remember that! Thanks, updated the post. – sundar - Reinstate Monica – 2018-06-22T13:42:22.150

1

Python 3, 78 76 bytes

def f(s):a,b=s.split();b,c=b.split('/');return'%s/'%(int(a)*int(c)+int(b))+c

Try it online!

xbarbie

Posted 2015-12-17T18:02:34.693

Reputation: 91

return'%s/'%(int(a)*int(c)+int(b))+c is 2 bytes shorter – ovs – 2018-06-16T13:07:50.670

1

Stax, 1 byte

+

Run and debug it (although there's not much to debug)

The challenge specification says "You do not need to simplify the output." Assuming it's allowed to simplify, then there's a built-in instruction in stax to do this. The input is implicitly interpreted as an integer and a rational number. The + instruction widens both to rationals, adds, and simplifies. The result is implicitly printed.

recursive

Posted 2015-12-17T18:02:34.693

Reputation: 8 616

1

Perl, 82 61 38 bytes

#!perl -paF/\D/
$_=$F[0]*$F[2]+$F[1]."/$F[2]"

This can probably be golfed more.

Changes

  • Saved 16 bytes by using a regex in split, and 5 by using <> instead of <STDIN>.
  • Saved another 16 bytes thanks to Dennis.

ASCIIThenANSI

Posted 2015-12-17T18:02:34.693

Reputation: 1 935

With shebang #!perl -paF/\D/ (9 bytes), you can use $_=$F[0]*$F[2]+$F[1]."/$F[2]". – Dennis – 2015-12-17T19:27:55.597

@Dennis I've added that in. Thanks! – ASCIIThenANSI – 2015-12-17T19:33:45.610

The #!perl part of the shebang and the linefeed do not count. This is only 38 bytes. – Dennis – 2015-12-17T19:35:52.707

@Dennis Oh, OK. I'll correct it now. (On the bright side I think this is the second-shortest non-esoteric answer) – ASCIIThenANSI – 2015-12-17T19:37:37.953

1

Java, 159 148 142 120 110 bytes

String m(String[]a){Long b=new Long(a[0]),d=new Long((a=a[1].split("/"))[1]);return b*d+new Long(a[0])+"/"+d;}

Saved a bunch of bytes thanks to FlagAsSpam.

SuperJedi224

Posted 2015-12-17T18:02:34.693

Reputation: 11 342

@FlagAsSpam Done. – SuperJedi224 – 2015-12-17T23:49:31.820

@FlagAsSpam But then the variables will be left undeclared! – SuperJedi224 – 2015-12-17T23:50:43.013

Disregard all of what I just said - a short way doing what you're doing is Long b=new Long(a[0]),c=new Long((a=a[1].split("/"))[0]),d=new Long(a[1]); – Addison Crump – 2015-12-17T23:55:34.517

1

Javascript ES6, 62 bytes

p=prompt;b=p(a=+p()).split`/`;alert((+b[1]*a+ +b[0])+"/"+b[1])

SuperJedi224

Posted 2015-12-17T18:02:34.693

Reputation: 11 342

1Pretty nice! Some tips: You can use [b,c]= in place of b=, then use b in place of b[0] and c in place of b[1]. Also, you can rearrange the equation so you don't need parentheses at all: p=prompt;[b,c]=p(a=+p()).split/;alert(+b+c*a+"/"+c) – ETHproductions – 2015-12-18T02:32:47.783

1

Mathematica, 51 bytes

Interpreter["ComputedNumber"]@#~ToString~InputForm&

Interestingly, Mathematica supports this with a built-in. If outputting a number is allowed, than we only need 28 bytes:

Interpreter@"ComputedNumber"

LegionMammal978

Posted 2015-12-17T18:02:34.693

Reputation: 15 731

0

Check, 120 bytes

>]+>:>32r#v
#d@0+\)  ##:>4;:>5'=:>48-\R-?
dd)R>32-#v
#>15-#v  #?
47r@>@   #v
#dd#v #?
r@>@     #v
    #\d@\: @*@+pd"/"op

Try it online!

I might be able to save some bytes by not trying to reuse the parsing loop (the second line). That way I could make the loop more specific, avoid the huge mess of conditionals, and I could use the register for other things.

Esolanging Fruit

Posted 2015-12-17T18:02:34.693

Reputation: 13 542

0

Ruby, 23 bytes

->x{eval x.split*?++?r}

Try it online!

G B

Posted 2015-12-17T18:02:34.693

Reputation: 11 099

0

C#, 112 bytes

s=>{string[]a=s.Split(),b=a[1].Split('/');int o=int.Parse(b[1]);return int.Parse(a[0])*o+int.Parse(b[0])+"/"+o;}

Full/Formatted Version:

namespace System.Linq
{
    class P
    {
        static void Main()
        {
            Func<string, string> f = s =>
            {
                string[] a = s.Split(), b = a[1].Split('/');
                int o = int.Parse(b[1]);
                return int.Parse(a[0]) * o + int.Parse(b[0]) + "/" + o;
            };

            Console.WriteLine(f("4 1/2"));
            Console.WriteLine(f("12 2/4"));
            Console.WriteLine(f("0 0/2"));
            Console.WriteLine(f("11 23/44"));

            Console.ReadLine();
        }
    }
}

TheLethalCoder

Posted 2015-12-17T18:02:34.693

Reputation: 6 930

0

APL (Dyalog Unicode), 31 bytes

∊∘(⍕¨⊃,⍨'/',⍨⊃⊥1∘↓)¯1⌽#⍎¨∊∘⎕D⊆⊢

Try it online!

Thanks to ngn for the ⊃⊥1∘↓ trick

user41805

Posted 2015-12-17T18:02:34.693

Reputation: 16 320

0

PHP, 65 Bytes

Try it online

Code

<?=(($a=preg_split("/[\s,\/]/",$argv))[0]*$a[2]+$a[1])."/".$a[2];

Explanation

$a=preg_split("/[\s,\/]/",$argv); # Split the string on "/" and " "
(($a)[0]*$a[2]+$a[1]) # as always denominator*whole number + numerator 
."/"                  # echo an slash
.$a[2];               # echo de denominator

Francisco Hahn

Posted 2015-12-17T18:02:34.693

Reputation: 591

0

Java 10, 87 bytes

A lambda from String to String.

s->{var p=s.split(" |/");return new Long(p[0])*new Long(p[2])+new Long(p[1])+"/"+p[2];}

Try It Online

Jakob

Posted 2015-12-17T18:02:34.693

Reputation: 2 428

0

Ouroboros, 16 bytes

rr\r.@*@+n47on1(

Try it here!

Explanation

The reason why Ouroboros is great for this challenge: its integer-reading primitive, r, skips over any non-digit characters until it comes to a number. So no parsing is required; we just read three numbers and process them.

rr                Read the first two numbers
                   Stack: 11 23
  \r              Swap and read the third one
                   Stack: 44 23 11
    .             Duplicate
                   Stack: 44 44 23 11
     @            Rotate (moving third item to top of stack)
                   Stack: 23 44 44 11
      *           Multiply
                   Stack: 1012 44 11
       @+         Rotate and add
                   Stack: 1023 44
         n        Output as number
                   Stack: 44  Output: 1023
          47o     Push 47 and output as character
                   Stack: 44  Output: 1023/
             n    Output as number
                   Output: 1023/44
              1(  Terminate

DLosc

Posted 2015-12-17T18:02:34.693

Reputation: 21 213

0

C, 64

main(i,d,n){scanf("%d %d/%d",&i,&n,&d);printf("%d/%d",i*d+n,d);}

Reads input from STDIN. Fairly self-explanatory, I think.

Digital Trauma

Posted 2015-12-17T18:02:34.693

Reputation: 64 644

0

Lua, 123 Bytes

m=io.read()z=string x=z.find c=z.sub b=tonumber s=x(m," ")f=x(m,"/")d=c(m,f+1)print(b(c(m,1,s))*b(d)+b(c(m,s,f-1)).."/"..d)

Nikolai97

Posted 2015-12-17T18:02:34.693

Reputation: 653

0

Milky Way 1.6.0, 31 bytes

'" "\="/"\=>;<A;A;:>*;A+"/"+<+!

Ended up being much longer than I thought it would be.


Explanation

'" "\="/"\=>;<A;A;:>*;A+"/"+<+!

'                                # read input from the command line
 " "  "/"               "/"      # push a string to the stack
    \    \                       # split the STOS at the TOS
     =    =                      # dump the TOS to the stack
           >       >             # rotate the stack rightward
            ;  ; ;   ;           # swap the TOS and STOS
             <              <    # rotate the stack leftward
              A A     A          # push the integer representation of the TOS
                  :              # duplicate the TOS
                    *            # multiply the STOS by the TOS
                       +   + +   # add the TOS and STOS
                              !  # output the TOS

Usage

./mw <path-to-code> -i <input>

Zach Gates

Posted 2015-12-17T18:02:34.693

Reputation: 6 152

0

Python 2.7, 88 Bytes

a=input().split('/');print int(a[-1])*int(a[0].split()[0])+int(a[0].split()[1]),'/',a[1]

Try it online!

You have to type the input in quotes.

Probably not the best ...

Alex

Posted 2015-12-17T18:02:34.693

Reputation: 417

76 bytes – Koishore Roy – 2017-07-13T10:57:38.910