-4
\$\begingroup\$

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
\$\endgroup\$
  • \$\begingroup\$ I suppose modulo is counted as an arithmetic operation? \$\endgroup\$ – Kyle Kanos Jan 7 '14 at 2:14
  • \$\begingroup\$ yep. it is. @KyleKanos \$\endgroup\$ – belvi Jan 7 '14 at 2:15
  • \$\begingroup\$ Does it have to be a function, or just an operation \$\endgroup\$ – scrblnrd3 Jan 7 '14 at 2:17
  • 2
    \$\begingroup\$ 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? \$\endgroup\$ – user8777 Jan 7 '14 at 2:34
  • 3
    \$\begingroup\$ @MistressDavid Becuase it is a very ill-defined problem. For starters, rules 2 and 3 are contradictory. \$\endgroup\$ – user8777 Jan 7 '14 at 2:52
3
\$\begingroup\$

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.
|improve this answer|||||
\$\endgroup\$
2
\$\begingroup\$

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...

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ I'd say mod is an arithmetic operation. \$\endgroup\$ – marinus Jan 7 '14 at 2:35
  • 1
    \$\begingroup\$ @marinus I'd also say that performing a network request to a site isn't. Very rule bendy, but not breaking. \$\endgroup\$ – user8777 Jan 7 '14 at 2:37
  • \$\begingroup\$ 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... \$\endgroup\$ – WallyWest Jan 7 '14 at 5:08
1
\$\begingroup\$

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.

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

PHP, 38 chars

function m($a,$b){return fmod($a,$b);}
|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ modulo is an arithmetic operation... \$\endgroup\$ – Kyle Kanos Jan 7 '14 at 2:18
  • \$\begingroup\$ I thought it just meant that there could be no arithmetic operators \$\endgroup\$ – scrblnrd3 Jan 7 '14 at 2:19
  • 1
    \$\begingroup\$ Literal reading has it say, "no arithmetic operations". This basically means we have to do some bit shifting. \$\endgroup\$ – Kyle Kanos Jan 7 '14 at 2:20
  • \$\begingroup\$ And now functions have been eliminated. \$\endgroup\$ – Kyle Kanos Jan 7 '14 at 2:22
  • 5
    \$\begingroup\$ Hard to write when the rules are constantly changing \$\endgroup\$ – scrblnrd3 Jan 7 '14 at 2:25
0
\$\begingroup\$

Python 2.7 - 67 chars

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

Old answer 87:

Takes a string input and aside from converting it to numbers does no numeric manipulation. The asterisk looks like a multiplication sign, but its actually repeated string concatenation ;)

n,d=raw_input().split('/')
x="."*int(n)
d=int(d)
while len(x)>d:
 x=x[d:]
print len(x)
|improve this answer|||||
\$\endgroup\$

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