|
I have the same thing happening with an extended warranty on my wife's car. They keep calling me telling me this is my last chance to purchase this extended warranty. Sometimes I play along, other times I tell them I'm hanging up before I get irate.
Yes, I've told them to take my number off the list and that I have added my number to the do not call list. Doesn't seem to phase them.
|
|
|
|
|
Yeah, I think they all took lessons from Scientology it would seem.
Jeremy Falcon
|
|
|
|
|
I just had an idea for the next time they call, I'm going to start wailing and moaning. I'll get control of myself and tell them that I no longer own the car because it was totaled in the wreck that killed my wife. That would be a big lie both are doing very well.
|
|
|
|
|
They seem to contact me once a year. I make a (small) donation.
Maybe if I didn't donate, they would nag me as well. Then, I would set a message filter in my mail agent and be done with it.
Then again, that would remove a rant or so.
Slow day in the lounge
Arguing with a woman is like reading the Software License Agreement. In the end, you ignore everything and click "I agree".
Anonymous
|
|
|
|
|
You caught me.
Jeremy Falcon
|
|
|
|
|
I did the same some years ago. I now see a request for more about once per year, which (given that Wikipedia is free) I do not consider excessive.
|
|
|
|
|
Luckily, that's not my experience with them.
|
|
|
|
|
Never mind Wikipedia, this is how actual charities get on sh*tlists.
|
|
|
|
|
It's also known as the Conway Sequence, Look and Say Sequence, and probably some others. It's rather simple. Start with a 1 and then describe what you see for the next iteration. So, starting at 1, the next number is one 1 (11), the next is two 1 (21), then one 2 one 1 (1211), and so on:
1
11
21
1211
111221
312211
The question to answer is what's the length in digits of the 100th number in the chain, starting with "1" as the first? The first six numbers have been given above. You could write it out by hand, but I wouldn't recommend it, and as developers, that's not what we do.
The seemingly simple challenge is to write the code to come up with the answer. The only hint you get is the 50th number is 894,810 digits long.
Oh, and don't bother Googling for code. Those examples will only get you so far and definitely won't get you to the answer.
System.ItDidntWorkException: Something didn't work as expected.
C# - How to debug code[ ^].
Seriously, go read these articles.
Dave Kreskowiak
|
|
|
|
|
|
System.ItDidntWorkException: Something didn't work as expected.
C# - How to debug code[ ^].
Seriously, go read these articles.
Dave Kreskowiak
|
|
|
|
|
Now why do I want to hit you with a stick?
|
|
|
|
|
Because you're curious and have no idea why you're driven to solve the problem?
System.ItDidntWorkException: Something didn't work as expected.
C# - How to debug code[ ^].
Seriously, go read these articles.
Dave Kreskowiak
|
|
|
|
|
I think I got a working code:
string LookAndSay(int S, int n)
{
string result = S.ToString();
for (int i = 0; i < (n - 1); i++)
{
StringBuilder NewString = new StringBuilder();
for (int j = 0; j < result.Length; j++)
{
string part = RepetingItems(j, result);
j += (int)char.GetNumericValue(part[0]) - 1;
NewString.Append(part);
}
result = NewString.ToString();
}
return result;
}
string RepetingItems(int index, string array)
{
int count = 1;
for (int i = index + 1; i < array.Length; i++)
{
if (array[index] == array[i])
{ count++; }
else { break; }
}
return (count.ToString() + array[index].ToString());
}
Got your result for the length of 50 iterations, and 100, well... I get an out of memory exception . But I do see that the last digits do not change, so I bet I can shave off quite a bit of numbers that I do not need to read. This is way more interesting than reading for the exam, so I should hate you now
|
|
|
|
|
|
Oh yes
|
|
|
|
|
I ended up doing a brute force method and was surprised at what I ran into along the way and what the final answer was. That's all I'm going to say.
System.ItDidntWorkException: Something didn't work as expected.
C# - How to debug code[ ^].
Seriously, go read these articles.
Dave Kreskowiak
modified 30-Nov-17 19:52pm.
|
|
|
|
|
Then I'll have to use the harddisk and do IO handling... The pain...
|
|
|
|
|
How much memory do you have? (I want to see if it's worth the try on my PC)
modified 19-Nov-18 21:01pm.
|
|
|
|
|
The numbers were floating out on my desk onto my paper and now it's a real mess here
|
|
|
|
|
Not so easy, is it?
System.ItDidntWorkException: Something didn't work as expected.
C# - How to debug code[ ^].
Seriously, go read these articles.
Dave Kreskowiak
|
|
|
|
|
Yes, these strings get huge, don't they? The whole thing really slows down in a very visible way once the lengths start to reach the 100,000s (40th iteration on) and gets ultra slow from there on in.
I'll leave mine running for a while and see exactly where it crashes and burns. Max chars for a StringBuilder are 2,147,483,647, I believe and it's clearly going to hit that at some point so I guess the true answer as you suggest involves hiving off the repeating elements.
My code (spectacularly Q&D C# - written on a whim in "do ... while" loops because someone recently said "for" loops are for dinosaurs) looks like this:
static void Main(string[] args)
{
string result = ("1");
<pre>
int i = 1;
do
{
Console.WriteLine(i.ToString() + "\t" + result.Length.ToString());
result = GetNextResult(result);
i += 1;
}
while (i < 101);
Console.ReadLine();
}
static string GetNextResult(string origin)
{
char character;
int occurences;
StringBuilder result = new StringBuilder();
do
{
if (origin.Length == 0)
break;
ProcessNextGroup(origin, out character, out occurences);
origin = origin.Substring(occurences);
result.Append(occurences.ToString());
result.Append(character.ToString());
GC.Collect();
}
while (true);
return result.ToString();
}
static void ProcessNextGroup(string sequence, out char character, out int occurences)
{
int index = 0;
character = sequence[0];
occurences = 1;
do
{
if (++index > (sequence.Length -1))
break;
if (sequence[index] == character)
occurences += 1;
else
break;
}
while (true);
}
}</pre>
98.4% of statistics are made up on the spot.
|
|
|
|
|
PeejayAdams wrote: written on a whim in "do ... while" loops because someone recently said "for" loops are for dinosaurs
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
No, the problem isnt that the strings are limited. You can load into memory the items you want, and perform the LookNSay from the partial string. When that is read to its end you simply load the next part into memory. Its just a little more complicated that's all:
string LookAndSayFile(int S, int n)
{
int SplitStringSize = 2;
string projectPath = System.IO.Path.GetFullPath(@"..\..\..\..\");
File.Delete(projectPath + "output.txt");
File.Delete(projectPath + "input.txt");
System.IO.File.WriteAllLines(projectPath + "output.txt", new string[] { string.Empty });
System.IO.File.WriteAllLines(projectPath + "input.txt", new string[] { S.ToString() });
for (int i = 0; i < (n - 1); i++)
{
char currentItem = '#';
int count = 1;
StringBuilder NewString = new StringBuilder();
using (StreamReader sr = new StreamReader(projectPath + "input.txt"))
{
while (sr.Peek() >= 0)
{
string res = sr.ReadLine();
foreach (char j in res)
{
if (currentItem == '#')
{
currentItem = j;
continue;
}
if (currentItem == j)
{
count++;
}
else
{
NewString.Append(count.ToString() + currentItem.ToString());
if (NewString.Length > SplitStringSize)
{
System.IO.File.AppendAllLines(projectPath + "output.txt", new string[] { NewString.ToString() });
NewString.Length = 0;
}
currentItem = j;
count = 1;
continue;
}
}
}
}
NewString.Append(count.ToString() + currentItem.ToString());
System.IO.File.AppendAllLines(projectPath + "output.txt", new string[] { NewString.ToString() });
File.Delete(projectPath + "input.txt");
System.IO.File.Copy(projectPath + "output.txt", projectPath + "input.txt");
System.IO.File.WriteAllText(projectPath + "output.txt", string.Empty);
}
return String.Join(Environment.NewLine, System.IO.File.ReadAllLines(projectPath + "input.txt"));
}
I 'think' it's working, although the string.join does not wanna play with me. Keeps returning a vector of strings.
|
|
|
|
|
Oh, the integer sequence are difined for a bit larger range than Dave gave here:
A006751 - OEIS[^]
|
|
|
|