전체 글 (105) 썸네일형 리스트형 [Project Euler] Problem 3: Largest prime factor (incomplete) https://projecteuler.net/problem=3 from typing import List def is_prime(my_target: int, my_primes: List[int]) -> bool: for prime in my_primes: if my_target % prime == 0: return False return True def get_primes(my_target: int) -> List[int]: my_primes: List[int] = [] for number in range(2, my_target + 1): if is_prime(number, my_primes): my_primes.append(number) return my_primes def get_factors(my_.. [Project Euler] Problem 2: Even Fibonacci numbers https://projecteuler.net/problem=2 def f(n): return n if n[-1] + n[-2] >= 4000000 else f(n + [n[-1] + n[-2]]) print(sum([i for i in f([1, 2]) if i % 2 == 0])) # Python 3 fibonacci = [1, 2]a = 1b = 2c = 3 while c < 4000000: fibonacci.append(c) a = b b = c c = a + b total = 0 for i in fibonacci: if i % 2 == 0: total += i print(total) # Python 3 fibonacci = [1, 2]total = 2c = 3 while c < 4000000: f.. [Project Euler] Problem 1: Multiples of 3 and 5 참고 :https://www.nayuki.io/page/project-euler-solutionshttps://projecteuler.net/problem=1 # Python 3 total: int = 0 for i in range(1, 1000): if i % 3 == 0 or i % 5 == 0: total += i print("total =", total) # Python 3 print(sum([i for i in range(1, 1000) if i % 3 == 0 or i % 5 == 0])) // C/C++ #include #include #include #include int _tmain(INT32 argc, LPTSTR argv[]) { INT32 total = 0; for (INT32 i .. [Python] virtualenv or venv import sys # virtualenv if hasattr(sys, 'real_prefix') \ and hasattr(sys, 'base_prefix') \ and hasattr(sys, 'prefix') \ and sys.base_prefix == sys.prefix: print("in virtualenv environment") print("sys.real_prefix", sys.real_prefix) print("sys.base_prefix", sys.base_prefix) print("sys.prefix ", sys.prefix) # venv if not hasattr(sys, 'real_prefix') \ and hasattr(sys, 'base_prefix') \ and hasattr(s.. [C# & C++] unsafe keyword로 pointer 사용하는 방법 unsafe keyword를 사용하면 , C/C++에서 사용하는 pointer를 C#에서도 사용할 수 있다. unsafe keyword를 사용하기 위해서 compile할 때 /unsafe option을 주어야한다. compile할 때 /unsafe option을 주려면 Visual Studio에서 아래와 같이 설정해주면 된다. 참고 : /unsafe (C# Compiler Options) To set /unsafe compiler option in the Visual Studio development environmentOpen the project's Properties page. Click the Build property page. Select the Allow Unsafe Code check bo.. From C# Call C++ [Hybrid] Mixing Sample 사용환경 : Visual Studio 2017, Windows 10 x64 C#과 C++을 Mixing해서 코딩하는 방법을 알아보자. C++ Class를 C#에서 사용하는 예제를 하나 진행해보자. C++ Class를 만든 후, 그 C++ Class를 사용하는 C++/CLI Class를 만든 다음, C#에서 C++/CLI Class를 사용하는 방식으로 진행하려고 한다. 먼저 Visual Studio에서 “Blank Solution”을 하나 만들자. Solution 이름은 “Hybrid1”으로 하자. Hybrid1 Solution에 “Windows Desktop Wizard”로 Visual C++ Project를 하나 추가한다. Project 이름은 “Native1”으로 하자. Application type.. Thread [Java] implements Runnable // [Java] Thread Samplepackage package1; public class Program { public static void main(String[] args) { Thread t1 = new Thread(new A()); Thread t2 = new Thread(new B()); t1.start(); t2.start(); for (int i = 0; i < 10000; i++) { System.out.print("@"); } }} class A implements Runnable { public void run() { for (int i = 0; i < 10000; i++) { System.out.print("."); } }} class B implements Runnable {.. Thread [C#] C# 2.0 Style Thread without ThreadStart // C# 2.0 Style Threadusing System;using System.Threading; namespace ThreadSample{ class Program { static void Main(string[] args) { // C# 2.0 Style Thread does not use ThreadStart Thread t2 = new Thread(Work); t2.Start(); for (int count = 0; count < Repetitions; count++) { Console.Write('@'); } } static void Work() { for (int count = 0; count < Repetitions; count++) { Console.Write('.'); } } co.. 이전 1 2 3 4 5 6 ··· 14 다음