This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension NSCoder { | |
// Encode String | |
func encodeString(string:String, forKey key:String) { | |
self.encodeObject(string as NSString, forKey:key) | |
} | |
func decodeStringForKey(key:String) -> String { | |
let ns = self.decodeObjectForKey(key) as! NSString | |
return ns as String | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- | |
n의 약수들 중에서 자신을 제외한 것의 합을 d(n)으로 정의했을 때, | |
서로 다른 두 정수 a, b에 대하여 d(a) = b 이고 d(b) = a 이면 | |
a, b는 친화쌍이라 하고 a와 b를 각각 친화수(우애수)라고 합니다. | |
예를 들어 220의 약수는 자신을 제외하면 1, 2, 4, 5, 10, 11, 20, 22, 44, 55, 110 이므로 그 합은 d(220) = 284 입니다. | |
또 284의 약수는 자신을 제외하면 1, 2, 4, 71, 142 이므로 d(284) = 220 입니다. | |
따라서 220과 284는 친화쌍이 됩니다. | |
10000 이하의 친화수들을 모두 찾아서 그 합을 구하세요. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- | |
영국의 화폐 단위는 파운드(£)와 펜스(p)이고, 동전의 종류는 아래와 같습니다. | |
1p, 2p, 5p, 10p, 20p, 50p, £1 (100p), £2 (200p) | |
이 동전들을 가지고 2파운드를 만드는 방법은 다양할 것입니다. 예를 하나 들면 이렇습니다. | |
1×£1 + 1×50p + 2×20p + 1×5p + 1×2p + 3×1p |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- | |
1부터 n까지의 숫자를 하나씩만 써서 만든 n자리 숫자를 팬디지털(pandigital)이라고 부릅니다. | |
2143은 4자리 팬디지털인데, 이 수는 동시에 소수이기도 합니다. | |
n자리 팬디지털 소수 중에서 가장 큰 수는 무엇입니까? | |
:::: | |
8, 9 자리 팬디지털 수 중에서는 소수가 없으므로 7자리부터 시작해서 찾아본다. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""10보다 작은 자연수 중에서 3 또는 5의 배수는 3, 5, 6, 9 이고, 이것을 모두 더하면 23입니다. | |
1000보다 작은 자연수 중에서 3 또는 5의 배수를 모두 더하면 얼마일까요?""" | |
def e001(): | |
print(sum((x for x in range(1, 1000) if x % 3 == 0 or x % 5 ==0))) | |
%time e001() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""n의 약수들 중에서 자신을 제외한 것의 합을 d(n)으로 정의했을 때, | |
서로 다른 두 정수 a, b에 대하여 d(a) = b 이고 d(b) = a 이면 | |
a, b는 친화쌍이라 하고 a와 b를 각각 친화수(우애수)라고 합니다. | |
예를 들어 220의 약수는 자신을 제외하면 1, 2, 4, 5, 10, 11, 20, 22, 44, 55, 110 이므로 그 합은 d(220) = 284 입니다. | |
또 284의 약수는 자신을 제외하면 1, 2, 4, 71, 142 이므로 d(284) = 220 입니다. | |
따라서 220과 284는 친화쌍이 됩니다. | |
10000 이하의 친화수들을 모두 찾아서 그 합을 구하세요.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
영국의 화폐 단위는 파운드(£)와 펜스(p)이고, 동전의 종류는 아래와 같습니다. | |
1p, 2p, 5p, 10p, 20p, 50p, £1 (100p), £2 (200p) | |
이 동전들을 가지고 2파운드를 만드는 방법은 다양할 것입니다. 예를 하나 들면 이렇습니다. | |
1×£1 + 1×50p + 2×20p + 1×5p + 1×2p + 3×1p |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""1부터 n까지의 숫자를 하나씩만 써서 만든 n자리 숫자를 팬디지털(pandigital)이라고 부릅니다. | |
2143은 4자리 팬디지털인데, 이 수는 동시에 소수이기도 합니다. | |
n자리 팬디지털 소수 중에서 가장 큰 수는 무엇입니까?""" | |
""" | |
9자리 펜디지털 수의 각 자리숫자 합은 45로 소수가 될 수 없다. | |
같은 원리로 8자리는 불가능. | |
따라서 답은 7자리 중에 나오게 되어 있으므로 | |
7654321의 순열로부터 소수인지 검사한다. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/swift | |
/* | |
오일러 프로젝트 51번 | |
두 자리 숫자 *3의 첫번째 자리를 여러가지로 바꿨을 때 가능한 아홉 가지의 결과 중에서 13, 23, 43, 53, 73, 83의 여섯 개는 소수입니다. | |
56**3 의 3번째와 4번째 자리를 동일한 숫자로 바꿔서 만들어지는 10개의 다섯자리 숫자 중에서는 아래에서 보듯이 7개가 소수가 되며, 이것은 이런 식으로 7개의 소수가 만들어지는 첫번째 경우입니다. 이 소수 집단의 첫번째 수인 56003은 이런 성질을 갖는 가장 작은 소수입니다. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""두 자리 숫자 *3의 첫번째 자리를 여러가지로 바꿨을 때 가능한 아홉 가지의 결과 중에서 13, 23, 43, 53, 73, 83의 여섯 개는 소수입니다. | |
56**3 의 3번째와 4번째 자리를 동일한 숫자로 바꿔서 만들어지는 10개의 다섯자리 숫자 중에서는 아래에서 보듯이 7개가 소수가 되며, 이것은 이런 식으로 7개의 소수가 만들어지는 첫번째 경우입니다. 이 소수 집단의 첫번째 수인 56003은 이런 성질을 갖는 가장 작은 소수입니다. | |
56003, 56113, 56333, 56443, 56663, 56773, 56993 | |
위의 예처럼 원래의 일부를 동일한 숫자로 치환했을 때 8개의 소수 집단이 만들어지는 경우를 찾고, 그 집단에 속한 가장 작은 소수를 구하세요. | |
치환하는 자리는 인접하지 않아도 되고, 가장 앞부분을 치환하는 경우 거기에 0은 올 수 없습니다.""" | |