Project1
标题: 大家会哪几种代码? [打印本页]
作者: 876加几 时间: 2014-7-30 13:42
标题: 大家会哪几种代码?
本帖最后由 876加几 于 2014-7-30 17:50 编辑
我会Ruby、VB和VB.NET。
代码演示:
array = [1,2,3,4]
array.clear
p array #=>[]
p array[0] #=> nil
class Array
def self.plus(ary1, ary2)
return ary1 + ary2
end
end
p Array.plus([1],[2]) #=>[1,2]
array = [1,2,3,4]
array.clear
p array #=>[]
p array[0] #=> nil
class Array
def self.plus(ary1, ary2)
return ary1 + ary2
end
end
p Array.plus([1],[2]) #=>[1,2]
Dim i As Integer
For i = 0 To 10
MsgBox(i.ToString) '=>0~10
End For
'其实是VB.NET
Dim i As Integer
For i = 0 To 10
MsgBox(i.ToString) '=>0~10
End For
'其实是VB.NET
好了,请大家尽快投票吧。
作者: 余烬之中 时间: 2014-7-30 14:04
本帖最后由 余烬之中 于 2014-7-30 16:44 编辑
你没发现ruby有两项吗
我还会伪代码(这是只有笨蛋才能看到的神奇文字
eval "Dim i As Integer
For i = 0 To 10
MsgBox(i.ToString) '=>0~10
Next".each_line.map{|line|
case line
when /^\s*Dim/
line.sub!(/^Dim/){}
line.gsub!(/\s+(.+)\s+As\s+(.+)($|,)/){ "#$1 = #{ {"Integer" => "0"}[$2] }" }
when /^\s*For/
line.sub!(/^For\s+(.+)\s+=\s+(\d+)\s+To\s+(\d+)/){ "#$2.upto(#$3){|#$1|" }
when /^\s*Next/
line.sub!(/^\s*Next.*/){ "}" }
else
line.gsub!(/MsgBox\((.*)\)/){ "puts #$1"}
line.gsub!(/'/){ "#" }
line.gsub!(/([^.]+)\.([^.]+?)(\s+.+|$)/){ "#$1.#{ {"ToString" => "to_s"}[$2] }#$3" }
end
line
}.join
eval "Dim i As Integer
For i = 0 To 10
MsgBox(i.ToString) '=>0~10
Next".each_line.map{|line|
case line
when /^\s*Dim/
line.sub!(/^Dim/){}
line.gsub!(/\s+(.+)\s+As\s+(.+)($|,)/){ "#$1 = #{ {"Integer" => "0"}[$2] }" }
when /^\s*For/
line.sub!(/^For\s+(.+)\s+=\s+(\d+)\s+To\s+(\d+)/){ "#$2.upto(#$3){|#$1|" }
when /^\s*Next/
line.sub!(/^\s*Next.*/){ "}" }
else
line.gsub!(/MsgBox\((.*)\)/){ "puts #$1"}
line.gsub!(/'/){ "#" }
line.gsub!(/([^.]+)\.([^.]+?)(\s+.+|$)/){ "#$1.#{ {"ToString" => "to_s"}[$2] }#$3" }
end
line
}.join
作者: shy 时间: 2014-7-30 14:10
就会一点从师兄那学到的C
作者: 你最珍贵 时间: 2014-7-30 14:15
半种
作者: taroxd 时间: 2014-7-30 14:19
本帖最后由 taroxd 于 2014-7-30 14:35 编辑
你没发现你 Ruby 的代码是错误的吗?别跟我说你这一段是在 Array.instance_eval 里面的
VB我也记得是 Next i 而不是 End For 吧?
你觉得怎样才算【会】呢?
看得懂语法:Lisp、C、C++、Python、VB、Ruby
写得出简单程序:C、C++、Ruby(VB仅限高中会考等级所以不算)
写得出程序卖萌:Ruby
代码演示:
https://rpg.blue/thread-368425-1-1.html
https://rpg.blue/thread-368980-1-1.html
作者: H·H·Y 时间: 2014-7-30 14:24
我都会!…………加减乘除……
作者: taroxd 时间: 2014-7-30 14:31
余烬之中 发表于 2014-7-30 14:04
你没发现ruby有两项吗
我还会伪代码(这是只有笨蛋才能看到的神奇文字
def int(_) end
def main(&b)
Object.send(:define_method, :main, &b)
main
end
std = Module.new do
def self.cout; STDOUT; end
def self.endl; "\n"; end
end
#include <iostream>
int main() {
std::cout << "Hello world!" << std::endl;
return 0;
}
def int(_) end
def main(&b)
Object.send(:define_method, :main, &b)
main
end
std = Module.new do
def self.cout; STDOUT; end
def self.endl; "\n"; end
end
#include <iostream>
int main() {
std::cout << "Hello world!" << std::endl;
return 0;
}
作者: taroxd 时间: 2014-7-30 14:38
@余烬之中
Ruby 2.0 环境
Array.instance_eval do
class Array
$array = self
end
end
p $array.new # []
Array.instance_eval do
class Array
$array = self
end
end
p $array.new # []
作者: 余烬之中 时间: 2014-7-30 14:40
本帖最后由 余烬之中 于 2014-7-30 14:59 编辑
taroxd 发表于 2014-7-30 14:38
@余烬之中
Ruby 2.0 环境
1.9.3
已证实
作者: 无脑之人 时间: 2014-7-30 14:45
看见LS几个触手秀Tentacles什么的我就不想多说了【
果然LZ对代码的认识就是顶楼那几种?
作者: 迷糊的安安 时间: 2014-7-30 15:09
cls
clrscr();
clc
char clscode[] = {0x1B, 0x5B, 0x48, 0x1B, 0x5B, 0x4A};
clear
作者: 克莉丝 时间: 2014-7-30 15:30
本帖最后由 克莉丝 于 2014-7-30 15:53 编辑
- push 14h
- push offset unk_4096B0
- call __SEH_prolog4
- or [ebp+var_20], 0FFFFFFFFh
- call __getptd
- mov edi, eax
- mov [ebp+var_24], edi
- call ___updatetmbcinfo
- mov ebx, [edi+68h]
- mov esi, [ebp+arg_0]
- call ?getSystemCP@@YAHH@Z ; getSystemCP(int)
- mov [ebp+arg_0], eax
- cmp eax, [ebx+4]
- jz loc_404E0E
复制代码 这样的东西好玩?
作者: myownroc 时间: 2014-7-30 15:32
楼主认识的语言种类也太少了吧
作者: awedcvgyujm 时间: 2014-7-30 15:59
大触人口普查帖_(:з」∠)_
作者: 江户川洛奇 时间: 2014-7-30 16:31
让渣渣都不好意思进来了
作者: kuerlulu 时间: 2014-7-30 16:36
渣渣不好意思进来了+1
能简单地写几个rmxp的脚本= =
因为做chm所以能简单地写几个htm的代码= =
作者: 艾尔露 时间: 2014-7-30 16:37
- //毫無反應只是C
- #include<stdio.h>
- void draw_1(int start_row,int end_row,int leading_space);
- void draw_base(int);
- int main()
- {
- int row,col,star,space;
- int top_size=5,mid_size=7,bottom_size=9;
- draw_1(1,top_size,2*(mid_size-top_size));
- draw_1(2,mid_size,bottom_size-mid_size);
- draw_1(3,bottom_size,0);
- draw_base(bottom_size);
- return 0;
- }
- void draw_1(int start_row,int end_row,int leading_space)
- {
- int row,col,star,space;
- for(row=1;row<=end_row;row++)
- {
- if (2*row>2*start_row-1)
- {
- for (col=1;col<=leading_space;col++)
- {
- printf_s("%c",' ');
- }
- for(space=1;space<=end_row-row;space++)
- printf_s("%c",' ');
- for(star=1;star<=2*row-1;star++)
- printf_s("%c",'*');
- printf_s("%c",'\n');
- }
- }
- }
- void draw_base(int b_size)
- {
- int row,col,space,star;
- for(row=1;row<=b_size/3;row++)
- {
- for(space=1;space<=b_size/2;space++)
- printf_s("%c",' ');
- for(star=1;star<=b_size;star++)
- printf_s("%c",'*');
- printf_s("%c",'\n');
- }
- }
复制代码
{:2_253:}
真正的小渣渣給各位觸手們跪了
嘛真的有學過的只有VB.NET,C和C++吧…
作者: kagamine_len 时间: 2014-7-30 17:11
一种都不会
作者: 876加几 时间: 2014-7-30 18:07
本帖最后由 876加几 于 2014-7-30 20:14 编辑
继续演示!!!
Public Module Judge
Function Prime(ByVal x As Integer) As Boolean '判断一个数是否是质数
If x < 2 Then
Return False
Elseif x = 2 Then
Return True
Else
Dim i As Integer
For i = 2 To (x - 1)
If x Mod i = 0 Then
Return False
End If
End For
End If
Return True
End Function
End Module
Class Demo
Sub New()
If Prime(17) Then
MsgBox("17是质数")
Else
MsgBox("17是合数")
End If
If Prime(16) Then
MsgBox("16是质数")
Else
MsgBox("16是合数")
End If
'运行结果:17是质数,16是合数
End Sub
End Class
'以上为VB.NET
Public Module Judge
Function Prime(ByVal x As Integer) As Boolean '判断一个数是否是质数
If x < 2 Then
Return False
Elseif x = 2 Then
Return True
Else
Dim i As Integer
For i = 2 To (x - 1)
If x Mod i = 0 Then
Return False
End If
End For
End If
Return True
End Function
End Module
Class Demo
Sub New()
If Prime(17) Then
MsgBox("17是质数")
Else
MsgBox("17是合数")
End If
If Prime(16) Then
MsgBox("16是质数")
Else
MsgBox("16是合数")
End If
'运行结果:17是质数,16是合数
End Sub
End Class
'以上为VB.NET
def 最大公因数(*num)
if num.size = 1
return num[0]
elsif num.size = 2
if num[0] % num[1] = 0
return num[1]
else
return 最大公因数(num[1], num[0] % num[1])
end
else
num2 = 最大公因数(num[0], num[1])
for i in 2...num.size
num2 = 最大公因数(num2, num[i])
end
end
end
p 最大公因数(60, 72, 40) #=>4
def 最大公因数(*num)
if num.size = 1
return num[0]
elsif num.size = 2
if num[0] % num[1] = 0
return num[1]
else
return 最大公因数(num[1], num[0] % num[1])
end
else
num2 = 最大公因数(num[0], num[1])
for i in 2...num.size
num2 = 最大公因数(num2, num[i])
end
end
end
p 最大公因数(60, 72, 40) #=>4
和……以前我写的的求和求积……
def sum(min, max)
ary = []
for i in min..max
ary.push(yield(i))
end
num = 0
for n in ary
num += n
end
return num.truncate == num ? num.truncate : num rescue Nan
end
def multi(min, max)
ary = []
for i in min..max
ary.push(yield(i))
end
num = ary[0]
ary.shift
for n in ary
num *= n
end
return num.truncate == num ? num.truncate : num rescue Nan
end
p sum(1, 3) {i * 3} #=>18
p sum(0, 4) {i / 2.0} #=>3(舍0)
p multi(1, 3) {i * 2} #=>48
def sum(min, max)
ary = []
for i in min..max
ary.push(yield(i))
end
num = 0
for n in ary
num += n
end
return num.truncate == num ? num.truncate : num rescue Nan
end
def multi(min, max)
ary = []
for i in min..max
ary.push(yield(i))
end
num = ary[0]
ary.shift
for n in ary
num *= n
end
return num.truncate == num ? num.truncate : num rescue Nan
end
p sum(1, 3) {i * 3} #=>18
p sum(0, 4) {i / 2.0} #=>3(舍0)
p multi(1, 3) {i * 2} #=>48
作者: gonglinyuan 时间: 2014-7-30 18:10
。。。这选项也太少了吧。。
Python、Java、Lisp、Pascal、Lua这些著名语言都被吃了?
既然有VB.NET这种微软黑科技,那么C#、F#这种也该算吧?(虽然我及其讨厌)
另外,像HTML、php等网页相关语言也没有吗?
作者: 克莉丝 时间: 2014-7-30 18:18
876加几 发表于 2014-7-30 18:07
继续演示!!!
Public Module Judge
帮我写个代码找出最大的质数,不谢
作者: taroxd 时间: 2014-7-30 18:23
本帖最后由 taroxd 于 2014-7-31 08:49 编辑
876加几 发表于 2014-7-30 18:07
继续演示!!!
Public Module Judge
看了楼主的代码,楼主完全不会 VB.net 和 Ruby。鉴定完毕。
# 懒得 require 'prime' 了
# 暂不考虑效率。想要效率去拿概率什么的算法去。
def prime?(n)
n > 1 && (2..n / 2).all? {|i| n % i != 0 }
end
[15, 16].each {|n| puts "#{n}是#{prime?(n) ? "质" : "合"}数" }
def 最大公约数(*nums)
nums.inject(:gcd)
end
p 最大公约数(60, 72, 40) #=> 4
# 懒得 require 'prime' 了
# 暂不考虑效率。想要效率去拿概率什么的算法去。
def prime?(n)
n > 1 && (2..n / 2).all? {|i| n % i != 0 }
end
[15, 16].each {|n| puts "#{n}是#{prime?(n) ? "质" : "合"}数" }
def 最大公约数(*nums)
nums.inject(:gcd)
end
p 最大公约数(60, 72, 40) #=> 4
作者: 876加几 时间: 2014-7-30 20:23
本帖最后由 876加几 于 2014-7-30 20:25 编辑
昨天写的VB.NET:
Public Class GameArray
'变量
Private ary(13, 13) As Integer
'调用
Public Sub New()
Make()
End Sub
'调用数据
Public ReadOnly Property Data() As Integer(,)
Get
Return ary
End Get
End Property
'制作
Sub Make()
Dim x, y As Integer
For x = 0 To 12
For y = 0 To 12
If x = 6 And y = 6 Then
ary(x, y) = 2
ElseIf Int(Rnd() * 10) = 1 Then
ary(x, y) = 1
Else
ary(x, y) = 0
End If
Next
Next
End Sub
'注释
'可通行区域 = 0
'禁止通行区域 = 1
'老鼠 = 2
'是否相邻判断
Function adjoin(ByVal x1 As Integer, ByVal y1 As Integer, ByVal x2 As Integer, ByVal y2 As Integer) As Boolean
If Not (Valid(x1, x2) = True And Valid(x2, y2) = True) Then
Throw New Exception("存在无效坐标。")
End If
If Math.Abs(x2 - x1) = 1 Or Math.Abs(y2 - y1) = 1 Then
Return True
End If
Dim num As Integer
num = y1 Mod 2
If num = 0 Then '奇数行靠左
If Math.Abs(y2 - y1) = 1 And x1 - x2 = 1 Then
Return True
End If
Else '偶数行靠右
If Math.Abs(y2 - y1) = 1 And x2 - x1 = 1 Then
Return True
End If
End If
Return False
End Function
'相邻可通行区域
Function AdjoinAndPossable(ByVal x As Integer, ByVal y As Integer) As Integer()()
If Valid(x, y) = False Then
Throw New Exception("无效坐标。")
End If
Dim x1, y1 As Integer
Dim Coordinate As Integer()() = {}
Dim SelfAry(2) As Integer
For x1 = 0 To 12
For y1 = 0 To 12
SelfAry(0) = x1
SelfAry(1) = y1
If adjoin(x, y, x1, y1) = True And Me.Data(x1, y1) = 1 = False Then
ArrayAdd(Coordinate, SelfAry)
End If
Next
Next
Return Coordinate
End Function
'有效
Function Valid(ByVal x As Integer, ByVal y As Integer) As Boolean
Return (x >= 0 And x < 13 And y >= 0 And y < 13)
End Function
'清除老鼠
Sub MoveMouse()
Dim x, y As Integer
For x = 0 To 12
For y = 0 To 12
If ary(x, y) = 2 Then
ary(x, y) = 0
Exit Sub
End If
Next
Next
End Sub
'移动老鼠
Sub MoveMouse(ByVal x As Integer, ByVal y As Integer)
If Valid(x, y) = False Then
Throw New Exception("无效坐标。")
End If
Dim x1, y1 As Integer
For x1 = 0 To 12
For y1 = 0 To 12
If ary(x1, y1) = 2 Then
ary(x1, y1) = 0
End If
Next
Next
ary(x, y) = 2
End Sub
'添加障碍 (返回是否成功)
Function AddBlock(ByVal x As Integer, ByVal y As Integer) As Boolean
If Valid(x, y) = False Then
Throw New Exception("无效坐标。")
End If
Dim x1, y1 As Integer
Dim mouse(2) As Integer
For x1 = 0 To 12
For y1 = 0 To 12
If ary(x1, y1) = 2 Then
mouse(0) = x1
mouse(1) = y1
End If
Next
Next
If (mouse(0) = x And mouse(1) = y) Or (Data(x, y) = 1) Then
Return False
End If
ary(x, y) = 1
Return True
End Function
End Class
Public Class GameArray
'变量
Private ary(13, 13) As Integer
'调用
Public Sub New()
Make()
End Sub
'调用数据
Public ReadOnly Property Data() As Integer(,)
Get
Return ary
End Get
End Property
'制作
Sub Make()
Dim x, y As Integer
For x = 0 To 12
For y = 0 To 12
If x = 6 And y = 6 Then
ary(x, y) = 2
ElseIf Int(Rnd() * 10) = 1 Then
ary(x, y) = 1
Else
ary(x, y) = 0
End If
Next
Next
End Sub
'注释
'可通行区域 = 0
'禁止通行区域 = 1
'老鼠 = 2
'是否相邻判断
Function adjoin(ByVal x1 As Integer, ByVal y1 As Integer, ByVal x2 As Integer, ByVal y2 As Integer) As Boolean
If Not (Valid(x1, x2) = True And Valid(x2, y2) = True) Then
Throw New Exception("存在无效坐标。")
End If
If Math.Abs(x2 - x1) = 1 Or Math.Abs(y2 - y1) = 1 Then
Return True
End If
Dim num As Integer
num = y1 Mod 2
If num = 0 Then '奇数行靠左
If Math.Abs(y2 - y1) = 1 And x1 - x2 = 1 Then
Return True
End If
Else '偶数行靠右
If Math.Abs(y2 - y1) = 1 And x2 - x1 = 1 Then
Return True
End If
End If
Return False
End Function
'相邻可通行区域
Function AdjoinAndPossable(ByVal x As Integer, ByVal y As Integer) As Integer()()
If Valid(x, y) = False Then
Throw New Exception("无效坐标。")
End If
Dim x1, y1 As Integer
Dim Coordinate As Integer()() = {}
Dim SelfAry(2) As Integer
For x1 = 0 To 12
For y1 = 0 To 12
SelfAry(0) = x1
SelfAry(1) = y1
If adjoin(x, y, x1, y1) = True And Me.Data(x1, y1) = 1 = False Then
ArrayAdd(Coordinate, SelfAry)
End If
Next
Next
Return Coordinate
End Function
'有效
Function Valid(ByVal x As Integer, ByVal y As Integer) As Boolean
Return (x >= 0 And x < 13 And y >= 0 And y < 13)
End Function
'清除老鼠
Sub MoveMouse()
Dim x, y As Integer
For x = 0 To 12
For y = 0 To 12
If ary(x, y) = 2 Then
ary(x, y) = 0
Exit Sub
End If
Next
Next
End Sub
'移动老鼠
Sub MoveMouse(ByVal x As Integer, ByVal y As Integer)
If Valid(x, y) = False Then
Throw New Exception("无效坐标。")
End If
Dim x1, y1 As Integer
For x1 = 0 To 12
For y1 = 0 To 12
If ary(x1, y1) = 2 Then
ary(x1, y1) = 0
End If
Next
Next
ary(x, y) = 2
End Sub
'添加障碍 (返回是否成功)
Function AddBlock(ByVal x As Integer, ByVal y As Integer) As Boolean
If Valid(x, y) = False Then
Throw New Exception("无效坐标。")
End If
Dim x1, y1 As Integer
Dim mouse(2) As Integer
For x1 = 0 To 12
For y1 = 0 To 12
If ary(x1, y1) = 2 Then
mouse(0) = x1
mouse(1) = y1
End If
Next
Next
If (mouse(0) = x And mouse(1) = y) Or (Data(x, y) = 1) Then
Return False
End If
ary(x, y) = 1
Return True
End Function
End Class
以前写的Ruby:
module Function
PI = 3.1415926535897932385
E = 2.7182818284590452354
BITS = 32
PHI = 1.6180339887498948482
TAU = 2 * PI
ABTS = 32
GAMMA = 0.5772156649015328606
C2 = 0.6601618158468695739
def gamma(x)
x = x.truncate == x ? x.truncate : x
if x.is_a?(Integer)
if x > 0
return fact(x)
else
raise ArgumentError.new("wrong number")
end
else
if x > 0
num = sqrt(2 * PI / x) * (1.0 / E * sqrt(x + 1.0 / (12 * x - 1.0 / (10 * x))))
else
num = gamma(1 - (n.abs - Integer(n.abs)))
for t in 1..Integer(n.abs) + 1
i = 1 - (n.abs - Integer(n.abs)) - t
num /= i
end
end
end
return num.truncate == num ? num.truncate : num rescue Infinity
end
def s_dec(x)
a = x.to_s.scan(/./)
dd = false
for s in 0...a.size
if dd
break
end
for c in 0...a.size
i = a[c]
if i == "."
a.shift
dd = true
break
else
a.shift
break
end
end
end
return a.to_s
end
def about(x, y)
num = Integer(x.abs)
ary = s_dec(x).scan(/./)
for i in 0...ary.size
ns = ary[i]
nt = ns.to_i
ntc = nt
ntc *= 10 ** (-i - 1)
if i < y and not i - y == -1
num += ntc
elsif i - y == -1
num += ntc
if ary[i + 1].to_i >= 5
num += 10 ** (-y)
end
break
else
break
end
end
if x < 0
num = -num
end
return num.truncate == num ? num.truncate : num
end
def fact(x)
x = x.truncate == x ? x.truncate : x
if x.is_a?(Integer)
if x < 0
raise ArgumentError.new("wrong number")
elsif x < 2
return 1
else
return x * fact(x - 1) rescue Infinity
end
else
return gamma(x + 1)
end
end
def sqrt(x)
if x < 0
raise ArgumentError.new("wrong number")
end
num = x ** 0.5
return num.truncate == num ? num.truncate : num
end
def sqr(x)
return x ** 2
end
def cube(x)
return x ** 3
end
def cuberoot(x)
if x < 0
return -cuberoot(-x)
end
num = x ** (1.0 / 3)
return num.truncate == num ? num.truncate : num
end
def root(x, y)
if (x.abs != self and y % 2 == 0) or y == 0
raise ArgumentError.new("wrong number")
end
if x.abs != x
num = (x * (-1)) ** (1.0 / y)
return num.truncate == num ? -num.truncate : -num
end
num = x ** (1.0 / y)
return num.truncate == num ? num.truncate : num
end
def sin(x)
while x < 0
x += TAU
end
x %= TAU
num = sum(0, BITS){|n| (-1) ** n * x ** (2 * n + 1) / fact(2 * n + 1).to_f}
num = about(num, ABTS)
return num.truncate == num ? num.truncate : num
end
def sind(x)
return sin(x * PI / 180.0)
end
def sing(x)
return sind(x * 0.9)
end
def cos(x)
num = sqrt((1 - sqr(sin(x))).abs)
if x % TAU >= PI
num = -num
end
return num.truncate == num ? num.truncate : num
end
def cosd(x)
return cos(x * PI / 180.0)
end
def cosg(x)
return cosd(x * 0.9)
end
def tan(x)
return sin(x) / cos(x)
end
def tand(x)
return sind(x) / cosd(x)
end
def tang(x)
return sing(x) / cosg(x)
end
def sum(min, max)
ary = []
for i in min..max
ary.push(yield(i))
end
num = 0
for n in ary
num += n
end
return num.truncate == num ? num.truncate : num rescue Nan
end
def multi(min, max)
ary = []
for i in min..max
ary.push(yield(i))
end
num = ary[0]
ary.shift
for n in ary
num *= n
end
return num.truncate == num ? num.truncate : num rescue Nan
end
def asin(x)
if x < -1 or x > 1
raise ArgumentError.new("wrong number")
end
num = 2 * atan(x / (1 + sqrt(1 - sqr(x))).to_f)
return num.truncate == num ? num.truncate : num
end
def acos(x)
num = PI / 2 - asin(x)
return num.truncate == num ? num.truncate : num
end
def atan(x)
num = x / (1 + sqr(x)).to_f * sum(0, BITS){|n| n == 0 ? 1 : multi(1, n){|k| 2 * k * sqr(x) / ((2 * k + 1) * (1 + sqr(x))).to_f}}
return num.truncate == num ? num.truncate : num
end
def asind(x)
num = asin(x) * 180 / PI
return num.truncate == num ? num.truncate : num
end
def acosd(x)
num = 90 - asind(x)
return num.truncate == num ? num.truncate : num
end
def atand(x)
num = atan(x) * 180 / PI
return num.truncate == num ? num.truncate : num
end
def erf(x)
num = 2.0 / sqrt(PI) * sum(0, BITS){|n| (-1) ** n * x ** (2 * n + 1) / fact(n) * (2 * n + 1)}
num = about(num, ABTS)
return num.truncate == num ? num.truncate : num
end
def erfc(x)
return 1 - erf(x)
end
def sgn(x)
return x <=> 0
end
def aerf(x)
num = sum(0, BITS){|g| erf_c(g) / (2 * g + 1).to_f * (sqrt(PI) / 2 * x) ** (2 * g + 1)}
return num.truncate == num ? num.truncate : num
end
def aerfc(x)
return aerf(1 - x)
end
def ln(x)
if x < 0
raise ArgumentError.new("wrong number")
end
y = (x - 1) / (x + 1)
num = 2 * y * (1 + sum(1, BITS){|n| 1.0 / (2 * n + 1) * y ** (2 * n)})
return num.truncate == num ? num.truncate : num
end
def lg(x)
if x < 0
raise ArgumentError.new("wrong number")
end
num = ln(x) / ln(10)
return num.truncate == num ? num.truncate : num
end
def log(x, y)
if x < 0 or (y <= 0 or y == 1)
raise ArgumentError.new("wrong number")
end
num = lg(y) / lg(x)
return num.truncate == num ? num.truncate : num
end
def sinh(x)
num = (E ** x - E ** (-x)) / 2
return num.truncate == num ? num.truncate : num
end
def cosh(x)
num = (E ** x + E ** (-x)) / 2
return num.truncate == num ? num.truncate : num
end
def tanh(x)
num = sinh(x) / cosh(x)
return num.truncate == num ? num.truncate : num
end
def asinh(x)
num = ln(x + sqrt(sqr(x) + 1))
return num.truncate == num ? num.truncate : num
end
def acosh(x)
num = ln(x + sqrt(sqr(x) - 1))
return num.truncate == num ? num.truncate : num
end
def atanh(x)
num = ln(sqrt(1 - sqr(x)) / (1 - x))
return num.truncate == num ? num.truncate : num
end
def beta(x, y)
num = (gamma(x) * gamma(y)) / gamma(x + y)
return num.truncate == num ? num.truncate : num
end
def dms(x)
ary = x.split(1, true)
na = [ary[0].to_s, ".", ""]
for i in ary[1]
str = (i * 60).to_s
na[2] += str
end
num = na.to_s.to_f
return num.truncate == num ? num.truncate : num
end
def Int(x)
return Integer(x)
end
def gen_e(x, y)
num = fact(x) / sqrt(PI) * sum(0, BITS){|p| (-1) ** p * ((y ** (x * p + 1)).to_f / ((x * p + 1) * fact(p)))}
return num.truncate == num ? num.truncate : num
end
def erf_c(x)
if x == 0
return 1
end
num = sum(0, x - 1){|m| erf_c(m) * erf_c(x - 1 - m) / ((m + 1) * (2 * m + 1)).to_f}
return num.truncate == num ? num.truncate : num
end
def Frac(x)
num = x - Int(x)
return num.truncate == num ? num.truncate : num
end
def adms(x)
ary = x.split(2, true)
na = [ary[0].to_s, ".", ""]
for i in ary[1]
if i > 60
raise ArgumentError.new("wrong number")
end
n = i / 6 / 10
na.push(n)
end
num = na.to_s.to_f
return num.truncate == num ? num.truncate : num
end
def atan2(y, x)
num = atan(y) / atan(x)
return num.truncate == num ? num.truncate : num
end
def atand2(y, x)
num = atand(y) / atand(x)
return num.truncate == num ? num.truncate : num
end
end
class Object
include Function
end
module Function
PI = 3.1415926535897932385
E = 2.7182818284590452354
BITS = 32
PHI = 1.6180339887498948482
TAU = 2 * PI
ABTS = 32
GAMMA = 0.5772156649015328606
C2 = 0.6601618158468695739
def gamma(x)
x = x.truncate == x ? x.truncate : x
if x.is_a?(Integer)
if x > 0
return fact(x)
else
raise ArgumentError.new("wrong number")
end
else
if x > 0
num = sqrt(2 * PI / x) * (1.0 / E * sqrt(x + 1.0 / (12 * x - 1.0 / (10 * x))))
else
num = gamma(1 - (n.abs - Integer(n.abs)))
for t in 1..Integer(n.abs) + 1
i = 1 - (n.abs - Integer(n.abs)) - t
num /= i
end
end
end
return num.truncate == num ? num.truncate : num rescue Infinity
end
def s_dec(x)
a = x.to_s.scan(/./)
dd = false
for s in 0...a.size
if dd
break
end
for c in 0...a.size
i = a[c]
if i == "."
a.shift
dd = true
break
else
a.shift
break
end
end
end
return a.to_s
end
def about(x, y)
num = Integer(x.abs)
ary = s_dec(x).scan(/./)
for i in 0...ary.size
ns = ary[i]
nt = ns.to_i
ntc = nt
ntc *= 10 ** (-i - 1)
if i < y and not i - y == -1
num += ntc
elsif i - y == -1
num += ntc
if ary[i + 1].to_i >= 5
num += 10 ** (-y)
end
break
else
break
end
end
if x < 0
num = -num
end
return num.truncate == num ? num.truncate : num
end
def fact(x)
x = x.truncate == x ? x.truncate : x
if x.is_a?(Integer)
if x < 0
raise ArgumentError.new("wrong number")
elsif x < 2
return 1
else
return x * fact(x - 1) rescue Infinity
end
else
return gamma(x + 1)
end
end
def sqrt(x)
if x < 0
raise ArgumentError.new("wrong number")
end
num = x ** 0.5
return num.truncate == num ? num.truncate : num
end
def sqr(x)
return x ** 2
end
def cube(x)
return x ** 3
end
def cuberoot(x)
if x < 0
return -cuberoot(-x)
end
num = x ** (1.0 / 3)
return num.truncate == num ? num.truncate : num
end
def root(x, y)
if (x.abs != self and y % 2 == 0) or y == 0
raise ArgumentError.new("wrong number")
end
if x.abs != x
num = (x * (-1)) ** (1.0 / y)
return num.truncate == num ? -num.truncate : -num
end
num = x ** (1.0 / y)
return num.truncate == num ? num.truncate : num
end
def sin(x)
while x < 0
x += TAU
end
x %= TAU
num = sum(0, BITS){|n| (-1) ** n * x ** (2 * n + 1) / fact(2 * n + 1).to_f}
num = about(num, ABTS)
return num.truncate == num ? num.truncate : num
end
def sind(x)
return sin(x * PI / 180.0)
end
def sing(x)
return sind(x * 0.9)
end
def cos(x)
num = sqrt((1 - sqr(sin(x))).abs)
if x % TAU >= PI
num = -num
end
return num.truncate == num ? num.truncate : num
end
def cosd(x)
return cos(x * PI / 180.0)
end
def cosg(x)
return cosd(x * 0.9)
end
def tan(x)
return sin(x) / cos(x)
end
def tand(x)
return sind(x) / cosd(x)
end
def tang(x)
return sing(x) / cosg(x)
end
def sum(min, max)
ary = []
for i in min..max
ary.push(yield(i))
end
num = 0
for n in ary
num += n
end
return num.truncate == num ? num.truncate : num rescue Nan
end
def multi(min, max)
ary = []
for i in min..max
ary.push(yield(i))
end
num = ary[0]
ary.shift
for n in ary
num *= n
end
return num.truncate == num ? num.truncate : num rescue Nan
end
def asin(x)
if x < -1 or x > 1
raise ArgumentError.new("wrong number")
end
num = 2 * atan(x / (1 + sqrt(1 - sqr(x))).to_f)
return num.truncate == num ? num.truncate : num
end
def acos(x)
num = PI / 2 - asin(x)
return num.truncate == num ? num.truncate : num
end
def atan(x)
num = x / (1 + sqr(x)).to_f * sum(0, BITS){|n| n == 0 ? 1 : multi(1, n){|k| 2 * k * sqr(x) / ((2 * k + 1) * (1 + sqr(x))).to_f}}
return num.truncate == num ? num.truncate : num
end
def asind(x)
num = asin(x) * 180 / PI
return num.truncate == num ? num.truncate : num
end
def acosd(x)
num = 90 - asind(x)
return num.truncate == num ? num.truncate : num
end
def atand(x)
num = atan(x) * 180 / PI
return num.truncate == num ? num.truncate : num
end
def erf(x)
num = 2.0 / sqrt(PI) * sum(0, BITS){|n| (-1) ** n * x ** (2 * n + 1) / fact(n) * (2 * n + 1)}
num = about(num, ABTS)
return num.truncate == num ? num.truncate : num
end
def erfc(x)
return 1 - erf(x)
end
def sgn(x)
return x <=> 0
end
def aerf(x)
num = sum(0, BITS){|g| erf_c(g) / (2 * g + 1).to_f * (sqrt(PI) / 2 * x) ** (2 * g + 1)}
return num.truncate == num ? num.truncate : num
end
def aerfc(x)
return aerf(1 - x)
end
def ln(x)
if x < 0
raise ArgumentError.new("wrong number")
end
y = (x - 1) / (x + 1)
num = 2 * y * (1 + sum(1, BITS){|n| 1.0 / (2 * n + 1) * y ** (2 * n)})
return num.truncate == num ? num.truncate : num
end
def lg(x)
if x < 0
raise ArgumentError.new("wrong number")
end
num = ln(x) / ln(10)
return num.truncate == num ? num.truncate : num
end
def log(x, y)
if x < 0 or (y <= 0 or y == 1)
raise ArgumentError.new("wrong number")
end
num = lg(y) / lg(x)
return num.truncate == num ? num.truncate : num
end
def sinh(x)
num = (E ** x - E ** (-x)) / 2
return num.truncate == num ? num.truncate : num
end
def cosh(x)
num = (E ** x + E ** (-x)) / 2
return num.truncate == num ? num.truncate : num
end
def tanh(x)
num = sinh(x) / cosh(x)
return num.truncate == num ? num.truncate : num
end
def asinh(x)
num = ln(x + sqrt(sqr(x) + 1))
return num.truncate == num ? num.truncate : num
end
def acosh(x)
num = ln(x + sqrt(sqr(x) - 1))
return num.truncate == num ? num.truncate : num
end
def atanh(x)
num = ln(sqrt(1 - sqr(x)) / (1 - x))
return num.truncate == num ? num.truncate : num
end
def beta(x, y)
num = (gamma(x) * gamma(y)) / gamma(x + y)
return num.truncate == num ? num.truncate : num
end
def dms(x)
ary = x.split(1, true)
na = [ary[0].to_s, ".", ""]
for i in ary[1]
str = (i * 60).to_s
na[2] += str
end
num = na.to_s.to_f
return num.truncate == num ? num.truncate : num
end
def Int(x)
return Integer(x)
end
def gen_e(x, y)
num = fact(x) / sqrt(PI) * sum(0, BITS){|p| (-1) ** p * ((y ** (x * p + 1)).to_f / ((x * p + 1) * fact(p)))}
return num.truncate == num ? num.truncate : num
end
def erf_c(x)
if x == 0
return 1
end
num = sum(0, x - 1){|m| erf_c(m) * erf_c(x - 1 - m) / ((m + 1) * (2 * m + 1)).to_f}
return num.truncate == num ? num.truncate : num
end
def Frac(x)
num = x - Int(x)
return num.truncate == num ? num.truncate : num
end
def adms(x)
ary = x.split(2, true)
na = [ary[0].to_s, ".", ""]
for i in ary[1]
if i > 60
raise ArgumentError.new("wrong number")
end
n = i / 6 / 10
na.push(n)
end
num = na.to_s.to_f
return num.truncate == num ? num.truncate : num
end
def atan2(y, x)
num = atan(y) / atan(x)
return num.truncate == num ? num.truncate : num
end
def atand2(y, x)
num = atand(y) / atand(x)
return num.truncate == num ? num.truncate : num
end
end
class Object
include Function
end
(未包括number.split,本来写过的此方法)
作者: taroxd 时间: 2014-7-30 20:25
876加几 发表于 2014-7-30 20:23
昨天写的VB.NET:
Public Class GameArray
那你 nums.size 的 size 方法是哪来的?你能用 size 为什么我不能用 inject?
求和的代码在此,我卖萌都写得比你好:https://rpg.blue/thread-368425-1-1.html
看了一这一层的代码,你不会这些语言无误
作者: PAME 时间: 2014-7-30 21:00
这个也太不全了点吧.....那么多编程语言orz
作者: myownroc 时间: 2014-7-30 21:31
本帖最后由 myownroc 于 2014-7-30 21:39 编辑
楼主来个大数(几十位的数字,用字符串表示)相乘呗~语言无所谓啦~反正都看得懂
作者: 恐惧剑刃 时间: 2014-7-30 21:40
会的意思?是精通么??
这样的话 我不会rgss更不会Ruby
如果会的意思,是学习过或者了解过
那么,我只会一点点rgss1
不客气的说,rgss1的很多东西我都是不会的。
新手可能觉得我是高手,但事实上我水平到底如何大家都懂,只是些雕虫小技而已。
另外 rgss 不等于 Ruby !!
综上——我什么代码也不会。。
作者: yagami 时间: 2014-7-31 00:00
- #include <iostream>
- #define 喵 {
- #define 呜 }
- #define 喵呜 <<
- #define 喵喵 using namespace std;
- #define 呜呜 cout
- #define 呜喵 endl
- #define 喵喵呜 ;
- #define 喵呜喵 int
- #define 呜呜喵 cout
- #define 呜喵呜 main()
- 喵喵 喵呜喵 呜喵呜 喵 呜呜 喵呜 "我种下一颗种子" 喵呜 呜喵 喵喵呜 呜呜 喵呜 "终于长出了果实" 喵呜 呜喵 喵喵呜 呜呜 喵呜 "今天是个伟大日子" 喵呜 呜喵 喵喵呜 呜
复制代码
作者: gonglinyuan 时间: 2014-7-31 08:09
876加几 发表于 2014-7-30 18:07
继续演示!!!
Public Module Judge
C的最大公因数(只支持两个数,但仅有一行)- int gcd(int a,int b) {return b?gcd(b,a%b):a;}
复制代码
作者: gonglinyuan 时间: 2014-7-31 08:26
本帖最后由 gonglinyuan 于 2014-7-31 08:29 编辑
876加几 发表于 2014-7-30 18:07
继续演示!!!
Public Module Judge
检测一个数是否是质数(Miller_Rabin+二次探测定理)(理论复杂度O(log N),18位十进制整数也秒出解)- long long mul(long long a,long long b,long long n)
- {
- long long ret=0;
- while (b)
- {
- if (b&1) ret=(ret+a)%n;
- a=(a+a)%n; b>>=1;
- }
- return ret;
- } // 快速乘
- long long exp(long long a,long long b,long long n)
- {
- long long ret=1;
- while (b)
- {
- if (b&1) ret=mul(ret,a,n);
- a=mul(a,a,n); b>>=1;
- }
- return ret;
- } // 快速幂
- bool miller_rabin(long long n)
- {
- if(n==2||n==3||n==5||n==7||n==11) return true;
- if(n==1||!(n%2)||!(n%3)||!(n%5)||!(n%7)||!(n%11)) return false;
- long long x,pre,u;
- int i,j,k=0;
- u=n-1;
- while(!(u&1)) {k++; u>>=1;}
- srand((long long)time(0));
- for (i=0;i<S;++i) // S是测试次数,越大正确率越高,一般大于5之后就基本全对
- {
- x=rand()%(n-2)+2;
- if(!(x%n)) continue;
- x=exp(x,u,n);
- pre=x;
- for (j=0;j<k;++j)
- {
- x=mul(x,x,n);
- if (x==1&&pre!=1&&pre!=n-1) return false; //二次探测定理
- pre=x;
- }
- if (x!=1) return false; //费马小定理
- }
- return true;
- }
复制代码
作者: delv26 时间: 2014-7-31 08:39
Python死(虽然我写过几个MCE滤器
Ruby活(?
VB.NET好吃但属于MS……
剩下的就是些HTMLCSSJavascriptJavaPHP和讨厌的Pascal(语言本身挺好只是被拿去干某些事情非常不爽
还有易语言(
作者: 876加几 时间: 2014-7-31 09:06
说实话,我被@taroxd 吓了一跳,但是我还会……做路
作者: taroxd 时间: 2014-7-31 09:11
876加几 发表于 2014-7-31 09:06
说实话,我被@taroxd 吓了一跳,但是我还会……做路
我只是新手而已,说实话一种代码都没有精通
周围的大触多了去了
作者: 我是大仙 时间: 2014-7-31 11:38
我会AGM(←这个不算)
和一丢丢易语言
作者: 弗雷德 时间: 2014-7-31 12:03
本帖最后由 弗雷德 于 2014-7-31 12:07 编辑
俺会RGSS,俺不会数学
俺会画立绘CG,俺更擅长像素画
俺会3DSMAX,俺不会MAYA
俺会ZBRUSH,俺更精通骨骼动作{:4_117:}
俺会喝酒,但是俺抽烟更牛X
美工来打酱油{:4_117:}
但是俺更擅长当老板{:4_117:}
作者: zeldafd 时间: 2014-7-31 12:32
現在我PHP能寫MVC框架, JAVA能在ANDROID寫遊戲引擎和軟件, RUBY現在也能寫點腳本, C++用來在CRYENGINE改框架
作者: 菜鸟飞呀飞 时间: 2014-8-2 09:21
提示: 作者被禁止或删除 内容自动屏蔽
作者: taroxd 时间: 2014-8-2 12:28
本帖最后由 taroxd 于 2014-8-2 12:31 编辑
菜鸟飞呀飞 发表于 2014-8-2 09:21
会抽烟喝酒打牌,特长吃,爱好吃
别人不知道你知道的,只是别人学了你不知道他知道的
人的知识都是学来的, ...
知识不一定要实用,学习知识的过程本身也是一种享受
我也享受写代码,玩RM的过程。
个人理解,不喜勿喷
作者: 菜鸟飞呀飞 时间: 2014-8-2 21:47
提示: 作者被禁止或删除 内容自动屏蔽
作者: 刺夜之枪 时间: 2014-8-2 21:49
JAVA学校学 RUBY 自学刚学 C++学校学
作者: 君虫丶 时间: 2014-8-3 13:40
首先,要有电脑
作者: 寒冷魔王 时间: 2014-8-3 17:44
ActionScript2.0
作者: 寒冷魔王 时间: 2014-8-3 17:47
不知有没有会Java的
作者: 月下の戰鬼 时间: 2014-8-3 18:39
{:2_276:}我只知道小电影的神秘代码。。。
{:2_252:}
作者: ali 时间: 2014-8-4 13:59
哎呦 我说出来都会吓死你 我会Minecraft OP代码...正在学C语言
欢迎光临 Project1 (https://rpg.blue/) |
Powered by Discuz! X3.1 |