Sinisterly
[Challenge:1] Multiples of 3 and 5 - Printable Version

+- Sinisterly (https://sinister.li)
+-- Forum: Coding (https://sinister.li/Forum-Coding)
+--- Forum: Coding (https://sinister.li/Forum-Coding--71)
+--- Thread: [Challenge:1] Multiples of 3 and 5 (/Thread-Challenge-1-Multiples-of-3-and-5)

Pages: 1 2


RE: Multiples of 3 and 5 - Pikami - 11-27-2016

(11-27-2016, 12:46 AM)bitm0de Wrote: @Pikami - You could have just used std::map<int, int> and it would have already been sorted on insertions.
Thanks for the tip, I know that using vectors for this is a shity solution Biggrin


RE: Multiples of 3 and 5 - Vi-Sion - 11-27-2016

Well done @bitm0de +100 for you.
You should now go for the second challenge https://sinister.li/Thread-Fibonacci-Divisibility .


RE: Multiples of 3 and 5 - lux - 11-30-2016

Go.

Code:
package main func main() { var total int for i := 0; i < 1000; i++ { if i%3 == 0 || i%5 == 0 { total += i } } println(total) }



RE: Multiples of 3 and 5 - Vi-Sion - 11-30-2016

@lux wow first time i hear of this language anyway you've done only the first part +50
For extra 50 points do a function to reverse that sum and a function to sort it in ascending order. (this is the part you forgot to do)


RE: [Challenge:1] Multiples of 3 and 5 - Bish0pQ - 12-08-2016

C#

Spoiler:
Code:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Multiples {    class Program    {        static void Main(string[] args)        {            //Variables            int intSum = 0;            string strSum = string.Empty;            //Calculate sum            for (int i = 0; i < 1000; i++)            {                if (i % 3 == 0 || i % 5 == 0)                {                    intSum += i;                    strSum = intSum.ToString();                                    }            }            Console.WriteLine("The sum is {0}", strSum); //Write sum result            //Reverse the number (another loop, boring I know)            string strSumReversed = string.Empty;            int intCount = strSum.Length;            for (int x = 0; x < strSum.Length; x++)            {                strSumReversed = strSumReversed + strSum.Substring(intCount -1, 1);                intCount = intCount - 1;            }            Console.WriteLine("The sum reversed is: {0}", strSumReversed); //Write reversed result            Console.ReadLine();                      }        }    }



RE: [Challenge:1] Multiples of 3 and 5 - Vi-Sion - 12-08-2016

Good job @Bish0pQ but as mentioned here https://sinister.li/Thread-Competition-Rules-and-scoreboard this competition won't continue.


RE: [Challenge:1] Multiples of 3 and 5 - bitm0de - 12-08-2016

(12-08-2016, 09:36 AM)Bish0pQ Wrote: C#

Spoiler:
Code:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Multiples {    class Program    {        static void Main(string[] args)        {            //Variables            int intSum = 0;            string strSum = string.Empty;            //Calculate sum            for (int i = 0; i < 1000; i++)            {                if (i % 3 == 0 || i % 5 == 0)                {                    intSum += i;                    strSum = intSum.ToString();                                    }            }            Console.WriteLine("The sum is {0}", strSum); //Write sum result            //Reverse the number (another loop, boring I know)            string strSumReversed = string.Empty;            int intCount = strSum.Length;            for (int x = 0; x < strSum.Length; x++)            {                strSumReversed = strSumReversed + strSum.Substring(intCount -1, 1);                intCount = intCount - 1;            }            Console.WriteLine("The sum reversed is: {0}", strSumReversed); //Write reversed result            Console.ReadLine();                      }        }    }

String's are immutable in .NET, but why didn't you use the for loop variable here?
Code:
for (int x = 0; x < strSum.Length; x++) { strSumReversed = strSumReversed + strSum.Substring(intCount -1, 1); intCount = intCount - 1; }

Instead of keeping track of your own variable?