Get the remainder of a mathematical division without using any arithemetic operation [closed]

Write a code that will display the remainder of a division. Code with shortest byte wins.

Rules:

• No arithmetic operation whatsoever should be in your code
• No use of functions or methods
• If you are using a function or method, it has to be written by you also

Samples:

Sample1: 9/3
Result1: 0


Sample2: 7/2
Result2: 1

• I suppose modulo is counted as an arithmetic operation? – Kyle Kanos Jan 7 '14 at 2:14
• yep. it is. @KyleKanos – belvi Jan 7 '14 at 2:15
• Does it have to be a function, or just an operation – scrblnrd3 Jan 7 '14 at 2:17
• If you are using a function or method, it has to be written by you also So we have to take input of the form "x/y" and also write our own string to integer converter? – user8777 Jan 7 '14 at 2:34
• @MistressDavid Becuase it is a very ill-defined problem. For starters, rules 2 and 3 are contradictory. – user8777 Jan 7 '14 at 2:52

J (23)

f=:4 :'##~,-.(-y)>\x#1'


e.g.

   f=:4 :'##~,-.(-y)>\x#1'
9 f 3
0
7 f 2
1


How it works:

• x#1: make a list of 1s as long as the left argument (x)
• (-y)>\: divide the list into a y-row (right arg) matrix, padding with zeroes.
• -.: negate the list (so the padding is 1)
• ,: flatten the matrix
• #~: replicate each number by itself (so all the zeroes disappear and all the ones remain)
• #: count how long the list is now.

CMD - 48 chars

start "" "http://google.com/search?q=%1 %%25 %2"


This program leverages the power of the mighty Google to calculate the result. Very rule bendy...

• I'd say mod is an arithmetic operation. – marinus Jan 7 '14 at 2:35
• @marinus I'd also say that performing a network request to a site isn't. Very rule bendy, but not breaking. – user8777 Jan 7 '14 at 2:37
• Also the % characters used in this are not modulo's but used as character substitutions... %1 and %2 substitute the first and second number; while %%25 substitutes the % sign itself... so technically, the use of %%25 is valid in the actual code itself... – WallyWest Jan 7 '14 at 5:08

Perl, 46 chars

The challenge is kind of vague, but if string manipulation and regexps are allowed, this should work:

($_,$x)=map$"x$_,split"/",<>;s/$x//g;say y///c  This code reads a line of the form 7/3 from stdin, and outputs the remainder of the division (in this case 1). Needs Perl 5.10+ and the -M5.010 (or -E) switch for the say feature. PHP, 38 chars function m($a,$b){return fmod($a,\$b);}

• modulo is an arithmetic operation... – Kyle Kanos Jan 7 '14 at 2:18
• I thought it just meant that there could be no arithmetic operators – scrblnrd3 Jan 7 '14 at 2:19
• Literal reading has it say, "no arithmetic operations". This basically means we have to do some bit shifting. – Kyle Kanos Jan 7 '14 at 2:20
• And now functions have been eliminated. – Kyle Kanos Jan 7 '14 at 2:22
• Hard to write when the rules are constantly changing – scrblnrd3 Jan 7 '14 at 2:25

Python 2.7 - 67 chars

n,d=raw_input().split('/')
d=-int(d)
print range(int(n))[d::d][-1]


n,d=raw_input().split('/')