Results 1 to 8 of 8
Hybrid View
-
27th April 2010 20:13 #1Banned
Join Date: Nov:2007
Location: Sofia
Posts: 1,400
2 .Code:static void Main(string[] args) { Dictionary<int, double> elementValue = new Dictionary<int, double>(); int elementNumber = 0; int value = 0; do { Console.WriteLine("Enter elements of the sequence:"); if (Int32.TryParse(Console.ReadLine(), out value)) { break; } } while (true); for (int i = 1; i < value; i++) { if ((i % 2) == 0) { elementNumber++; if (elementNumber != 1) { //var newValue = elementValue[elementNumber -1] % 2; var newValue = 3 * elementValue[elementNumber - 1] + 1; if (newValue == 1) { Console.WriteLine("We have found that the element at which the An is 1 is " + elementNumber); break; } elementValue.Add(elementNumber, newValue); } else { elementValue.Add(elementNumber, elementNumber); } } } }
, :
0, 1, 2 ... N -
- N e , N+1 = aN div 2
- N e , N+1 = 3*aN + 1Last edited by PhrozenOne; 27th April 2010 at 20:20.
-
27th April 2010 20:57 #2Registered User
Join Date: Dec:2007
Location: Sofia
Posts: 366
?
-
27th April 2010 21:29 #3Banned
Join Date: Nov:2007
Location: Sofia
Posts: 1,400
, ?
-
27th April 2010 22:55 #4Registered User
Join Date: Dec:2007
Location: Sofia
Posts: 366
,

- Collatz, C# . .
- , .
-
28th April 2010 00:19 #5Registered User
Join Date: Feb:2006
Location: Plovdiv
Posts: 392
Code:static IEnumerable<int> Hahaha(int val) { while(val > 1) { yield return val; val = (val % 2 == 0) ? val / 2 : val * 3 + 1; } yield return 1; }
-
28th April 2010 00:29 #6Banned
Join Date: Nov:2007
Location: Sofia
Posts: 1,400
, N, aN 1.
-
28th April 2010 00:35 #7Registered User
Join Date: Feb:2006
Location: Plovdiv
Posts: 392
-
28th April 2010 00:40 #8Banned
Join Date: Nov:2007
Location: Sofia
Posts: 1,400
... ...
. , , ... , .a0, a1, ... aN :
- N e , an+1 = an div 2
- aN e , n+1 = 3*an +1
"n", an = 1
, .Code:static void Main(string[] args) { int value = 0; do { Console.WriteLine("Enter starting element element of the sequence:"); if (Int32.TryParse(Console.ReadLine(), out value)) { if (value > 0) break; } } while (true); int sum = value; int sequence = 0; do { if ((sum % 2) != 0) { sum = (3 * sum) + 1; } else { sum = sum / 2; } sequence++; Console.WriteLine(sum); } while (sum > 1); Console.Write("Reached 1 in n:" + sequence); Console.ReadLine(); }Last edited by PhrozenOne; 28th April 2010 at 01:13.




Reply With Quote

Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in