Skip to main content

Posts

Showing posts with the label coding

Fill 2D Space with Hilbert Curve

Fill 2D Space with Hilbert Curve

I was introduced to the amazing world of fractals by a coding channel named The Coding Train . I was fascinated by the elegance of the process. It was an amazing mix of math, computer science, coding, and nature, all of which I admire a lot! This project is about such a fractal pattern named Hilbert Curve . I got to know about Hilbert Curve from my university's computer graphics course. As soon as I got introduced to the topic I searched the web for coding it. I coded Hilbert curve with OpenGL in C++ , but it felt clumsy to set it all up. Then I remember The Coding Train and his work on p5js and processing . These libraries were primarily developed for easy use for creative coding. I played around with the libraries but never dedicated to do something serious with it; until now! About the Project Hilbert Curve is a space-filling curve. That means this 1-D line can fill a 2-D space! This fact on its own is amazing! The time I ...

Light OJ 1278 - Sum of Consecutive Integers

Description Given a positive integer \(n\), you have to find the number of ways you can express \(n\) as sum of consecutive integers. You have to use at least two integers. For example, \(n = 15\) has three solutions, \( (1+2+3+4+5), (4+5+6), (7+8)\). একটা ধনাত্মক সংখ্যা \(n\) দেয়া আছে, তোমাকে বের করতে হবে \(n\) কে কত উপায়ে একাধিক ক্রমিক সংখ্যার যোগফল আকারে লেখা যায়। যেমন, \(n = 15\) কে তিন উপায়ে লেখা যায়, \( (1+2+3+4+5), (4+5+6), (7+8)\). Problem Link আমার সমাধান ধরে নেই \(a,b\in \mathbb{N},a \neq b\) \[ \begin{eqnarray*} &&a + (a+1) + (a+2) + \cdots + b = n\\ &\Rightarrow& \sum_{k = a}^{b} k = n\\ &\Rightarrow& \sum_{k = 1}^{b} k - \sum_{k = 1}^{a-1} k = n\\ &\Rightarrow& \frac{b(b+1)}{2} - \frac{(a-1)(a-1+1)}{2} = n\\ &\Rightarrow& b^2 + b - (a^2-a) = 2n\\ &\Rightarrow& b...