Skip to content
프로젝트

소개

양자 자살을 사용해 역인과성을 시뮬레이션합니다.

기타 프로젝트

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

quantum

Simulate reverse causality using quantum suicide.

import quantum
x = quantum.choice([1,2,3,4,5,6])  # creates 6 universes
quantum.assert_(x > 3)  # destroys universes 1,2,3
quantum.assert_(x < 6)  # destroys universe 6
print(x)  # prints either 4 or 5

quantum.choice(sequence)

Returns every element of the provided sequence, each in a different alternative universe (which this call creates). If the provided sequence is empty, this is equivalent to quantum.fail().

quantum.fail()

Silently and instantaneously destroys the universe, preventing you from observing the timeline in which this call was made. Warning: Only useful if a previous call to quantum.choice() has created other universes. See notes below.

quantum.assert_(condition)

Shorthand for if not condition: quantum.fail().

Examples

Quantum sort

def qsort(xs):
    # choose a permutation of the input
    r = quantum.choice(itertools.permutations(xs))
    # assert that it's sorted
    quantum.assert_(all(r[i - 1] <= r[i] for i in range(1, len(r))))
    # return it
    return r

print(qsort([3, 0, 5, 1, 2]))  # prints [0, 1, 2, 3, 5]

Sudoku solver

def solve(board):
    '''
    Given a Sudoku puzzle as a list of 81 ints in {0,...,9}
    with 0 representing an empty cell, solve the puzzle in-place.
    '''
    for i in range(81):
        if board[i] == 0:
            neighbors = set(board[j] for group in GROUPS[i] for j in group)
            board[i] = quantum.choice(x for x in range(1, 10) if x not in neighbors)

board = [0] * 81
solve(board)
printboard(board)

Output:

1 2 3 4 5 6 7 8 9
4 5 6 7 8 9 1 2 3
7 8 9 1 2 3 4 5 6
2 1 4 3 6 5 8 9 7
3 6 5 8 9 7 2 1 4
8 9 7 2 1 4 3 6 5
5 3 1 6 4 2 9 7 8
6 4 2 9 7 8 5 3 1
9 7 8 5 3 1 6 4 2

Notes

How it works: Because you can never observe a scenario in which fail has been called (since it destroys the universe), you will necessarily observe a "fortuitous" timeline in which the values returned by choice cause your program to complete without ever calling fail. Be careful to ensure that such a timeline exists!

Do not run a program that calls fail() unconditionally or in every timeline. Such a program destroys every universe in which it runs correctly, so the only observable outcome is one in which an extremely unlikely (and potentially dangerous) event prevents it from completing.

When there are multiple possible (non-failing) executions of a quantum program, we consistently end up observing the lexicographically smallest one with respect to the iteration order of sequences passed to choice. This phenomenon remains unexplained.

관련 프로젝트 살펴보기

불러오는 중…