Posts

Showing posts from January, 2024

Underrated step for logic building in programming.

Image
Logic building is a crucial and complex skill in programming. In essence, it is ability to come-up with solution of coding problem and write precise instructions ( or code) that a computer can execute autonomously. This skill requires aligning your thought process with computer and its capabilities. And running through code some-what abstractly to know and predict the behavior of code before it is executed. To be able to do this, one essential step that many beginner programmers overlook is performing dry runs. Understanding Dry Runs The concept of a dry run in programming is straightforward: can you mentally execute your code and predict its output without actually running it on a computer? While this seems simple, it is a challenging task. Typically, we are taught to write code, run it, and observe the output. This cycle is essential because code needs to run to be validated. However, if you rely solely on running your code to understand its behavior, you may struggle with building...

Python code #14

 1. Insertion sort: def InsertionSort (TheData): for Count in range ( 0 , len (TheData)): DataToInsert = TheData[Count] Inserted = 0 NextValue = Count - 1 while (NextValue >= 0 and Inserted != 1 ): if (DataToInsert < TheData[NextValue]): TheData[NextValue + 1 ] = TheData[NextValue] NextValue = NextValue - 1 TheData[NextValue + 1 ] = DataToInsert else : Inserted = 1 return TheData print (InsertionSort([ 3 , 2 , 1 , 7 , 5 , 9 , 0 ]))

Python code #13

1. 2D array bubble sort of array with 3 columns def bubble_sort_2d (arr): rows = len (arr) for i in range (rows): for j in range (rows - i - 1 ): if arr[j][ 0 ] > arr[j + 1 ][ 0 ]: temp1 = arr[j][ 0 ] arr[j][ 0 ] = arr[j + 1 ][ 0 ] arr[j + 1 ][ 0 ] = temp1 temp2 = arr[j][ 1 ] arr[j][ 1 ] = arr[j + 1 ][ 1 ] arr[j + 1 ][ 1 ] = temp2 temp3 = arr[j][ 2 ] arr[j][ 2 ] = arr[j + 1 ][ 2 ] arr[j + 1 ][ 2 ] = temp3 return arr two_d_array = [ [ 4 , 2 , 3 ], [ 1 , 5 , 6 ], [ 7 , 8 , 9 ], [ 10 , 11 , 12 ], [ 13 , 14 , 15 ], [ 16 , 17 , 18 ], [ 19 , 20 , 21 ], [ 8 , 23 , 24 ], [ 28 , 26 , 27 ], [ 21 , 29 , 30 ] ] sorted_array = bubble_sort_2d(two_d_array) for row in sorted_array: print (row) ------------------------------------------------------------------------------------------...

Popular posts from this blog

Building JavaScript Array Methods from Scratch in 2024 - Easy tutorial for beginners # 1

A better way to learn programming.

Thinking in React: A Guide to Building User Interfaces