阿尔尔..。喂,我的马提斯!展开主帆!右舷满了!啊,感觉风吹在你的头发上!
对,我亲爱的..。我需要一点你的技能!我的船员比我自己更现代化..。我仍然更喜欢th指南针的‘th’点(更多信息见这里,Arrr.)当我的船员总是用头.我想要一种简单的方法,把这个废话变成我能理解的东西,Arrr!
我需要的是输入一个数字(小数是好的)的代码,比如“0 <= the headin' < 360”,它把答案作为最接近的指南针点!阿尔尔!
以下是一些例子:
> heading 0.1
North
> heading 11.25
North by East
> heading 22.7
North Northeast
> heading 44.99
Northeast
> heading 91
East
现在,如果你的头正好落在两个指南针的中间,我亲爱的,别担心.我期待着‘这’代码吐出Between <point 1> and <point 2>,例如,heading 5.625会说,Between North and North by East只会发生在一个头部,即H = 5.625 + 11.25(N)方程,其中H是‘headin’,N是0到31之间的整数.
两个限制.
( 1)我不想用数组来存储点或头的数据。你在欺骗我,先生,你在品尝我的过失.这是必须计算的,朱斯,就像过去的日子一样!阿尔尔!
2)最短的代码获胜,否则我会让你走在木板上.阿尔尔!
发布于 2014-01-04 12:35:00
我花了太多的时间在这里寻宝,但这里有一个Java解决方案:
public class Aaaaarrrr {
public static void main(String[] aaarrrgs) {
float heading = Float.parseFloat(aaarrrgs[0]);
final List<String> points = Arrays.asList("North",
"North by east", "North-northeast", "Northeast by north",
"Northeast", "Northeast by east", "East-northeast",
"East by north", "East", "East by south", "East-southeast",
"Southeast by east", "Southeast", "Southeast by south",
"South-southeast", "South by east", "South", "South by west",
"South-southwest", "Southwest by south", "Southwest",
"Southwest by west", "West-southwest", "West by south", "West",
"West by north", "West-northwest", "Northwest by west",
"Northwest", "Northwest by north", "North-northwest",
"North by west");
float cp = heading / 360.0f * 32.0f;
if (cp % 1 == 0.5f)
System.out.print("Between " + points.get((int)Math.floor(cp)) + " and ");
System.out.println(points.get(Math.round(cp)));
}
}如果我将上面的代码最小化并使其变得很难看,就会编辑如下:
import java.util.*;class A{public static void main(String[] r){List<String> l=Arrays.asList("North","North by east","North-northeast","Northeast by north","Northeast","Northeast by east","East-northeast","East by north","East","East by south","East-southeast","Southeast by east","Southeast","Southeast by south","South-southeast","South by east","South","South by west","South-southwest","Southwest by south","Southwest","Southwest by west","West-southwest","West by south", "West","West by north","West-northwest","Northwest by west","Northwest","Northwest by north","North-northwest","North by west");float c=Float.parseFloat(r[0])/360.0f*32.0f;if (c%1==0.5f) System.out.print("Between "+l.get((int)Math.floor(c))+" and ");System.out.println(l.get(Math.round(c)));}}发布于 2014-01-04 13:36:26
n='north'
e='east'
s='south'
w='west'
b=' by '
def f(H):x,y,z=(n,e,s,w,e,s,w,n,n+e,s+e,s+w,n+w)[int(H%360/90)::4];return(x,x+b+y,x+'-'+z,z+b+x,z,z+b+y,y+'-'+z,y+b+x)[int(H%90*4/45)].capitalize()
h=input()+5.625
print h%11.25and f(h)or'Between '+f(h-1)+' and '+f(h)这使用了维基百科页面上的资本化,并且应该适用于任何数字。
发布于 2014-01-04 14:14:49
A,R,r=int,input()/360.*32,' by #South#north#West#East#south#North#west#east#-#/#Between#and'.split('#')
a=''.join(r[A(c,16)]for c in'6A608A6928A6802A68A6808A4928A402A4A405A4958A1808A18A1805A1958A108A1A107A1957A1705A17A1707A3957A305A3A302A3927A6707A67A6702A6927A607').split('/')
if R%1==.5:print r[11],a[A(R)],r[12],
print a[A(round(R))]谢谢@Jeen
https://codegolf.stackexchange.com/questions/17438
复制相似问题