# 编写一个数学函数，其结果为“ hello world”。

9

``````print(2*2*3*59*61*97*416510539*72330832279)==int("68656c6c6f20776f726c64", 16)
``````

• 您可以选择自己的方式将“ hello world”编码/表示为整数。还允许使用哈希函数

• 允许使用数学库（例如numpy，GMP）。

• 目的是专注于数学部分

1

Kendall Frey 2014年

4

1
@kylek由于您没有指定“最有创意/最英勇”之外的确切获胜标准，因此我自由地将人气竞赛添加为获胜标准。
Victor Stafusa 2014年

2
（在本网站的上下文中）所有计算机数据和程序都可以用数字简单地表示-因为这是发明人（巴贝奇等人）使用的模型。同样允许任何编码实际上只是一场竞赛，争夺谁可以编写产生数字的最具创造力的程序。暗示源代码应使用“数学运算”，但是程序所做的任何事情都可以建模为数学运算。建议您要求使用ASCII编码，然后进行竞赛以将其表示为“特殊数字”，请参阅：www2.stetson.edu/~efriedma/numbers.html
2014年

1

Tim Seguine 2014年

14

Python 2.7

``````>>> import random
>>> n=[(15,30,15,25,15,0,-15,-25,-15,-30,-15),(107,35,34,26,22,0,71,188,94,64,81)]
>>> random.seed(4711)
>>> m = zip("MERRY CHRISTMAS",*n)
>>> print(''.join(map(lambda x:chr(ord(x)+random.randint(x,x)),m)))

hello world
``````

jmiserez 2014年

25

``````1767707668033969 / 3656158440062975
``````

``````0.helloworldhelloworldhelloworldhelloworldhelloworld...
``````

``````2399843759207982499621172523113947162810942763812298565948669
/ 1357602166130257152481187563160405662935023615
``````

``````helloworld.helpimtrappedinanumberfactoryhelpimtrappedinanumberfactoryhelpimtrappedinanumberfactory...
``````

12

# Python （尚未完成...！）已完成！：D

``````number = ((sum(b'This text will end up converting to the text "hello world" by a bunch of math.') *
sum(b'For example, multiplication will be used to increase the number so that it may reach the required result.') *
sum(b'Wow, double multiplication! The required result number is extremely big so I have to use lots of math to get there.') *
sum(b'TRIPLE multiplication?!?!?! Wow!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Did I put too many exclamation points?') *
sum(b'I think maybe I might have put too many exclamation points, oops. :(') *
sum(b'This is taking a long time...') *
sum(b'A very, very, very long time...')) // 2)

number -= (sum(b'Okay, the number is a bit too high. Blah. This is extremely hard.') *
sum(b'I need to reduce it. I will just keep multiplying again! Yay! That seems effective!') *
sum(b'I don\'t know what to write now... I used up all my creativity in the previous number.') *
sum(b'So. Uhhh, how has your day been? Was it good? I wonder how many people are still reading.') *
sum(b'Gah! There is nothing to type about anymore! I will just type randomness then.') *
sum(b'Do you like pie? I like pie. Refrigerator. The chicken ate the potato. Llamas are not tasty.'))

number -= (sum(b'Blah, I am still a tiny bit too high!') *
sum(b'This is very frustrating!') * sum(b'Argh!!!!!!!') *
sum(b'I have even less creative ideas now since I have written two paragraphs already.') *
sum(b'Well, I suppose they\'re not paragraphs. They\'re just blocks of code.') *
sum(b'The only reason I made that remark was to increase this number to subtract, so that I reach my target.'))

number -= (sum(b'I am an extremely miniscule amount over the target!!!') *
sum(b'I am so close!!! So close!!') *
sum(b'I must make it!!! I will!!!') *
sum(b'I shall NEVER give up!!!') *
sum(b'Okay, ummm... maybe not exactly "never"...') *
sum(b'I mean, this is REALLY hard...'))

number -= (sum(b'I am so close. This is just ridiculous.') *
sum(b'Just ridiculous. And that\'s awesome :D') *
sum(b'Why am I doing this?!?') *
sum(b'The answer\'s probably "becase I can."') *
sum(b'Notice how most of the text in this program is meaningless.'))

number -= (sum(b'How have I been above my target this whole time? That is very odd.') *
sum(b'I wonder how much time I could have saved if I removed a few characters in the first block.') *
sum(b'I wish I did that. That would have made it so much easier.... But oh well.') *
sum(b'Well, I am really really really really really really close now!'))

number -= (sum(b'I am so close!') *
sum(b'I will never give up now! Not after all this!') *
sum(b'I wonder if I will ever get exactly on the target. What if I do, and then discover a typo? :O') *
sum(b'So close!'))

number -= (sum(b'Wow; this is the eighth block. That\'s a lot of blocks!') *
sum(b'I only have a little more to go! I must finish! I will!') *
sum(b'It is starting to get harder thinking of things to type than it is getting to the target...'))

number -= (sum(b'These strings are short') *
sum(b'So the number to subtract is less') *
sum(b'Hi'))

sum(b'That\'s new') *
sum(b':D'))

number -= (sum(b'I am back to subtraction, and also longer strings.') *
sum(b'But this time I only get two strings!'))

number -= (sum(b'I have switched over to adding the strings, not multiplying them!') +
sum(b'I am really really close! So close that I can\'t even multiply two strings to subtract anymore!') +
sum(b'This is very exciting; I\'ve nearly made it! Only a few more strings to add...') +
sum(b'I ran out of ideas for what to type again... I will just type exactly what I am thinking, which is what I am doing now actually.') +
sum(b'But now the only thing I am thinking about is getting to the target, and there is not much about that to type...') +
sum(b'I am only a few thousand away!!!!!!!!!!!!'))

number += 8 # NOOOOOOOOOOOOOOOOOOOOOOOOOOOOO

print(number)
``````

kyle k 2014年

1

2

tomsmeding

8

## 的PHP

``````<?=1?>
``````

14
`10`在碱基的“hello world”

7

# 计算器字体/ FreePascal

1. 计算7734/100000。将前导零更改为蓝色，将其他数字更改为计算器字体。颠倒过来。蓝色的O代表世界： ``````uses graph;
var gd, gm : integer;
var n,m:integer;

begin
gd := D4bit;
gm := m640x480;
initgraph(gd,gm,'');
setcolor(black);

For n:=0 to 5  do for m:=0 to 3 do begin;
setfillstyle(solidfill,(abs(n*2-1)));

if((\$967EEF shr (20-n*4+m)) and 1) = 1
then sector(50+n*80,100,90*m,90*(m+1),40,60);

if((\$EDF7E9 shr (20-n*4+m)) and 1) = 1
then sector(50+n*80,300,90*m,90*(m+1),40,60);
end;

closegraph;
end.
`````` kyle k

3

## Ruby和Python

``````%w(hello world).map{|n|n.to_i(36)}
``````

``````[29234652, 54903217]
``````

``````def f(words); words.split.map{|n|n.to_i(36)}; end
``````

``````f("hello world")
=> [29234652, 54903217]
``````

``````def f(words): return map(lambda n: int(n,36), words.split())
``````

``````>>> f("hello world")
[29234652, 54903217]
``````

3

``````\$x=18306744;
\$w=(\$z=(\$y=30)/3)/2;
echo base_convert(\$x, \$z, \$y+\$z/\$w),chr(\$y+\$z/\$w).base_convert(\$x*(\$y/\$z)-\$w*41*83,\$z,\$y+\$y/\$w);
``````

kyle k 2014年

1

# R6RS计划

``````#!r6rs
(import (rnrs))
(define (hello-world)
(bitwise-xor (fold-left (lambda (acc d)
(+ (* acc 256)
(+ (bitwise-and 255 acc) d)))
104
'(-3 7 0 3 8 0 -8 3 -6 -8))
(bitwise-arithmetic-shift 87 40)))
``````

``````126207244316550804821666916
``````

# 球拍（方案方言）

``````(define (hello-world)
(bitwise-xor (foldl (lambda (d acc)
(+ (* acc 256)
(+ (bitwise-and 255 acc) d)))
104
'(-3 7 0 3 8 0 -8 3 -6 -8))
(arithmetic-shift 87 40)))
``````

1

# 的JavaScript

``````function stringTheory(theory) {
var proof = 0;
var principles = theory.split(/[ ,.'-]/);
for (var i = 0; i < principles.length; i++) {
var formula = '';
for (var j = 0; j < principles[i].length; j++) {
formula += principles[i].charCodeAt(j).toString(10);
}
proof += +formula;
}
return proof;
}

console.log(
/* \2 and \3 are start of text and end of text characters */
stringTheory('\2 Yo it\'s 4327 - Go to space, look back, and see the dot of a small blue rock you once sat on amid the vast empty void - KA-BOOM - you are in awe of it. "Ah" - so tiny in this vast space yet you are even more so. A mere atom in an ocean of stars, the earth a speck of dust to the sun\'s ping-pong ball. One day you shall go back and as your toes touch the soft soil once more, the cool wind in your hair as you cast your gaze upon the moon, a mere rock just like this one, and bask in it\'s warm glow - Ah. Only then can you know the scale of it all, what luck you have to call this place home.  And with this new ken, a love you\'ve kept for all of time but had not seen - for it is clear to you now. You lay open your arms and fill the air with your song - (aah) ~o Good-bye space and ... o? \3') + 42
);
``````

### 到底是怎么回事？

`'\2 Yo it\'s 4327 - Go to space, look back, and see the dot of a small blue rock you once sat on amid the vast empty void - KA-BOOM - you are in awe of it. "Ah" - so tiny in this vast space yet you are even more so. A mere atom in an ocean of stars, the earth a speck of dust to the sun\'s ping-pong ball. One day you shall go back and as your toes touch the soft soil once more, the cool wind in your hair as you cast your gaze upon the moon, a mere rock just like this one, and bask in it\'s warm glow - Ah. Only then can you know the scale of it all, what luck you have to call this place home. And with this new ken, a love you\'ve kept for all of time but had not seen - for it is clear to you now. You lay open your arms and fill the air with your song - (aah) ~o Good-bye space and ... o? \3'`

1

# 蟒蛇

``````from math import fsum
c=[104.,-4412.705557362921,12008.518259002305,-13041.051140948179,7566.060243625142,-2619.91695720304,567.427662301322,-77.52280096313,6.48776455347,-0.303552138602,0.006079144624]
def f(x):
return fsum([c[i]*x**i for i in range(len(c))])
s=""
for i in range(11):
s+=chr(int(round(f(i))))
print s
``````

0

## 红宝石

``````# encode string to integer
def str_to_int(s)
i = 0
s.chars.each do |c|
i = i << 7 | c.ord
end
i
end
``````

``````# decode integer to string
def int_to_str(i)
s = ''
while i > 0 do
s = (i & 0x7f).chr + s
i = i >> 7
end
s
end
``````

``````str_to_int("ABC")
=> 1073475
int_to_str(1073475)
=> "ABC"

str_to_int("hello world")
=> 123720932638399026476644
int_to_str(123720932638399026476644)
=> "hello world"
``````

0

C＃

``````string Encode(string text)
{
string hexValue = String.Empty;
foreach(char c in text)
hexValue += String.Format("{0:X}", (int)c);
return hexValue;
}
``````

``````string Decode(string hexValue)
{
string text = String.Empty;
for (int i = 0; i < hexValue.Length; i += 2)
{
int value = Convert.ToInt32(hexValue.Substring(i, 2), 16);
text += (char)value;
}
return text;
}
``````

``````using System;

namespace ConsoleApplication1
{
class Program
{

static string Encode(string text)
{
string hexValue = String.Empty;
foreach(char c in text)
hexValue += String.Format("{0:X}", (int)c);
return hexValue;
}

static string Decode(string hexValue)
{
string text = String.Empty;

for (int i = 0; i < hexValue.Length; i += 2)
{
int value = Convert.ToInt32(hexValue.Substring(i, 2), 16);
text += (char)value;
}

return text;
}

static void Main(string[] args)
{
string Text1 = "Hello World!";
Console.WriteLine("Before Encoding: " + Text1 + "\n");

string Hex = Encode(Text1);
Console.WriteLine("After endoding: " + Hex + "\n");

string Text2 = Decode(Hex);
Console.WriteLine("After decoding: " + Text2 + "\n");
}
}
}
`````` 0

## 蟒蛇

``````def D(A):
try:
return sum(D(x)**2 for x in A)
except TypeError:
return A
print hex(D([[[[33,22,3,1],[20,13,2],5],[[31,19,1],[11,5,3],1]],[[[26,13],[18,14,6,4],1],[[12,10],[10,3,1],2],4],28]))
``````

（也许<= 1的基本情况会很有趣...）

0

## 蟒蛇

``````def church(i):
if i > 0:
return 'f(' + church(i-1) + ')'
else:
return 'x'

def church_string(bs):
import base64
return church(int(base64.b16encode(bs), 16))

print(church_string(b'hello world'))``````

0

``````int main()
{
int a , b, c;
double i = 0, f = 0;

for (; i < 1; i += .00000012785666)
f += cos(i);
c = f;
a = f * 276.393089;
b = a + f * 7.4358109;

printf("%.4s%.4s%.4s\n", &a, &b, &c);
}
``````