샤브의 블로그 RSS 태그 관리 글쓰기 방명록
Device & Language (105)
2022-11-05 13:31:27

1. ubuntu를 다운로드 받기(Install Ubuntu on a Raspberry Pi | Ubuntu)

2. SD카드에 다운로드 받아 압축을 해제한 이미지를 write하기

    이미지 Write Tool : Win32 Disk Imager download | SourceForge.net

3. SD카드를 라즈베리파이3에 넣고 라즈베리파이3 기동

4. ubuntu login: 창에서 당황하지 않고

    id : ubuntu, pw : ubuntu 입력하기

5. 최신 버전으로 update하기

sudo apt update && sudo apt upgrade -y

2017-08-24 13:17:05

Sum square difference

Problem 6 

The sum of the squares of the first ten natural numbers is,


1**2 + 2**2 + ... + 10**2 = 385

The square of the sum of the first ten natural numbers is,


(1 + 2 + ... + 10)**2 = 55**2 = 3025

Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640.


Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.


Answer 25164150


Code

num = 100

temp = 0

diff = 0


temp =  num ** 2

diff = (3 * temp ** 2 + 2 * temp * num - 3 * temp -2 * num )/12


print(diff)

2017-08-16 20:42:36

Smallest multiple

Problem 5 

2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.


What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?


Answer 232792560


Code

def gcd(a, b):

    while b != 0:

        a, b = b, a % b

    return a


def lcm(a, b):

    return a*b/gcd(a, b)


lcmNum = 1

for i in range(2,21):

    lcmNum = lcm(lcmNum,i)

    

print(lcmNum)

2017-08-16 20:20:34

Largest palindrome product

Problem 4 

A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.


Find the largest palindrome made from the product of two 3-digit numbers.


Answer

number = 906609


Code

print(max([x*y for x in range(999,900,-1) for y in range(x,900,-1) if str(x*y) == str(x*y)[::-1]]))

2017-04-06 20:47:16

Largest prime factor
Problem 3
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?

Answer
number = 600851475143

i = 2
m = 2
while number != 1:
    if number % i == 0:
        number = number / i
        m = i
    i = i + 1

print m

2016-05-31 13:32:26

기존의 DNS를 이용한 방식은 추천하는 방식이 아님.

따라서 아래의 코드를 이용하여 ip를 가져올 것을 추천


using System.Net.NetworkInformation;

using System.Net.Sockets;


...


public string GetLocalIPv4(NetworkInterfaceType _type)

{

    string output = "";

    foreach (NetworkInterface item in NetworkInterface.GetAllNetworkInterfaces())

    {

        if (item.NetworkInterfaceType == _type && item.OperationalStatus == OperationalStatus.Up)

        {

            foreach (UnicastIPAddressInformation ip in item.GetIPProperties().UnicastAddresses)

            {

                if (ip.Address.AddressFamily == AddressFamily.InterNetwork)

                {

                    output = ip.Address.ToString();

                }

            }

        }

    }

    return output;

}


'Device & Language' 카테고리의 다른 글

웹사이트 최적화 방법론  (0) 2013.10.17
Data compression in DB2 9  (0) 2013.08.20
[java]My Math Class  (0) 2010.11.09
2014-12-27 21:21:01

Problem : Even Fibonacci numbers
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

Answer
before =1
now=0
next =0
sum=0
while now < 4000000:
  next = now + before
  before = now
  now = next
  if (now % 2) ==0:
    sum= sum + now
print (sum)

Other
p = 1
n = 2
s = 0
while s < 1000000:
  s += n
  p, n = 2 * n + p, 3 * n + 2 * p
print s


출처 : https://projecteuler.net/problem=2

2014-12-23 21:11:35

Problem : Multiples of 3 and 5
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000.

Answer
s=0
for x in range(0, 100):
if (x % 3)==0 :
s = s+x
elif (x %5)==0:
s = s+x
print (s)

Other
sum([x for x in range(1000) if x % 3== 0 or x % 5== 0])

출처 : https://projecteuler.net/problem=1

2013-10-30 16:25:35

drawnow


1줄이면 화면이 refresh 됨.


참고 : http://www.mathworks.co.kr/kr/help/matlab/ref/drawnow.html

2013-10-29 13:38:00
[fileName, pathName, filterIndex] = uigetfile({'*.*';'*.xls';'*.txt';'*.csv'}, 'Select file(s)', 'MultiSelect', 'on');
if iscell(fileName)
    nbfiles = length(fileName);
elseif fileName != 0
    nbfiles = 1;
else
    nbfiles = 0;
end


출처 : http://stackoverflow.com/questions/13285449/matlab-uigetfile-with-one-or-multiple-files

'Device & Language > MATLAB' 카테고리의 다른 글

화면 refresh하기  (0) 2013.10.30
Matlab 메모리 관리  (0) 2013.10.15