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는 친화쌍이 됩니다. |
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
process :: (Integral a) => String -> a | |
process = foldr1 (*) . map (read . (:"")) | |
main = print $ process "2462547592605757" |
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
module Euler ( | |
isPrime, | |
isPalindrome, | |
isPalindromeString, | |
reversedNumber, | |
numberOfDivisors, | |
numberOfDivisors', | |
sumOfDivisors, | |
sumOfProperDivisors, | |
factorize, |
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
{-아래와 같은 20×20 격자가 있습니다. | |
08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08 | |
49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00 | |
81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65 | |
52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91 | |
22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80 | |
24 47 32 60 99 03 45 02 44 75 33 53 78 36 84 20 35 17 12 50 | |
32 98 81 28 64 23 67 10 26 38 40 67 59 54 70 66 18 38 64 70 | |
67 26 20 68 02 62 12 20 95 63 94 39 63 08 40 91 66 49 94 21 |
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 | |
2파운드를 만드는 서로 다른 방법은 모두 몇가지나 있습니까?*/ | |
import Foundation |
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
// | |
// BigInt.swift | |
// EulerKit | |
// | |
// Created by soooprmx on 2015. 6. 2.. | |
// Copyright (c) 2015년 sooop. All rights reserved. | |
// | |
import Foundation |
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
import Foundation | |
func parseExpression(tokens:[String]) -> [String] { | |
let operators:[String:Int] = [ | |
"*": 10, | |
"/": 10, | |
"+": 9, | |
"-": 9, | |
"(": 0, | |
")": 0 |
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
let k = ["a", "b", "c", "d"] | |
let v = [1, 2, 3, 4] | |
let p = zip(k, v) | |
//: build fast dictionary from zipped object | |
func fastDictionary<K:Hashable, V>(data:Zip2<[K], [V]>) -> Dictionary<K, V> { | |
var result:[K:V] = [:] | |
for i in data { | |
result[i.0] = i.1 | |
} |
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
# coding: utf-8 | |
# 어떤 공장에서 생산하는 제품의 단위 및 출고가가 다음과 같다. | |
# | |
# * 1kg - 2 | |
# * 4kg - 3 | |
# * 10kg - 7 | |
# | |
# nkg을 출고하는데 드는 최소 비용과 이때의 생산량을 구해보자. |
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
func encode<T>(var value:T) -> NSData { | |
let data = withUnsafePointer(&value){ | |
(ptr:UnsafePointer<T>) -> NSData in | |
return NSData(bytes:ptr, length:sizeof(T.Type)) | |
} | |
return data | |
} | |
func decode<T>(data:NSData) -> T { | |
var ptr = UnsafeMutablePointer<T>.alloc(sizeof(T.Type)) |