Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace WeirdCase
- {
- class Program
- {
- static void Main(string[] args)
- {
- test_and_time("The quick brown fox jumped over the lazy dog");
- test_and_time("What the fuck did you just fucking say about me, you little bitch? I'll have you know I graduated top of my class in the Navy Seals, and I've been involved in numerous secret raids on Al-Quaeda, and I have over 300 confirmed kills. I am trained in gorilla warfare and I'm the top sniper in the entire US armed forces. You are nothing to me but just another target. I will wipe you the fuck out with precision the likes of which has never been seen before on this Earth, mark my fucking words. You think you can get away with saying that shit to me over the Internet? Think again, fucker. As we speak I am contacting my secret network of spies across the USA and your IP is being traced right now so you better prepare for the storm, maggot. The storm that wipes out the pathetic little thing you call your life. You're fucking dead, kid. I can be anywhere, anytime, and I can kill you in over seven hundred ways, and that's just with my bare hands. Not only am I extensively trained in unarmed combat, but I have access to the entire arsenal of the United States Marine Corps and I will use it to its full extent to wipe your miserable ass off the face of the continent, you little shit. If only you could have known what unholy retribution your little 'clever' comment was about to bring down upon you, maybe you would have held your fucking tongue. But you couldn't, you didn't, and now you're paying the price, you goddamn idiot. I will shit fury all over you and you will drown in it. You're fucking dead, kiddo.");
- }
- static void test_and_time(String x)
- {
- DateTime time_start = DateTime.Now;
- Console.WriteLine(to_weird_case(x));
- DateTime time_stop = DateTime.Now;
- TimeSpan duration = time_stop - time_start;
- Console.WriteLine("(" + (int)duration.TotalMinutes + " minutes, " + duration.Seconds + " seconds, and " + duration.Milliseconds + " milliseconds)");
- Console.ReadLine();
- }
- static String to_weird_case(String x)
- {
- char[] xs = x.ToCharArray();
- for (uint i = 0; i < xs.Length; i++)
- {
- if (is_even(i)) xs[i] = char.ToLower(xs[i]);
- else xs[i] = char.ToUpper(xs[i]);
- }
- return new String(xs);
- }
- static bool is_even(uint n)
- {
- /*
- * Goldbach's conjecture is known to be true well past 2^32, so all we have
- * to do is exhaustively search for two primes (each greater than 2) that
- * add up to n. If we find any, then n is even, otherwise odd. We have to
- * handle the first few cases manually.
- */
- if (n == 0) return true;
- else if (n == 1) return false;
- else if (n == 2) return true;
- else if (n == 3) return false;
- else if (n == 4) return true;
- else
- {
- for (uint i = 3; i < n; i++)
- {
- if (is_prime(i))
- {
- for (uint j = i; j < n; j++)
- {
- if (is_prime(j))
- {
- if (i + j == n) return true;
- }
- }
- }
- }
- return false;
- }
- }
- static bool is_prime(uint n)
- {
- /*
- * We can determine if n is a prime by exhaustively searching for
- * numbers less than n that, when repeatedly subtracted from n,
- * eventually reach 0. If we find one, then n is composite, but
- * if we don't, then n is prime.
- */
- for (uint m = 2; m < n; m++)
- {
- uint k = n;
- while (k >= m) k -= m;
- if (k == 0) return false;
- }
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment