4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

万物についての究極の疑問の答えを出力する関数

Last updated at Posted at 2024-05-24

コード

生命、宇宙、そして万物についての究極の疑問の答えを出力するコードです。
ぜひ実行して真理に触れてみてください。

import numpy as np
from scipy.fft import fft
import time

def life(age, nationality, name):
    fib_seq = [0, 1]
    for i in range(6): 
        fib_seq.append(fib_seq[-1] + fib_seq[-2])
        time.sleep(0.5)
        print(f"\r{name} calculates the next life number: {fib_seq[-1]}", end="")
    return fib_seq

def universe():
    planck_base = 6.62607015e-34
    scale_factor = 1e34
    planck_constant = 0
    for i in range(1, 11):
        planck_constant += (planck_base * scale_factor) / 10 
        time.sleep(0.5)
        print(f"\rUniverse constant being calculated: {planck_constant:.2e}", end="")
    
    meaning_of_life = np.pi * np.e
    time.sleep(0.5)
    print(f"\rCalculated Planck constant: {planck_constant:.2e}, and the meaning of life constant: {meaning_of_life:.2f}", end="")
    
    return planck_constant, meaning_of_life

def calculate_subtle_catalan(n):
    result = 1
    for i in range(2, n + 1):
        result *= (n + i) / i
        print(f"\rCalculating hidden element: {result:.2f}", end="")
        time.sleep(0.5)
    return np.ceil(result)

def everything(fib_seq):
    catalan_result = calculate_subtle_catalan(5)

    fib_fft = fft(fib_seq)
    meaningful_index = np.argmax(np.abs(fib_fft))

    sum_fib = sum(fib_seq) + meaningful_index
    result = (sum_fib * 2) % catalan_result
    if result != catalan_result:
        result = catalan_result
    return result, meaningful_index

def answer_to_the_ultimate_question_of_life_the_universe_and_everything(age, nationality, name):
    fib_sequence = life(age, nationality, name)
    planck, philosophy = universe()
    final_result, fft_index = everything(fib_sequence)
    
    return fib_sequence, planck, philosophy, fft_index, final_result

# Example usage
age = 30
nationality = "Globetrotter"
name = "Arthur Dent"
fib_sequence, planck, philosophy, fft_index, final_result = answer_to_the_ultimate_question_of_life_the_universe_and_everything(age, nationality, name)

print("\rAnswer to the Ultimate Question of Life, the Universe, and Everything is  :  ", int(final_result))

何の話?

以下を導出するようなコードをchatGPTに書いてもらったという話です。

つまりジョークプログラムです。
途中で無駄な公式や定理、数式をはさみつつ、最終的に42にこじつけるようなコードを書いてもらいました。

苦労した点

環境はGPT4oで遊びました。

「生命、宇宙、そして万物についての究極の疑問の答えで42を出力するようなジョークプログラムを作成してくれ」という指示をしたら、最初はprint文で面白文章をいろいろ出力して結局やってることはreturn 42というクソつまらないコードを出力してきました。

次に「物理学や数学、哲学などに関する計算式を追加したうえで42を導出するようなものを入れてください、例えばフィボナッチ数列やオイラーの等式、フーリエ変換など何でもいいですがこじつけでも良いので42を導出する結果としてください。」と指示を加えたところ、いろいろ書いてきたのですがなんと結果が8にならないというコードを書いてきました。

そこからしばらく42にならないコードを吐き出し続けたので、これはトークンの限界で最初のほうの指示が抜けたかなと思い(4oは30000だと思うんですけどね)、
経過のコードだけもらって最初から指示をやりなおしたところ、途中の計算は無駄に謎なジョークコードを入れてくれたものの最後が以下のように超詰まんない帳尻合わせをしてきました。

    mod_index = (int(planck_constant) + int(meaning_of_life) + meaningful_index + sum_fib) % 42
    if mod_index == 0:
        result = 42
    else:
        result = 42 - mod_index

しょうがないのでこっちから
「42というハードコーディングが直接的すぎます。たとえば5番目のカタラン数であることを利用するとか、6番目の矩形数であることを利用する。2番目の楔数である。20番目のハーシャッド数である。であることを利用してください。」
と指示して、そこからもジョークがわからないものを出力してきたのを何回かピンポンし
なんとかそれっぽいのを作ってくれました。

こっちの指示も悪かったでしょうけど、4oでも無茶ぶりは厳しいですね。

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?