Skip to content

Instantly share code, notes, and snippets.

View rodrigopuls's full-sized avatar
🎯
Focusing

Rodrigo Puls rodrigopuls

🎯
Focusing
View GitHub Profile
const isPrime = (n) => {
if(n < 2) return false;
for(let i = 2; i <= Math.sqrt(n); i += 1) {
if(n % i === 0) {
return false;
}
}
return true;
public static List<int> rotLeft(List<int> a, int d)
{
for (var i = 0; i < d; i++)
{
var temp = a[0];
a.RemoveAt(0);
a.Add(temp);
}
return a;
}
public static int hourglassSum(List<List<int>> arr)
{
var max = -63; // 7 * -9 lower value possible
for (var i = 0; i < 4; i++) { // 4 row possibilities
for (var j = 0; j < 4; j++) // 4 column possibilities
{
var sum = 0;
sum = (arr[i][j] + arr[i][j + 1] + arr[i][j + 2] + arr[i + 1][j + 1] + arr[i + 2][j] +
arr[i + 2][j + 1] + arr[i + 2][j + 2]);
max = max < sum ? sum : max;
public static long repeatedString(string s, long n)
{
if (string.IsNullOrEmpty(s) || n <= 0) return 0;
var c = 'a';
long count = 0;
var repetitions = n / s.Length + 1;
var remainingSize = n % s.Length;
var i = 0;
@rodrigopuls
rodrigopuls / hackerrank_csharp_jumping_clouds.cs
Last active July 19, 2022 01:37
Hackerranck Jumping Cloud C#
public static int jumpingOnClouds(List<int> c)
{
var cloudPos = 0;
var jumpCount = 0;
var listSize = c.Count - 1;
while(true) {
if(cloudPos + 2 <= listSize && c[cloudPos + 2] == 0)
{
cloudPos = cloudPos + 2;
@rodrigopuls
rodrigopuls / hackerrank_csharp_counting_valleys.cs
Last active January 21, 2022 03:22
HackerRank - C# - Counting Valleys
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
@rodrigopuls
rodrigopuls / hackerrank_csharp_sock_merchant.cs
Last active January 21, 2022 03:12
HackerRank - Sales by match
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;