ํƒœ๊ทธ ๋ณด๊ด€๋ฌผ: primes

primes

ํ”„๋ผ์ž„ ์–ผ๊ฐ„์ด ์ €๊ฒฉ ํŒจํ„ด currentIndex

์ผ๋…„ ์ค‘ ๊ฐ€์žฅ ๊ธด ๋‚ -์—ฌ๊ธฐ ์—ฌ๋ถ„์˜ ์‹œ๊ฐ„์„ ๋‚ญ๋น„ํ•˜๋Š” ๊ฒƒ์ด ์žˆ์Šต๋‹ˆ๋‹ค โ€ฆ


๊ฐœ์š”

์ด๊ฒƒ์€ ์ธ๊ธฐ ๊ฒฝ์—ฐ ๋Œ€ํšŒ๊ฐ€ ์•„๋‹ˆ๋ฉฐ ๊ทธ๋ž˜ํ”ฝ ์ถœ๋ ฅ ๋ฌธ์ œ๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค. 65,536 ๊ฐœ์˜ 0๊ณผ 1์˜ ๋ฌธ์ž์—ด ๋งŒ ์ถœ๋ ฅํ•˜๋ฉด๋ฉ๋‹ˆ๋‹ค. ์งˆ๋ฌธ ํ•˜๋‹จ์˜ ์Šคํƒ ์Šค ๋‹ˆํŽซ์€ ์ด๊ฒƒ์„ 256 x 256 ํ‘๋ฐฑ ์ด๋ฏธ์ง€๋กœ ํ‘œ์‹œํ•˜๊ณ  ๊ณต์‹ ์ ์ˆ˜๋ฅผ ๊ณ„์‚ฐํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ ๋‹ค์Œ ์ด๋ฏธ์ง€๋ฅผ ์ €์žฅํ•˜๊ณ  ์ฝ”๋“œ์™€ ํ•จ๊ป˜ ๋‹ต๋ณ€์— ์—…๋กœ๋“œ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค (๋ฌธ์ž์—ด ์ถœ๋ ฅ์ด 30,000 ์ž์˜ ์Šคํƒ ๊ตํ™˜ ๋‹ต๋ณ€์— ๋งž์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์—).


์ฑ„์ 

์ด๋ฏธ์ง€์˜ ์ ์ˆ˜๋Š” ๊ฐœ๋ณ„ ํ”ฝ์…€์˜ ์ ์ˆ˜์˜ ํ•ฉ๊ณ„์ž…๋‹ˆ๋‹ค. ๊ฐœ๋ณ„ ํ”ฝ์…€์˜ ์ ์ˆ˜๋Š” ๊ฐ ์˜์—ญ ์ ์ˆ˜์˜ ํ•ฉ ๋น„ ์ง๊ต , ํ”„๋ผ์ž„ ๊ฑฐ๋ฆฌ ์˜ ํ”ฝ์…€ ๋งŒ ๋ฐ˜๋Œ€ ์ƒ‰์ƒ ํš๋“๋˜๋Š” ํ™”์†Œ. ์ด๋Ÿฌํ•œ ๊ฐ ํ™”์†Œ์— ๋Œ€ํ•œ ๋ถ€๋ถ„ ์ ์ˆ˜๋Š” 1/p์—ฌ๊ธฐ์„œ pํ”„๋ผ์ž„ ๊ฑฐ๋ฆฌ์ด๋‹ค.

์ด ์งˆ๋ฌธ์˜ ๋งฅ๋ฝ์—์„œ ์šฉ์–ด๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ •์˜๋ฅผ ๊ฐ–์Šต๋‹ˆ๋‹ค.

  • ๋น„ ์ง๊ต : ํ”ฝ์…€์ด ๊ฐ™์€ ํ–‰์— ์žˆ์ง€ ์•Š๊ณ  ๊ฐ™์€ ์—ด์— ์žˆ์ง€ ์•Š์œผ๋ฉด ํ”ฝ์…€์ด ์Šค์ฝ”์–ด๋ง๋˜๋Š” ํ”ฝ์…€๊ณผ ์ง๊ตํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

  • ํ”„๋ผ์ž„ ๊ฑฐ๋ฆฌ : ํ”ฝ์…€์ด ์ •ํ™•ํ•˜๊ฒŒ ์†Œ์ˆ˜ ์ธ์œ ํด๋ฆฌ๋“œ ๊ฑฐ๋ฆฌ๋กœ ๋ถ„๋ฆฌ ๋œ ๊ฒฝ์šฐ ํ”ฝ์…€์€ ์Šค์ฝ”์–ด๋ง๋˜๋Š” ํ”ฝ์…€๊ณผ ํ”„๋ผ์ž„ ๊ฑฐ๋ฆฌ์— ์žˆ์Šต๋‹ˆ๋‹ค. ํŠนํžˆ, ๊ฑฐ๋ฆฌ๋Š” ํ™˜์ƒ์ ์œผ๋กœ ์ธก์ • ๋œ ์ตœ์†Œ ๊ฑฐ๋ฆฌ์ž…๋‹ˆ๋‹ค. ์™ผ์ชฝ ์œ„ ํ”ฝ์…€์€sqrt(2)์˜ค๋ฅธ์ชฝ ์•„๋ž˜ํ”ฝ์…€๊ณผ์˜ ๊ฑฐ๋ฆฌ์ž…๋‹ˆ๋‹ค(๋ชจ๋“  4 ๊ฐœ์˜ ๊ฐ€์žฅ์ž๋ฆฌ ๋žฉ).

  • ๋ฐ˜๋Œ€ ์ƒ‰์ƒ : ํ”ฝ์…€์˜ ๊ฐ’์ด 1 ์ธ ๊ฒฝ์šฐ ์Šค์ฝ”์–ด๋ง๋˜๋Š” ํ”ฝ์…€๊ณผ ๋ฐ˜๋Œ€ ์ƒ‰์ƒ์ž…๋‹ˆ๋‹ค. ์ฆ‰, ์ฒซ ๋ฒˆ์งธ๋Š” 0์ด๊ณ  ๋‘ ๋ฒˆ์งธ๋Š” 1์ด๊ฑฐ๋‚˜ ์ฒซ ๋ฒˆ์งธ๋Š” 1์ด๊ณ  ๋‘ ๋ฒˆ์งธ๋Š” 0์ž…๋‹ˆ๋‹ค.

์Šคํƒ ์Šค ๋‹ˆํŽซ์—๋Š” ์ด๋ฏธ์ง€์˜ ์ ์ˆ˜๋ฅผ ๋งค๊ธฐ๋Š” ๋ฐฉ๋ฒ•์„ ๋ณด์—ฌ์ฃผ๋Š” ์˜ˆ์ œ ์ฝ”๋“œ๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ์ง€๋งŒ ์ตœ์ ํ™” ๋˜๋Š” ํšจ์œจ์ ์ธ ์ ‘๊ทผ ๋ฐฉ๋ฒ•์€ ํฌํ•จ๋˜์–ด ์žˆ์ง€ ์•Š์œผ๋ฉฐ ์ฝ”๋“œ ๋งŒ ์ˆ˜์ •ํ•˜๋ฉด ์ตœ์ข… ์ด๋ฏธ์ง€์˜ ์ ์ˆ˜๋ฅผ ์ผ๊ด€๋˜๊ฒŒ ์ˆ˜ํ–‰ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ฝ”๋“œ์˜ ๋‚ด์šฉ์ด ์ •ํ™•ํ•˜์ง€ ์•Š์€ ๊ฒฝ์šฐ ์˜๊ฒฌ์ด๋‚˜ ์ฑ„ํŒ…์œผ๋กœ ์•Œ๋ ค์ฃผ์‹ญ์‹œ์˜ค .

JavaScript ๊ฐ€์ด ํŠน์ • ๋„์ „ ์— ๋Œ€๋‹ต ํ•˜๊ธฐ์œ„ํ•œ ์ตœ์ƒ์˜ ์–ธ์–ด ์ผ ํ•„์š”๋Š” ์—†์Šต๋‹ˆ๋‹ค . Snippet ์ฝ”๋“œ๋Š” ์˜๋„์ ์œผ๋กœ ๋” ๋น ๋ฅธ ์ ‘๊ทผ ๋ฐฉ์‹์— ๋Œ€ํ•œ ๋‹จ์„œ๋ฅผ ์ œ๊ณตํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๊ธฐ์กด ๋‹ต๋ณ€์—์„œ ์ด๋ฏธ ์ž…์ฆ ๋œ ํšจ์œจ์„ฑ ๋งŒ ์†Œ๊ฐœ ํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค.


์‹ฌ์ƒ

์Šค์ฝ”์–ด๋ง ํ”ฝ์…€

์Šค์ฝ”์–ด๋ง ํ”ฝ์…€์˜ ๋ถ„ํฌ์— ๋Œ€ํ•œ ์ง๊ด€์  ์ธ ๋Š๋‚Œ์„์ฃผ๊ธฐ ์œ„ํ•ด, ์—ฌ๊ธฐ (๋ณด๋ผ์ƒ‰)๋Š” 256 x 256 ์ด๋ฏธ์ง€์˜ ํ”ฝ์…€ (128, 128)์— ๋Œ€ํ•œ ๋น„ ์ง๊ต ์ฃผ์š” ๊ฑฐ๋ฆฌ ํ”ฝ์…€์ž…๋‹ˆ๋‹ค.

๋น„ ์ง๊ต ์ฃผ์š” ๊ฑฐ๋ฆฌ ๋ถ„ํฌ ์ด๋ฏธ์ง€


์ž„์˜์˜ ์ด๋ฏธ์ง€

์ด ์˜ˆ์ œ๋Š” Python 3 ๋‹ต๋ณ€ ์˜ˆ์ œ์—์„œ ์ž„์˜๋กœ ์ƒ์„ฑ ๋œ ์ด๋ฏธ์ง€์ž…๋‹ˆ๋‹ค. ๊ทธ๊ฒƒ์€ 138,267.64์˜ ์ ์ˆ˜๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์œผ๋ฉฐ ๋‹น์‹ ์—๊ฒŒ ์ด๊ธธ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


์ž…๋ ฅ

์ฝ”๋“œ๋Š” ์ž…๋ ฅ์ด ํ•„์š”ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

์‚ฐ์ถœ

์ด ์ฝ”๋“œ๋Š” ํ‘๋ฐฑ 256 x 256 ์ด๋ฏธ์ง€์˜ ํ”ฝ์…€์„ ๋‚˜ํƒ€๋‚ด๋Š” 65,536 ๊ฐœ์˜ 0๊ณผ 1์˜ ๋ฌธ์ž์—ด์„ ์ถœ๋ ฅํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค. ์ˆซ์ž๋Š” ๊ตฌ๋ถ„ ๊ธฐํ˜ธ๊ฐ€์—†๋Š” ์—ฐ์† ๋ฌธ์ž์—ด์ด์–ด์•ผํ•ฉ๋‹ˆ๋‹ค. ํŒŒ์ผ๋กœ ์ถœ๋ ฅํ•˜๋ฉด ๋ณต์‚ฌ ๋ฐ ๋ถ™์—ฌ ๋„ฃ๊ธฐ๊ฐ€ ๋” ์‰ฌ์šธ ์ˆ˜ ์žˆ์ง€๋งŒ ์ด๋Š” ์‚ฌ์šฉ์ž์—๊ฒŒ ๋‹ฌ๋ ค ์žˆ์Šต๋‹ˆ๋‹ค.

๋ฌธ์ž์—ด์„ ๋ณต์‚ฌํ•˜์—ฌ ์Šคํƒ ์Šค ๋‹ˆํŽซ์— ๋ถ™์—ฌ ๋„ฃ์„ ์ˆ˜ ์žˆ์œผ๋ฉด ์ฝ”๋“œ์—์„œ ์œ ์šฉํ•œ ๋‹ค๋ฅธ ์ •๋ณด๋ฅผ ์ถœ๋ ฅ ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ๊ฐ€์žฅ ์ข‹์€ ๋ฌธ์ž์—ด์„ ํŒŒ์ผ์— ์ถœ๋ ฅํ•˜๊ณ  ๊ฐ€์žฅ ์ข‹์€ ์Šค์ฝ”์–ด๋ฅผ ์ •๊ธฐ์ ์œผ๋กœ STDOUT์— ์ถœ๋ ฅํ•˜์—ฌ ์‚ฌ์šฉ์ž๊ฐ€ ๊ฒ€์ƒ‰์„ ์ค‘์ง€ ํ• ์‹œ๊ธฐ๋ฅผ ์„ ํƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


์Šคํƒ ์Šค ๋‹ˆํŽซ

Sp3000 ์—์„œ ์ง€์ ํ–ˆ๋“ฏ์ด ์Šค ๋‹ˆํŽซ์€ ์ ์ˆ˜๋ฅผ ๊ณ„์‚ฐํ•˜๋Š” ๋ฐ 10 ๋ถ„์ด ๊ฑธ๋ ธ์œผ๋ฉฐ , ์˜๋„์ ์œผ๋กœ ๋น„ํšจ์œจ์  ์ธ ์ฐธ์กฐ ๊ตฌํ˜„์˜ ๊ฒฝ์šฐ์—๋„ ๋„ˆ๋ฌด ๋Š๋ฆฝ๋‹ˆ๋‹ค. Sp3000์—์„œ ์Šค์ฝ”์–ด๋ง์„์œ„ํ•œ ํ”ฝ์…€ ์˜คํ”„์…‹ ์‚ฌ์ „ ๊ณ„์‚ฐ์˜ ๊ฐœ์„  ์ œ์•ˆ์„ ํŽธ์ง‘ํ–ˆ์œผ๋ฉฐ ์ด์ œ ์Šค์ฝ”์–ด๋ฅผ ๊ณ„์‚ฐํ•˜๋Š” ๋ฐ ๋ช‡ ์ดˆ๊ฐ€ ๊ฑธ๋ฆฝ๋‹ˆ๋‹ค.

canvas = document.getElementById('canvas')
ctx = canvas.getContext('2d')
scoreArea = document.getElementById('scoreArea')
pastedData = document.getElementById('pastedData')
timeout = 0

primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499]

primesSquared = []
for (i=0; i<primes.length; i++) {
    primesSquared.push(primes[i] * primes[i])
}

width = canvas.width
height = canvas.height
area = width * height

scoringFilter = calculateScoringFilter()

function calculateScore() {
    var percentage = Math.floor(currentIndex / 65536 * 10000) / 100
    scoreArea.value = 'Calculating:' + percentage + '%'
    for (var t=0; t<1000; t++) {
        if (currentIndex < 65536) {
            partialScore += pixelScore(currentIndex)
            currentIndex += 1
        } else {
            scoreArea.value = 'Score: ' + partialScore
            return
        }
    }

    timeout = setTimeout(calculateScore, 10)
}

function pixelScore(i) {
    var score = 0
    var x = i % width
    var y = Math.floor(i / width)
    var a, b, xd, yd, j, k, d, m
    for (k=0; k<scoringFilter.length; k++) {
        bundle = scoringFilter[k]
        m = bundle[0]
        a = m % width
        b = Math.floor(m / width)
        j = ((x+a) % width) + width * ((y+b) % height)
        d = bundle[1]
        score += Math.abs(pixels[i] - pixels[j]) / d
    }
    return score
}

function display(pixels) {
    for (var i=0; i<area; i++) {
        ctx.fillStyle = pixels[i] ? 'white' : 'black'
        ctx.fillRect(i % width, Math.floor(i / width), 1, 1)
    }
}

function stop() {
    clearTimeout(timeout)
    scoreArea.value = 'Calculation cancelled.'
}

function isPrimeSquared(n) {
    return primesSquared.indexOf(n) > -1
}

function applyToImage() {
    var potentialPixels = []
    var pastedString = pastedData.value
    if (pastedString.length !== 65536) {
        scoreArea.value = 'Incorrect length:' + pastedString.length
        return
    }
    var i, digit
    for (i=0; i<pastedString.length; i++) {
        digit = pastedString.substring(i, i + 1)
        if (digit === '0') {
            potentialPixels.push(0)
        } else if (digit === '1') {
            potentialPixels.push(1)
        } else {
            scoreArea.value = 'Invalid character ' + i + ':' + digit
            return
        }
    }
    pixels = potentialPixels
    display(pixels)
    scoreArea.value = 'Calculating score...'
    partialScore = 0
    currentIndex = 0

    timeout = setTimeout(calculateScore, 10)
}

function calculateScoringFilter() {
    var scoringFilter = []
    var i, x, y, xd, yd
    for (i=0; i<area; i++) {
        x = i % width
        y = Math.floor(i / width)
        xd = Math.min(x,(-x+width)%width)
        yd = Math.min(y,(-y+height)%height)
        dSquared = xd*xd + yd*yd
        if (xd && yd && isPrimeSquared(dSquared)) {
            d = Math.sqrt(dSquared)
            scoringFilter.push([i, d])
        }
    }
    return scoringFilter
}
<canvas id='canvas' width='256' height='256'></canvas>
<br>
<input id='scoreArea' rows='1' readonly></input>
<br>
<button onclick='applyToImage()'>Apply string to image</button>
<button onclick='stop()'>Stop</button>
<br>
<br>
Paste in string of 65,536 zeroes and ones here:
<br>
<input id='pastedData'></input>

์ž์‹ ์˜ ์ฝ”๋“œ์˜ ์‹œ์ž‘์ ์œผ๋กœ ์ถœ๋ ฅ ๋˜๋Š” ๋‹ค๋ฅธ ๋‹ต๋ณ€์˜ ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ ์ง€์› ๋‹ต๋ณ€์— ๋Œ€ํ•œ ํฌ๋ ˆ๋”ง๊ณผ ๋งํฌ๋ฅผ ์ œ๊ณตํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค. ์ด ์งˆ๋ฌธ์— ๋Œ€ํ•œ ๋‹ต๋ณ€์€ ์˜ˆ์ œ ๋‹ต๋ณ€์ด๋‚˜ ์งˆ๋ฌธ์˜ โ€‹โ€‹์ฝ”๋“œ๋ฅผ ๊ฐ€๋ฆฌ์ง€ ์•Š์•„๋„๋ฉ๋‹ˆ๋‹ค.

Nerd Sniping ์ด๋ผ๋Š” ์šฉ์–ด๋กœ Randall Munroe์˜ ํฌ๋ ˆ๋”ง



๋‹ต๋ณ€

CJam, 276496.9062958626 ์ 

2,128*_(]128*

๊ฑฐ๋ฆฌ๊ฐ€ 2 ์ธ ์ง๊ต๊ฐ€ ์•„๋‹Œ ์Œ์ด โ€‹โ€‹์—†๊ธฐ ๋•Œ๋ฌธ์— ๊ฑฐ๋ฆฌ๊ฐ€ ํ™€์ˆ˜ ์—ฌ์•ผํ•˜๋ฉฐ ๊ฑฐ๋ฆฌ๋„ ์ œ๊ณฑ์ž…๋‹ˆ๋‹ค. p 2 = x 2 + y 2 ์ด๋ฏ€๋กœ x์™€ y (์ œ๊ณฑ ์—ฌ๋ถ€) ์ค‘ ํ•˜๋‚˜๋Š” ํ™€์ˆ˜ ์—ฌ์•ผํ•˜๊ณ  ๋‹ค๋ฅธ ํ•˜๋‚˜๋Š” ์ง์ˆ˜ ์—ฌ์•ผํ•ฉ๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ์ ์€์ด ์ด๋ฏธ์ง€์—์„œ ํ•ญ์ƒ ๋ฐ˜๋Œ€ ์ƒ‰์ƒ์ž…๋‹ˆ๋‹ค.

์ด๊ฒƒ๊ณผ ๊ทธ๊ฒƒ์˜ ๋ถ€์ •์ ์ธ ๊ฒƒ๋งŒ์ด ์œ ์ผํ•œ ์ตœ์ ์˜ ์†”๋ฃจ์…˜์ž…๋‹ˆ๋‹ค. ์ตœ์ ์˜ ์†”๋ฃจ์…˜์—์„œ ์ง๊ตํ•˜์ง€ ์•Š์€ ๊ธฐ๋ณธ ๊ฑฐ๋ฆฌ ํ”ฝ์…€์˜ ์ƒ‰์ƒ์€ ๋™์ผํ•˜์ง€ ์•Š์•„์•ผํ•ฉ๋‹ˆ๋‹ค. (3,4) ๋ฐ (4,3)๊ณผ ๊ฐ™์ด ๋Œ€๊ฐ์„ ์œผ๋กœ ์ธ์ ‘ํ•œ ๋ฐ˜๋Œ€ ํ”ฝ์…€์ด ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฐ˜๋Œ€ ์ƒ‰์ƒ ๋“ฑ์˜ ํ”ฝ์…€์„ ์ฑ„์›€์œผ๋กœ์จ ๊ฐ™์€ ์ƒ‰์ƒ์˜ ๋Œ€๊ฐ์„ ์„ ์–ป์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋Œ€๊ฐ์„ ์˜ ๊ฐ ํ”ฝ์…€์—์„œ ์‹œ์ž‘ํ•˜์—ฌ ๋ชจ๋“  ๋Œ€๊ฐ ๋Œ€๊ฐ์„ ์„ ๊ฐ™์€ ๋ฐฉ์‹์œผ๋กœ ์ฑ„์šธ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๊ฒƒ๋“ค์€ ๋‘˜๋Ÿฌ ์‹ธ์—ฌ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋ž˜๋„ ๊ทธ๋ž˜๋„ ์ตœ์ ์ž…๋‹ˆ๋‹ค.


๋‹ต๋ณ€

Python 3, 138267.64 ์ 

์ด๊ฒƒ์€ ํ•„์š”ํ•œ ๊ฒƒ์˜ ์˜ˆ์™€ ์ด๊ธธ๋งŒํ•œ ์ตœ์†Œํ•œ์˜ ๋Œ€๋‹ต์ž…๋‹ˆ๋‹ค โ€ฆ

๊ทธ๊ฒƒ์€ ํฌํ•จ

  • ์–ธ์–ด ์ด๋ฆ„.
  • ์งˆ๋ฌธ์˜ ์Šคํƒ ์Šค ๋‹ˆํŽซ ์ ์ˆ˜์ž…๋‹ˆ๋‹ค.
  • ์ด๋ฏธ์ง€๊ฐ€ ์Šคํƒ ์Šค ๋‹ˆํŽซ์—์„œ ์ €์žฅ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
  • ์ด ์ฝ”๋“œ๋Š” 65,536 ๊ฐœ์˜ 0๊ณผ 1์˜ ๋ฌธ์ž์—ด์„ ์ƒ์„ฑํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

์‚ฐ์ถœ

์•”ํ˜ธ

from random import random

output_string = ''
filename = '65536digits.txt'

for t in range(65536):
    digit = int(random() * 2)
    output_string += str(digit)

with open(filename, 'w') as output_file:
    output_file.write(output_string)

์ด๊ฒƒ์€ ๋‹จ์ง€ ์˜ˆ์ผ๋ฟ์ž…๋‹ˆ๋‹ค. ํŒŒ์ด์ฌ์ด ๋ฐ˜๋“œ์‹œ์ด ํŠน์ • ๋„์ „์— ๋Œ€ํ•œ ๊ฒฝ์Ÿ์ ์ธ ๋‹ต๋ณ€์— ๊ฐ€์žฅ ์ ํ•ฉํ•œ ์–ธ์–ด๋Š” ์•„๋‹™๋‹ˆ๋‹ค.


๋‹ต๋ณ€