Hi there, I’m Noob OwO)/

This is Noob’s first blog about how she solve programing problems that she has met.

  • Noob writes for fun
  • Don’t bash Noob

Snail

Problem Source: Codewars Given an n x n array, return the array elements arranged from outermost elements to the middle element, traveling clockwise. array = [[1,2,3], [4,5,6], [7,8,9]] snail(array) #=> [1,2,3,6,9,8,7,4,5] For better understanding, please follow the numbers of the next array consecutively: array = [[1,2,3], [8,9,4], [7,6,5]] snail(array) #=> [1,2,3,4,5,6,7,8,9] This image will illustrate things more clearly: NOTE: The idea is not sort the elements from the lowest value to the highest; the idea is to traverse the 2-d array in a clockwise snailshell pattern....

March 5, 2024

ASCII Games: Warning: Ice!

Problem Source: Codewars Any youngster Joeys should probably know what this image means, and why it is traumatic: In many grid-based 2D puzzle games, there is a typical form of puzzle which are usually referred to as ‘ice puzzle’: You have to traverse from point A to point B You can move towards one of the 4 orthogonal directions, 1 tile at a time Some of the floors are slippery; if you walk onto a slippery tile, you’ll keep sliding in the direction you’re going until you land on a non-slippery tile, or you collide with an obstacle/wall For example, the top-left part of the above puzzle has such a solution:...

January 18, 2023

Adding Big Numbers

Problem Source: Codewars We need to sum big numbers and we require your help. Write a function that returns the sum of two numbers. The input numbers are strings and the function must return a string. Example add("123", "321"); -> "444" add("11", "99"); -> "110" Notes The input numbers are big. The input is a string of only digits The numbers are positives Solution In arithmetic, addition can be performed by aligning the addends vertically and add the colums, starting from the unit colum (on the right)....

June 7, 2022

TheLift

Problem Source: Codewars Synopsis A multi-floor building has a Lift in it. People are queued on different floors waiting for the Lift. Some people want to go up. Some people want to go down. The floor they want to go to is represented by a number (i.e. when they enter the Lift this is the button they will press) BEFORE (people waiting in queues) AFTER (people at their destinations) +--+ +--+ /----------------| |----------------\ /----------------| |----------------\ 10| | | 1,4,3,2 | 10| 10 | | | |----------------| |----------------| |----------------| |----------------| 9| | | 1,10,2 | 9| | | | |----------------| |----------------| |----------------| |----------------| 8| | | | 8| | | | |----------------| |----------------| |----------------| |----------------| 7| | | 3,6,4,5,6 | 7| | | | |----------------| |----------------| |----------------| |----------------| 6| | | | 6| 6,6,6 | | | |----------------| |----------------| |----------------| |----------------| 5| | | | 5| 5,5 | | | |----------------| |----------------| |----------------| |----------------| 4| | | 0,0,0 | 4| 4,4,4 | | | |----------------| |----------------| |----------------| |----------------| 3| | | | 3| 3,3 | | | |----------------| |----------------| |----------------| |----------------| 2| | | 4 | 2| 2,2,2 | | | |----------------| |----------------| |----------------| |----------------| 1| | | 6,5,2 | 1| 1,1 | | | |----------------| |----------------| |----------------| |----------------| G| | | | G| 0,0,0 | | | |====================================| |====================================| Rules Lift Rules The Lift only goes up or down!...

June 6, 2022

Hamming Number

Problem Source: Codewars A Hamming number is a positive integer of the form 2i3j5k, for some non-negative integers i, j, and k. Write a function that computes the nth smallest Hamming number. Specifically: The first smallest Hamming number is 1 = 203050 The second smallest Hamming number is 2 = 213050 The third smallest Hamming number is 3 = 203150 The fourth smallest Hamming number is 4 = 223050 The fifth smallest Hamming number is 5 = 203051 The 20 smallest Hamming numbers are given in example test fixture....

May 23, 2022

Number of reduced fractions with denominator d

Problem If n is the numerator and d the denominator of a fraction, that fraction is defined a reduced fraction if and only if GCD(n,d)==1. For example $\displaystyle\frac{5}{16}$ is a reduced fraction, while $\displaystyle\frac{5}{16}$ is not, as both 6 and 16 are divisible by 2, thus the fraction can be reduced to $\displaystyle\frac{3}{8}$. Now, if you consider a given number d, how many reduced fractions can be built using d as a denominator?...

December 8, 2021

Carmichael function

Problem Source: Codewars In number theory, the Carmichael function of a positive integer $n$, denoted $\lambda(n)$, is defined as the smallest positive integer m such that $$a^m \equiv 1 \mod n$$ for every integer $a \leq n$ that is coprime to $n$. The Carmichael function is also known as the reduced totient function (as it is linked to Euler Totient function) or the least universal exponent function. The Carmichael function is important in number theory....

September 4, 2021

Sum of intervals

Problem Source: Codewars Write a function called sumIntervals/sum_intervals() that accepts an array of intervals, and returns the sum of all the interval lengths. Overlapping intervals should only be counted once. Intervals Intervals are represented by a pair of integers in the form of an array. The first value of the interval will always be less than the second value. Interval example: [1, 5] is an interval from 1 to 5. The length of this interval is 4....

July 27, 2021

Roman Numerals Helper

The problem Source: Codewars Create a RomanNumerals class that can convert a roman numeral to and from an integer value. #include <string> #include <vector> class RomanHelper{ public: std::string to_roman(unsigned int n){ } int from_roman(std::string rn){ } } RomanNumerals; It should follow the API demonstrated in the examples below. Multiple roman numeral values will be tested for each helper method. Modern Roman numerals are written by expressing each digit separately starting with the left most digit and skipping any digit with a value of zero....

July 25, 2021

Two Knights

Problem Source: CSES Your task is to count for $k=1,2,…,n$ the number of ways two knights can be placed on a $k \times k$ chessboard so that they do not attack each other. For example: Input: 8 Output: 0 6 28 96 252 550 1056 1848 Solution Idea The most reachable method is for each of the first knight’s position, i’m looking for pertinent positions to place the second knight and sum them all....

May 27, 2021