Skip to main content

Posts

Showing posts with the label online judge

Primality - Easy

This is an experimental post. I'm trying out Scarky.com . Seems promising, but we can't an create account and manage challenges. Apparently, I have to save this secret URL if I want to edit a challenge. Very inconvenient! :( I've created a simple programming challenge for my readers. If it's a hit, expect more.

The 3n + 1 Problem - Easy

Find the problem statement here . The 3n + 1 problem is also known as The Collatz Conjecture  in Mathematics. The problem is simple, you are given a positive integer 'n'. We perform the following operations. If n = 1, Stop If n is even, n = n / 2 If n is odd, n = 3 * n + 1 The problem statement asks to count the number of iterations we need to perform till we get to 1. (Note : 0 is a corner case.) It's a Conjecture because it's still hasn't been proved that every number will end up at 1.  I've decided to approach UVaOJ with C++ so that I can brush up my C++ skills. Here's my solution . I've used recursion combined with memoization. Memoization is a type of dynamic programming. It's kind of a cache memory which stores solutions to already solved subproblems so that you don't need to solve them again. Comments are welcome! Cheers.