結果が「hello world」である数学関数を記述します[終了]


9

「hello world」の整数表現となる数学関数を記述します

たとえば、16進68656c6c6f20776f726c64数の「hello world」は、「hello world」を表す数値を生成する数学的なプログラムを作成することを目的としています。

以下は、pythonを使用した可能な解決策の例です。

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

べき乗、級数、階乗、その他の数学演算など、あらゆるタイプの数学方程式を使用できます。

ルール:

  • 「hello world」を整数としてエンコード/表現する独自の方法を選択できます。ハッシュ関数も許可されています

  • 数学ライブラリ(numpy、GMPなど)が許可されています。

  • 意図は数学の部分に焦点を当てることです


1
創造性は客観的ではありません。人気コンテストを考えていますか?
Kendall Frey

4
エンコーディングを決定できる場合は、任意の整数で「hello world」を表すことができます。例= -1 = "hello worlc"、0 = "hello world"、1 = "hello worle"など
Kendall Frey

1
@kylekあなたが「最も創造的/独創的」なものを超える正確な勝者基準を指定しなかったので、私は勝者基準として人気コンテストを自由に追加しました。
Victor Stafusa 2014年

2
(このWebサイトのコンテキストでは)すべてのコンピューターデータとプログラムは、数として簡単に表すことができます。これは、発明者(Babbageなど)が使用したモデルだからです。また、エンコーディングを許可することで、数値を生み出す最も創造的なプログラムを誰が書けるかというコンテストになります。ソースコードで「数学演算」を使用する必要があるという含意がありますが、プログラムが行うことはすべて、数学演算としてモデル化できます。ASCIIエンコーディングが必要であることを提案し、それを「特別な番号」として表現することについてコンテストを行う。参照:www2.stetson.edu/~efriedma/numbers.html
user2460798

1
あなたはあなたの数学用語で非常に速く、ゆるく遊んでいます。「方程式」と「関数」を交換可能に使用しているようです。あなたが探していた言葉は「表現」だと思います。しかし、それでも問題はうまく提起されていません。私が選んだ "hello world"の数学的エンコーディングは、元のK&R hello worldソースコードです。ああ、それはうまくいきます!
Tim Seguine 2014年

回答:


14

Python 2.7

乱数ジェネレーターの乱用は、Python 2.7では機能しますが、Python 3.xでは機能しません。これは、ジェネレーターがシードアルゴリズムを変更したためです。

>>> 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[0])+random.randint(x[1],x[2])),m)))

hello world

これは私を私の机で大声で笑わせました。人々は今私を見つめています:-/
jmiserez '

25

ただ印刷するより上手くやる、何度も無限に印刷します!

有理数

1767707668033969 / 3656158440062975

次のbase-36拡張を返します。

0.helloworldhelloworldhelloworldhelloworldhelloworld...

やってみて!(ウォルフラムアルファ)

または、よりサブリミナルなメッセージが必要な場合は、以下を試してください。

2399843759207982499621172523113947162810942763812298565948669
/ 1357602166130257152481187563160405662935023615

これは(ベース36でも)戻ります:

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'))

number += (sum(b'Finally adding') *
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)

出力126207244316550804821666916(例に相当0x68656c6c6f20776f726c64


あなたは私が求めていることをよく理解しています。
kyle k 2014年1

1
ラマは美味しくない」haha +1
assylias 2014年

2
これは勝つはずです。
tomsmeding 2014年

8

「hello world」を整数としてエンコード/表現する独自の方法を選択できます。

じゃあ...

PHP

<?=1?>

ここで、1は「hello world」を表します。


14
10ベース
EmilVikström2014年

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;

  readln;
  closegraph;
end.

ここに画像の説明を入力してください

円は0-5の番号が付けられ、色はabs(2n-1)によって決定されます。円ごとに1桁の16進数、最下位ビットから右下に時計回りに四分円が色分けされます。ミステリック定数967EEFおよびEDF7E9 hex。

FreePascalで複製できるようにTurboPascalに入れてくれた以下のプリミティブとBorlandに特に感謝します。

プロシージャSector(x:SmallInt; y:SmallInt; StAngle:Word; EndAngle:Word; XRadius:Word; YRadius:Word); Sectorは、楕円の扇形を描画し、中心(X、Y)と半径XRadiusおよびYRadiusで塗りつぶします。角度Startで始まり、角度Stopで終わります。


私はこれまでこの方法を考えたことはありませんでした。
kyle k

3

RubyとPython

ベース36の数学を使用すると、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

注意深く作成されたPHPの一部:

$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

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)))

出力#x68656c6c6f20776f726c64(10進数):

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
);

何が起こっている?

この文字列を使用して少し適用します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'

まず、句読点で分割して単語を形成します。次に、文字を10進数のASCIIコードに変換して一連の数値を作成します。隣接する文字は隣接する数字になります(例:にaaなる9797)。

その後、数値が合計されます。私たちが返すのは191212222216169、まったく役に立たない数です。それは、空間で空中に浮かんでいる岩石の四分の一のように、意味がありません。この世界は何が特別なのですか?なぜそれが人生なのか。したがって、この数に生命意味を与えることで、次の+=42ようになり191212222216211ます。

しかし、なぜ?

これは何を意味するのでしょうか?stringTheory("Hello world")もちろんそれが意味する理由。


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#

任意の文字列(hello worldなど)を16進数の文字列に変換する方法

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

16進数文字列を文字列に変換する方法

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;
}

ここに完全なC#プログラムがあります

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]))

再帰的に、ターゲット数を最大で4乗の合計に分解します。私のベースケースは100未満です。私はhttp://www.alpertron.com.ar/FSQUARES.HTMを使用して分解を計算しました。

(おそらく<= 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

数字を使ったちょっとしたCの楽しみ、特別なことは何もありません。

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);
}

デモ


弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.