본문 바로가기

분류 전체보기175

[자료구조 프로그래밍 연습문제] maze 미로 경로 찾기 1. maze 교재 Program 3.12의 함수 path를 아래 요건대로 수정한 후 이를 호출하여 경로찾기를 수행하고 경로 를 출력하는 maze 프로그램을 작성하시오. mark[][] 배열을 사용하지 않는다. maze[][] 배열의 상하좌우 가장자리 element들을 사용하지 않는다. 즉, n by m maze의 경우 교재의 프로그램에서는 maze[][] 배열을 maze[n+2][m+2] 로 선언하고 상하좌우 가장자리 element들의 값을1로 설정하여 사용하는데 본 수정에서는 maze[][] 배열을 maze[n][m]로 선언하여 maze를 표현한다. stack에 저장 시 위치좌표만 저장하고 방향정보는 저장하지 않는다. 즉, 교재에서는 (row, col, dir)을 push하는데 (row, col) 만.. 2022. 1. 11.
[자료구조 프로그래밍 연습문제] 희소행렬 전치 1. sparse matrix transpose 교재에서는 그림 2.4(b)의 6×6 matrix를 그림 2.5(a)의 a 배열로 표현하였다. A. 그림 2.5(a)의 a 배열의 값은 정확한가? 정확하다. B. 그림 2.5(b)의 b 배열은 그림 2.4(b)의 6×6 matrix를 transpose 한 결과이다. 그림 2.5(b)의 b 배열의 값은 정확한가? 정확하다. C. 교재 2.5.3절의 마지막 부분에는 2.5(a)의 a 배열에 대해 프로그램 2.9 fastTranspose()의 3번째 for loop 수행 직후 시점의 rowTerms 배열과 startingPos 배열의 값을 보이고 있다. 이들 값은 정확한가? 정확하다. D. 프로그램 2.9 fastTranspose()로 그림 2.5의 a 배열로부.. 2022. 1. 11.
[자료구조 프로그래밍 연습문제] 다항식 계수 배열, 다항식 곱하기, 구조체 1. 다항식 : 계수 배열 representation 교재 2.4.2절에 기술된 다항식 표현 방법 두 가지 중 앞부분에 먼저 기술된 계수 배열 표현의 C 구현으로 다항식 A(x) = a_n*x^n + a_(n-1)*x^(n-1) + ... + a_(1)*x^1 + a_(0)*x^0 을 표현하였다고 하자. 최고차항 a_(n)*x^n의 계수 a_(n)은 0이 아니고 나머지 항들의 계수는 0일 수도 있다고 가정한다. A(x)를 나타내는 변수 a를 교재에서 정의한 구조체 자형 polynomial로 선언하면 C 코드로 polynomial a; 이다. A. 구조체 자료형 polynomial에서 degree의 의미는 무엇인가? 차수, 즉 다항식에서 가장 큰 지수를 뜻한다. B. a.coef[i] = a_(n-i) 라.. 2022. 1. 11.
[자료구조 프로그래밍 연습문제] 재귀함수, 선택정렬, 배열 1. recursion 교재 Figure 1.3의 C 코드에서 수업시간에 언급된 오류를 차고 정확한 코드로 수정하시오. 수정하지 않을 경우 실행 결과에 어떤 오류가 발생하는지 간단한 예를 들어 설명하시오. float rsum(float list[], int n) { if (n) return rsum(list, n-1) + list[n-1]; return 0; } 0 대신 list[0]의 값을 반환하면, list배열의 값들의 전체 합에 첫번째 요소 값이 한 번 더 더하여져서 값이 달라진다. 예를 들어, list == [1, 2, 3, 4, 5] 인 경우, rsum의 결과 값은 1 + 1 + 2 + 3 + 4+ 5, 16으로 첫번째 요소인 1만큼의 오차가 발생한다. 2. recursive implementa.. 2022. 1. 10.
[GLSL] Fractal Brownian Motion https://thebookofshaders.com/13/ The Book of Shaders Gentle step-by-step guide through the abstract and complex universe of Fragment Shaders. thebookofshaders.com float amplitude = 1.; float frequency = 1.; y = sin(x * frequency); float t = 0.01*(-u_time*130.0); y += sin(x*frequency*2.1 + t)*4.5; y += sin(x*frequency*1.72 + t*1.121)*4.0; y += sin(x*frequency*2.221 + t*0.437)*5.0; y += sin(x*freq.. 2022. 1. 6.
[GLSL] Voronoi https://thebookofshaders.com/12/ The Book of Shaders Gentle step-by-step guide through the abstract and complex universe of Fragment Shaders. thebookofshaders.com #ifdef GL_ES precision mediump float; #endif uniform vec2 u_resolution; uniform vec2 u_mouse; void main(){ vec2 coord = gl_FragCoord.xy/u_resolution; coord.x *= u_resolution.x/u_resolution.y; vec2 mouse = u_mouse.xy/u_resolution; mouse.. 2022. 1. 6.
[GLSL] Gradient Noise https://thebookofshaders.com/11/ The Book of Shaders Gentle step-by-step guide through the abstract and complex universe of Fragment Shaders. thebookofshaders.com #ifdef GL_ES precision mediump float; #endif uniform vec2 u_resolution; // vec2 vec2 random vec2 random(vec2 st){ float x = fract(sin(dot(st*25., vec2(17.34,50.13)))*84239.523); float y = fract(cos(dot(st*25., vec2(28.13,39.49)))*94820.. 2022. 1. 6.
[GLSL] Value Noise https://thebookofshaders.com/11/ The Book of Shaders Gentle step-by-step guide through the abstract and complex universe of Fragment Shaders. thebookofshaders.com Vec2-float noise. #ifdef GL_ES precision mediump float; #endif uniform vec2 u_resolution; float random(vec2 st){ float c = fract(sin(dot(st*25., vec2(17.34,50.13)))*84239.523); return c; } float noise(vec2 st){ vec2 i = floor(st); vec2.. 2022. 1. 6.
[GLSL] Float-float Noise https://thebookofshaders.com/11/ The Book of Shaders Gentle step-by-step guide through the abstract and complex universe of Fragment Shaders. thebookofshaders.com The left side is a noise graph, and the right side is a random graph. A noise and a random are different. Let's make a noise function. float i = floor(x); // integer float f = fract(x); // fraction y = rand(i); float i = floor(x); // i.. 2022. 1. 6.