挑战:
在不使用您的语言已经提供的模除运算符的情况下,编写一个程序,该程序将接受用户的两个整数输入,然后显示第一个数的模除数除以第二个数的结果。假设所有输入都是正数。
示例:
Input of first number:2
Input of second number:2
Result:0谁赢了:
如果你不知道Code Golf是如何工作的,胜利者是用最少的字符编写这个程序的人。
发布于 2010-06-11 03:52:02
CSS: 107个字符:)
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;
}附带的超文本标记语言: <ol> <li></li> <li></li> <li></li> <!-- etc. --> </ol>
输出:
Output http://img155.imageshack.us/img155/4643/modd.png
这在IE中不起作用(惊喜吧!)。
发布于 2010-06-10 11:58:55
J,10个字符
([-]*<.@%)用法:
10 ([-]*<.@%) 3
1J,17个字符(输入为列表)
({.-{:*[:<.{.%{:)用法:
({.-{:*[:<.{.%{:) 10 3
1
({.-{:*[:<.{.%{:) 225 13
4解释:
我拿了一个图腾柱,把它变成了一个笑脸,它起作用了。
发布于 2010-06-12 20:32:28
RePeNt,5个字符
2?/*-使用以下命令运行:
RePeNt mod.rpn 17 3
RePeNt "2?/*-" 17 3RePeNt是我自己制作的基于堆栈的玩具语言,其中每个操作符/命令/循环都是以反向波兰语表示法输入的。等我整理好了,我会释放解释器的。
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 2https://stackoverflow.com/questions/3011389
复制相似问题