Posts
The Factorial Function
· ☕ 2 min read · ✍️ devoalda
The Factorial Function The factorial function is a mathematical function that takes a non-negative integer n and returns the product of all positive integers less than or equal to n. The factorial function is denoted by n!. This is a reference page for the factorial function, written in C and Python. Background The first 10 factorials are: n n! 0 1 1 1 2 2 3 6 4 24 5 120 6 720 7 5040 8 40320 9 362880 10 3628800 Where $n!

HackerRank - Project Euler #1: Multiples of 3 and 5
· ☕ 2 min read · ✍️ devoalda
Introduction 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 N. Input and Output Format 1 2 3 4 5 6 7 # Input: 2 10 100 # Output: 23 2318 {: file="Input and Output” }

HackerRank - Handshake
· ☕ 1 min read · ✍️ devoalda
Introduction At the annual meeting of Board of Directors of Acme Inc. If everyone attending shakes hands exactly one time with every other attendee, how many handshakes are there? Input and Output Format 1 2 3 4 5 6 7 # Input: 2 1 2 # Output: 0 1 {: file="Input and Output” } Process This is a math challenge. So using the primitive way of counting, I counted the number of handshakes for each number of attendees, I came up with this:

Leetcode - Two Sums(1)
· ☕ 2 min read · ✍️ devoalda
Introduction Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order. Input and Output 1 2 3 Input: nums = [2,7,11,15], target = 9 Output: [0,1] Explanation: Because nums[0] + nums[1] == 9, we return [0, 1].

HackerRank - Sherlock and Divisors
· ☕ 2 min read · ✍️ devoalda
Introduction Watson gives an integer N to Sherlock and asks him: What is the number of divisors of N that are divisible by 2? Input and Output Format 1 2 3 4 5 6 7 8 # Input: 2 9 8 # Output: 0 3 {: file="Input and Output” } Explanation 9 has three divisors 1, 3 and 9 none of which is divisible by 2. 8 has four divisors 1,2,4 and 8, out of which three are divisible by 2.

HackerRank - Printing Tokens
· ☕ 2 min read · ✍️ devoalda
Introduction Given a sentence, s, print each word of the sentence in a new line. Input and Output Format 1 2 3 4 5 6 7 # Input: This is C # Output: This is C {: file="Input and Output” } Process This was a pretty simple challenge. Completing the code, I’ve added a for loop to print each character at a time, scanning for any blank spaces and “replacing” that with a newline escape character \n.

Leetcode - Concatenation of array(1929)
· ☕ 2 min read · ✍️ devoalda
Introduction Given an integer array nums of length n, you want to create an array ans of length 2n where ans[i] == nums[i] and ans[i + n] == nums[i] for 0 <= i < n (0-indexed). Specifically, ans is the concatenation of two nums arrays. Return the array ans. Example 1 2 3 4 5 Input: nums = [1,2,1] Output: [1,2,1,1,2,1] Explanation: The array ans is formed as follows: - ans = [nums[0],nums[1],nums[2],nums[0],nums[1],nums[2]] - ans = [1,2,1,1,2,1] Process This was a pretty simple one other that figuring out how to use malloc again.

Leetcode - Ugly Number(263)
· ☕ 2 min read · ✍️ devoalda
Introduction Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. Given an integer n, return true if n is an ugly number. Input and Output Format 1 2 3 Input: n = 6 Output: true Explanation: 6 = 2 × 3 Process This was my thought process while attempting this challenge.

Exercism - Difference of Squares
· ☕ 2 min read · ✍️ devoalda
Introduction Find the difference between the square of the sum and the sum of the squares of the first n natural numbers. The square of the sum of the first ten natural numbers is $(1 + 2 + … + 10)^2 = 55^2 = 3025$. The sum of the squares of the first ten natural numbers is $1^2 + 2^2 + … + 10^2 = 385$. Hence the difference between the square of the sum of the first ten natural numbers and the sum of the squares of the first ten natural numbers is $3025 - 385 = 2640$.

HackerRank - Sum of Digits of a Five Digit Number
· ☕ 2 min read
Introduction Given a five digit integer, print the sum of its digit Input: 5 digit number, n Output: sum of 5 digit number Input and Output Format # Input 10564 # Output 16 {: file="Sum Of Digits of a Five Digit Number.c” } $1+0+5+6+4=16$ This is a watered-down version of the question {: .prompt-info } Process This was my thought process while attempting this challenge. Calculate the number of digits By dividing the number by 10 and incrementing a counter in a while loop The number of digits can be found In a for loop to loop through the total number of digits (5) sum += number % 10 number /= 10 This is to remove the LSB of the number for each iteration of the loop Print out the sum Code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 #include <stdio.

PicoCTF - Obedient Cat
· ☕ 1 min read
Description This file has a flag in plain sight (aka “in-the-clear”). Process The flag was downloaded on a Windows machine (probably not a good idea), using notepad++ to view the file, the flag was found in the file. However, using the cat command on a Linux machine, the flag should also be found. Flag picoCTF{s4n1ty_v3r1f13d_1f6e3b3b} {: file="flag.txt” }

PicoCTF - Wave a flag
· ☕ 1 min read · ✍️ devoalda
Description Can you invoke help flags for a tool or binary? This program has extraordinarily helpful information… Process {: width="972” height="589” } Hex Editor in VSCode The flag is found in the file, but it is not in plain sight. Using a hex editor, the flag can be found. The word binary triggered me to use some sort of hex editor to view the file. I used VSCode to view the file, and found the flag.

PicoCTF - MOD 26
· ☕ 1 min read
Description Cryptography can be easy, do you know what ROT13 is? The flag given: cvpbPGS{arkg_gvzr_V'yy_gel_2_ebhaqf_bs_ebg13_uJdSftmh} Process Using an online tool for ROT13, we can decode the message to get the flag. Doing a ROT13 Decryption of cvpbPGS{arkg_gvzr_V'yy_gel_2_ebhaqf_bs_ebg13_uJdSftmh}, I get the flag: picoctf{next_time_i'll_try_2_rounds_of_rot13_hwqfsgzu} Flag picoctf{next_time_i'll_try_2_rounds_of_rot13_hwqfsgzu} {: file="flag.txt” }