20 language-agnostic code-golf
挑战:
如果不使用您的语言提供的模数除法运算符,请编写一个程序,该程序将从用户获取两个整数输入,然后显示第一个数字模数除以第二个数字的结果.假设所有输入都是正数.
例:
Input of first number:2
Input of second number:2
Result:0
Run Code Online (Sandbox Code Playgroud)
谁赢:
如果您不知道Code Golf的工作原理,获胜者是以最少的字符编写此程序的人.
Cas*_*Chu 95
CSS(ungolfed):
li {
counter-increment: a;
}
li:after {
content: counter(a);
}
li:nth-child(3n) { /* replace 3 with 2nd input ("b" in "a % b") */
counter-reset: a;
counter-increment: none;
}
Run Code Online (Sandbox Code Playgroud)
伴随HTML:
<ol> <li></li> <li></li> <li></li> <!-- etc. --> </ol>
输出:
输出http://img155.imageshack.us/img155/4643/modd.png
这在IE中不起作用(惊喜!).
Dav*_*vid 25
([-]*<.@%)
Run Code Online (Sandbox Code Playgroud)
用法:
10 ([-]*<.@%) 3
1
Run Code Online (Sandbox Code Playgroud)
({.-{:*[:<.{.%{:)
Run Code Online (Sandbox Code Playgroud)
用法:
({.-{:*[:<.{.%{:) 10 3
1
({.-{:*[:<.{.%{:) 225 13
4
Run Code Online (Sandbox Code Playgroud)
说明:
我拿了一个图腾柱把它变成笑脸,它起作用了.
Cla*_*diu 25
2*~/*-
Run Code Online (Sandbox Code Playgroud)
用法(只输入golfscript的方式):
echo 14 3 | ruby golfscript.rb modulo.gs
2
Run Code Online (Sandbox Code Playgroud)
说明:
2*~ #double the input string and eval (so now 14 3 14 3 are on the stack)
/ #int divide 14 / 3, gives quotient
*- #multiply that result by 3, subtract from 14, gives remainder
Run Code Online (Sandbox Code Playgroud)
Cal*_*ers 13
2?/*-
Run Code Online (Sandbox Code Playgroud)
运行使用:
RePeNt mod.rpn 17 3
RePeNt "2?/*-" 17 3
Run Code Online (Sandbox Code Playgroud)
RePeNt是一种基于堆栈的玩具语言,我自己在每个操作符/命令/循环中以反向波兰表示法(RPN)输入.当我整理一下时,我会释放翻译.
Command Explanation Stack
------- ----------- -----
n/a The program takes 2 parameters ( 17 3 ) and pushes them 17 3
onto the stack
2 Pushes a 2 onto the stack 17 3 2
? Pops a number (x) off the stack + copies the last x 17 3 17 3
stack items onto the stack
/ Divides on stack 17 3 5
* Multiplies on stack 17 15
- Subtracts on stack 2
Run Code Online (Sandbox Code Playgroud)
Fat*_*tus 12
p(a=gets.to_i)-a/(b=gets.to_i)*b
Run Code Online (Sandbox Code Playgroud)
当然我不会赢,但这里什么都没有:
<?php
$a=readline("#1:");
$b=readline("#2:");
while($b<=$a)$a-=$b;
echo "Result: $a";
Run Code Online (Sandbox Code Playgroud)
我知道已有两个Ruby答案,但为什么不呢?以这种方式获得输入是一种不同的方法来敲掉几个字符.
a,n=*$*.map(&:to_i);p a-a*n/n
Run Code Online (Sandbox Code Playgroud)
$ ruby a.rb 10 3 1