Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!
what are the comments like, is anyone a member?

Adbot
ADBOT LOVES YOU

tef
May 30, 2004

-> some l-system crap ->

qntm posted:

So I guess the real challenge overcome here was to slightly obfuscate the location of the "if" statement!

this is what some java programmers think OO is actually about

PalmTreeFun
Apr 25, 2010

*toot*

tef posted:

this is what some java programmers think OO is actually about

Obfuscation-Oriented Programming! :pseudo:

TasteMyHouse
Dec 21, 2006

Orzo posted:

reminds me of that old 'object calisthenics' thing

http://binstock.blogspot.com/2008/04/perfecting-oos-small-classes-and-short.html

That Stupid Article posted:

Use only one dot per line. This step prevents you from reaching deeply into other objects to get at fields or methods, and thereby conceptually breaking encapsulation.

I'd like to see his definition of encapsulation for which this statement makes any sense at all.

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!

TasteMyHouse posted:

I'd like to see his definition of encapsulation for which this statement makes any sense at all.
Actually that point is pretty valid, a pattern of calls like thisObject.getSubObject().getOtherSubObject().performAction() is generally pretty bad, and it violates the conventional definition of encapsulation because objects aren't hiding their internals at all.

TasteMyHouse
Dec 21, 2006

Orzo posted:

Actually that point is pretty valid, a pattern of calls like thisObject.getSubObject().getOtherSubObject().performAction() is generally pretty bad, and it violates the conventional definition of encapsulation because objects aren't hiding their internals at all.

I agree with that, but thats a result of having those methods that expose the subobjects in the first place, and isn't inherent in chaining method calls by using multiple dots per line.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

TasteMyHouse posted:

I agree with that, but thats a result of having those methods that expose the subobjects in the first place, and isn't inherent in chaining method calls by using multiple dots per line.

That's why he should have said "don't traverse object graphs" instead of some bs pseudo-wisdom that can't withstand a moment of scrutiny.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Orzo posted:

Actually that point is pretty valid, a pattern of calls like thisObject.getSubObject().getOtherSubObject().performAction() is generally pretty bad, and it violates the conventional definition of encapsulation because objects aren't hiding their internals at all.
SubObject sub = thisObject.getSubObject();
OtherSubObject other = sub.getOtherSubObject();
other.performAction();

or

thisObject.
getSubObject().
getOtherSubObject().
performAction();
:smug:

GROVER CURES HOUSE
Aug 26, 2007

Go on...

PalmTreeFun posted:

Obfuscation-Oriented Programming! :pseudo:

But they're not using C++? :stare:

Sedro
Dec 31, 2008
More like
code:
SubObject sub1 = thisObject.getSubObject();
if (sub1 != null)
{
    OtherSubObject sub2 = sub1.getOtherSubObject();
    if (sub2 != null)
    {
        OtherOtherSubObject sub3 = sub2.getOtherOtherSubObject();
        if (sub3 != null)
        {
            ...
                sub23623456.performAction();
            ...
        }
    }
}
Java 7 has new operators to make this crap faster to write. :rolleyes:

zeekner
Jul 14, 2007

Sedro posted:

Java 7 has new operators to make this crap faster to write. :rolleyes:

code:
ohMyGod?[0]?.pleaseKill(me);

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"
It's me, I'm the horror :smith:

Found this while updating an old library; it's is a Haskell function I wrote for parsing DBus signatures. It's called a lot, so speed is important, but...well, the spec just isn't that complex:
code:
type = atom | container
atom = 'y' | 'b' | 'n' | 'q' | 'i' | 'u' | 'x' | 't' | 'd' | 's' | 'o' | 'g'
container = 'v' | array | dict | struct
array = 'a' type
dict = 'a{' atom '}'
struct = '(' type+ ')'
avert your eyes, ye sensitive:
code:
mkBytesSignature :: ByteString -> Maybe Signature
mkBytesSignature = unsafePerformIO . flip unsafeUseAsCStringLen io where
	io (cstr, len) = case len of
		0 -> return $ Just $ Signature []
		1 -> fmap fast $ peek cstr
		_ | len <= 255 -> slow (castPtr cstr) len
		_ -> return Nothing

	fast c = parseAtom c (\t -> Just (Signature [t])) $ case c of
		0x76 -> Just (Signature [DBusVariant])
		_ -> Nothing

	parseAtom c yes no = case c of
		0x62 -> yes DBusBoolean
		0x79 -> yes DBusByte
		0x6E -> yes DBusInt16
		0x69 -> yes DBusInt32
		0x78 -> yes DBusInt64
		0x71 -> yes DBusWord16
		0x75 -> yes DBusWord32
		0x74 -> yes DBusWord64
		0x64 -> yes DBusDouble
		0x73 -> yes DBusString
		0x67 -> yes DBusSignature
		0x6F -> yes DBusObjectPath
		_ -> no

	slow buf len = loop [] 0 where
		loop acc ii | ii >= len = return . Just . Signature $ reverse acc
		loop acc ii = do
			c <- peekElemOff buf ii
			let next t = loop (t : acc) (ii + 1)
			parseAtom c next $ case c of
				0x76 -> next DBusVariant
				
				-- '('
				0x28 -> do
					mt <- structure buf len (ii + 1)
					case mt of
						Just (ii', t) -> loop (t : acc) ii'
						Nothing -> return Nothing
				
				-- 'a'
				0x61 -> do
					mt <- array buf len (ii + 1)
					case mt of
						Just (ii', t) -> loop (t : acc) ii'
						Nothing -> return Nothing
				
				_ -> return Nothing

	structure buf len = loop [] where
		loop _ ii | ii >= len = return Nothing
		loop acc ii = do
			c <- peekElemOff buf ii
			let next t = loop (t : acc) (ii + 1)
			parseAtom c next $ case c of
				0x76 -> next DBusVariant
				
				-- '('
				0x28 -> do
					mt <- structure buf len (ii + 1)
					case mt of
						Just (ii', t) -> loop (t : acc) ii'
						Nothing -> return Nothing
				
				-- ')'
				0x29 -> return $ Just $ (ii + 1, DBusStructure (reverse acc))
				
				-- 'a'
				0x61 -> do
					mt <- array buf len (ii + 1)
					case mt of
						Just (ii', t) -> loop (t : acc) ii'
						Nothing -> return Nothing
				
				_ -> return Nothing

	array _   len ii | ii >= len = return Nothing
	array buf len ii = do
		c <- peekElemOff buf ii
		let next t = return $ Just (ii + 1, DBusArray t)
		parseAtom c next $ case c of
			0x76 -> next DBusVariant
			
			-- '('
			0x28 -> do
				mt <- structure buf len (ii + 1)
				case mt of
					Just (ii', t) -> return $ Just (ii', DBusArray t)
					Nothing -> return Nothing
			
			-- '{'
			0x7B -> dict buf len (ii + 1)
			
			-- 'a'
			0x61 -> do
				mt <- array buf len (ii + 1)
				case mt of
					Just (ii', t) -> return $ Just (ii', DBusArray t)
					Nothing -> return Nothing
			
			_ -> return Nothing

	dict _   len ii | ii + 1 >= len = return Nothing
	dict buf len ii = do
		c1 <- peekElemOff buf ii
		c2 <- peekElemOff buf (ii + 1)
		
		let mt1 = parseAtom c1 Just Nothing
		
		let next t = return $ Just (ii + 2, t)
		mt2 <- parseAtom c2 next $ case c2 of
			0x76 -> next DBusVariant
			
			-- '('
			0x28 -> structure buf len (ii + 2)
			
			-- 'a'
			0x61 -> array buf len (ii + 2)
			
			_ -> return Nothing
		
		case mt2 of
			Nothing -> return Nothing
			Just (ii', t2) -> if ii' >= len
				then return Nothing
				else do
					c3 <- peekElemOff buf ii'
					return $ do
						if c3 == 0x7D then Just () else Nothing
						t1 <- mt1
						Just (ii' + 1, DBusDictionary t1 t2)

Che Delilas
Nov 23, 2009
FREE TIBET WEED

Geekner posted:

code:
ohMyGod?[0]?.pleaseKill(me);

It's fitting that they all have question marks as part of the operator, because people looking at lines like that are going to be thinking "what the gently caress is this poo poo?"

Sedro
Dec 31, 2008

Geekner posted:

code:
ohMyGod?[0]?.pleaseKill(me);

What if that array is empty? Surely the indexer should return null instead of throwing an exception.

zeekner
Jul 14, 2007

Sedro posted:

What if that array is empty? Surely the indexer should return null instead of throwing an exception.

From what I understand, if the left side of the ? is null, it will return null instead of attempting to read the array. The second question mark does the same for the array value.

code:
if(ohMyGod != null && ohMyGod[0] != null){
  Object whatever = ohMyGod.pleaseKill(me);
}else{
  Object whatever = null;
}
Or for extra horror:
code:
Object whatever = (ohMyGod != null ? (ohMyGod[0] != null ? ohMyGod.pleaseKill(me) : null) : null);
Kill me.

e: Misread that, from that link: "(the array) is non-null and non-empty", it'll return null instead of throwing an error.

zeekner fucked around with this message at 07:01 on May 22, 2011

Sedro
Dec 31, 2008
The operators won't perform bounds checking on your array so there is still the possibility of error.

What we really need is the tried and true onErrorResumeNext()

wellwhoopdedooo
Nov 23, 2007

Pound Trooper!
Am I missing something or are you dudes hating on the coalesce operator?

zeekner
Jul 14, 2007

It might be fine in other languages, but Java always encouraged avoiding null references as a design methodology. That way you don't have to check for null on every single operation. Now I'm gonna see code that'll have more question marks than a :foxnews: headline.

e: My complaints are really about the quality of the average Java programmer, the actual function isn't horrible. The coding horrors that will result will be.

zeekner fucked around with this message at 09:32 on May 22, 2011

Molog
Mar 4, 2004
Title text

Wheany posted:

SubObject sub = thisObject.getSubObject();
OtherSubObject other = sub.getOtherSubObject();
other.performAction();

or

thisObject.
getSubObject().
getOtherSubObject().
performAction();
:smug:

If only there was a third better option.

Scaevolus
Apr 16, 2007

mjau posted:

code:
#include <stdio.h>

int main ()
{
    int i;
    for (i = 1; i <= 100; ++i)
        printf("% 3d\n\0fizz\n\0buzz\n\0fizzbuzz\n"+(!(i%3)+2*!(i%5))*6, i);
    return 0;
}
:v:
We should follow that guy's advice and avoid unnecessary indentations as well.

code:
#include <stdio.h>
#include <stdlib.h>

int main(int n) {
    printf("%d\n\0  Fizz\n\0Buzz\n\0FizzBuzz\n"+(!(n%3)+2*!(n%5))*6, n);
    (main+((int(*)(int))exit-main)*(n/100))((n+1)%101);
}

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Orzo posted:

what are the comments like, is anyone a member?

I am, and let's just say it's mainly a place for designers.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Lumpy posted:

I am, and let's just say it's mainly a place for designers.

There's so much bad PHP and JavaScript there it's hilarious.

mr_jim
Oct 30, 2006

OUT OF THE DARK

Scaevolus posted:

We should follow that guy's advice and avoid unnecessary indentations as well.

code:
#include <stdio.h>
#include <stdlib.h>

int main(int n) {
    printf("%d\n\0  Fizz\n\0Buzz\n\0FizzBuzz\n"+(!(n%3)+2*!(n%5))*6, n);
    (main+((int(*)(int))exit-main)*(n/100))((n+1)%101);
}

That's awesomely terrible.

schnarf
Jun 1, 2002
I WIN.
All hail my terrible C++ template metaprogramming FizzBuzz: http://codepad.org/MCDF6Zt9. There's no runtime branching.
:smug:

I'd really like to concatenate the entire string at compile time, but that seems hard.

schnarf fucked around with this message at 16:48 on May 22, 2011

GROVER CURES HOUSE
Aug 26, 2007

Go on...

schnarf posted:

All hail my terrible C++ template metaprogramming FizzBuzz: http://codepad.org/MCDF6Zt9. There's no runtime branching.
:smug:

I'd really like to concatenate the entire string at compile time, but that seems hard.

Enterprise C++. I may have dislocated my elbow with that last fistpump. :(

Zombywuf
Mar 29, 2008

schnarf posted:

I'd really like to concatenate the entire string at compile time, but that seems hard.

Consider something like:
code:
template<class T, class List>
struct list_to_string {
  static const T value = List::head::value;
  list_to_string<T, List::tail>;
};

template<class T>
struct list_to_string<T, Null> {
  static const T value = 0;
};

list_to_string<char, fizzbuzz::type> fizzbuzz_;
char *fizzbuzz_string = reinterpret_cast<char *>(&fizzbuzz_);

Milotic
Mar 4, 2009

9CL apologist
Slippery Tilde
Look at those C/C++ guys frontin' with their pointers and templates. Time to step to and show them how we do this stuff in the .NET world.

code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FBConsole
{
    public static class CustomExtensions
    {

        public static IEnumerable<TSource> AllOrDefaultIfEmpty<TSource>(this IEnumerable<TSource> source, TSource defaultValue)
        {
            if (source.Count() != 0)
            {
                foreach (var tSourceValue in source)
                {
                    yield return tSourceValue;
                }
            }
            else
            {
                yield return defaultValue;
            }
        }

        public delegate void Func<TSource>(TSource source);

        public static IEnumerable<TSource> ForEach<TSource>(this IEnumerable<TSource> source, Func<TSource> func)
        {
            foreach (var tSourceValue in source)
            {
                func(tSourceValue);
                yield return tSourceValue;
            }
        }

    }

    public class FizzBuzzCharacter
    {
        public string CharacterOrNumber { get; set; }
        public int Order { get; set; }
        public bool DivisibleByThree { get; set; }
        public bool DivisibleByFive { get; set; }
        public bool DivisibleByFifteen { get; set; }
        public bool DivisibleByNada { get; set; }
    }

    static class Program
    {
        static void Main(string[] args)
        {
            List<FizzBuzzCharacter> fbCharacters = new List<FizzBuzzCharacter>();
            //Populate the list.
            fbCharacters.AddRange("fizz".ToCharArray()
                .Select((c, index) => new FizzBuzzCharacter() { 
                    CharacterOrNumber = c.ToString(), 
                    Order = index, 
                    DivisibleByThree = true, 
                    DivisibleByFive = false, 
                    DivisibleByFifteen = true, 
                    DivisibleByNada = false 
                }));
            fbCharacters.AddRange("buzz".ToCharArray()
                .Select((c, index) => new FizzBuzzCharacter() { 
                    CharacterOrNumber = c.ToString(), 
                    Order = index + 4, 
                    DivisibleByThree = false, 
                    DivisibleByFive = true, 
                    DivisibleByFifteen = true, 
                    DivisibleByNada = false 
                }));
            //Don't forget the new line character for matches!
            fbCharacters.AddRange("\n".ToCharArray()
                .Select((c, index) => new FizzBuzzCharacter() { 
                    CharacterOrNumber = c.ToString(), 
                    Order = 9, 
                    DivisibleByThree = true, 
                    DivisibleByFive = true, 
                    DivisibleByFifteen = true, 
                    DivisibleByNada = false 
                }));
            //Select the Fizz Buzz characters which match
            for (int i = 1; i <= 100; i++)
            {
                Type fbType = typeof(FizzBuzzCharacter);
                string methodName = string.Format("DivisibleBy{0}", i % 15 == 0 ? "Fifteen" : i % 5 == 0 ? "Five" : i % 3 == 0 ? "Three" : "Nada");
                var defaultFbc = new FizzBuzzCharacter() { CharacterOrNumber = i.ToString() + "\n" };

                var results = fbCharacters
                    .Where(fbc => (bool)fbType.InvokeMember(methodName, System.Reflection.BindingFlags.GetProperty, null, fbc, null))
                    .OrderBy(fbc => fbc.Order)
                    .AllOrDefaultIfEmpty(defaultFbc)
                    .ForEach(fbc => Console.Write(fbc.CharacterOrNumber));
                int x = results.Count(); //Force evaluation

            }
        }
    }

}

Volte
Oct 4, 2004

woosh woosh

schnarf posted:

All hail my terrible C++ template metaprogramming FizzBuzz: http://codepad.org/MCDF6Zt9. There's no runtime branching.
:smug:

I'd really like to concatenate the entire string at compile time, but that seems hard.
I did that with variadic C++0x templates once. You could open the EXE in a hex editor and see the answer. Unfortunately I think it's lost forever.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Milotic posted:

Look at those C/C++ guys frontin' with their pointers and templates. Time to step to and show them how we do this stuff in the .NET world.

That's beautifully horrible. Kudos.

Smugdog Millionaire
Sep 14, 2002

8) Blame Icefrog
As long as we're talking horrible C# fizzbuzz implementations, we have include melonhead's reflection version: http://dotnetpad.net/ViewPaste/SrmP90hoE02rYAyTIVHc3w

Thel
Apr 28, 2010

Milotic posted:

Look at those C/C++ guys frontin' with their pointers and templates. Time to step to and show them how we do this stuff in the .NET world.

I refuse to believe this actually works. :catstare:

(Nice job. :barf:)

Scaevolus
Apr 16, 2007

code:
#include <stdio.h>

int main(int n) {
    printf("%d\n\0  Fizz\n\0Buzz\n\0FizzBuzz\n"+(!(n%3)+2*!(n%5))*6,n)&&n%100&&main(n+1);
}

Milotic
Mar 4, 2009

9CL apologist
Slippery Tilde
Thank you for all the kind words. I found it surprisingly fun. There's a couple of problems with that solution, one of which being it is far too quick - you don't really get the excitement of waiting for the solution. We could throw in Thread.Sleeps, but that's far too predictable. We want people on the edge of their seats.

So I present: GeneticFizzBuzz, with a mutation chance of around 1 in 1 million.

code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GeneticFizzBuzzConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            DateTime startTime = DateTime.Now;
            var idealFizzBuzz = FizzBuzzSelector.BreedTheBuggersUntilOneFits();
            DateTime endTime = DateTime.Now;
            foreach (KeyValuePair<int, string> kvp in idealFizzBuzz.Map)
            {
                Console.WriteLine(string.Format("{0} : {1}", kvp.Key, kvp.Value));
            }
        }
    }

    public class FizzBuzzSelector
    {
        public static FizzBuzzCandidateSolution BreedTheBuggersUntilOneFits()
        {
            //Mitochondrial Eve
            var eve = new FizzBuzzCandidateSolution();
            for (int i = 1; i <= 100; i++) { eve.Map.Add(i, "Fizz"); }
            //Piltdown Buzz
            var piltdown = new FizzBuzzCandidateSolution();
            for (int i = 1; i <= 100; i++) { piltdown.Map.Add(i, "Buzz"); }

            var population = new List<FizzBuzzCandidateSolution>();
            population.Add(eve);
            population.Add(piltdown);
            double generations = 0;
            int bestMatch = 0;
            while (!population.Any(p => p.Suitability() == 100))
            {
                //Select the top two from the population
                var topFittest = population.OrderByDescending(p => p.Suitability()).Take(2);
                var newMother = topFittest.ElementAt(0);
                var newFather = topFittest.ElementAt(1);
                var baby = FizzBuzzBreeder.Mate(newMother, newFather);
                population = new List<FizzBuzzCandidateSolution>();
                population.Add(newMother); population.Add(newFather); population.Add(baby);
                generations++;
                int candidateBestMatch = Math.Max(
                    Math.Max(newMother.Suitability(), newFather.Suitability())
                    , baby.Suitability());
                if (candidateBestMatch > bestMatch)
                {
                    bestMatch = candidateBestMatch;
                    Console.WriteLine(string.Format("New best Match at {0} generations: {1}", generations, bestMatch));
                }
            }
            return population.First(p => p.Suitability() == 100);
        }
    }

    public class FizzBuzzCandidateSolution
    {
        public FizzBuzzCandidateSolution()
        {
            Map = new Dictionary<int, string>();
        }

        public Dictionary<int, string> Map { get; set; }

        private int? _Score = null;


        //Assume we only call this once and the Map never changes contents
        public int Suitability()
        {
            if (_Score == null)
            {
                _Score = 0;
                foreach (KeyValuePair<int, string> kvp in Map)
                {
                    if (Suitable(kvp.Key, kvp.Value)) { _Score++; }
                }
            }
            return _Score.Value;
        }

        public static bool Suitable(int i, string value)
        {
            if (i % 15 == 0 && value.Equals("FizzBuzz")) { return true; }
            else if ((i % 15 != 0) && (i % 5 == 0) && value.Equals("Buzz")) { return true; }
            else if ((i % 15 != 0) && (i % 3 == 0) && value.Equals("Fizz")) { return true; }
            else if ((i % 5 != 0) && (i % 3 != 0) && value.Equals(i.ToString())) { return true; }
            return false;
        }
    }


    public class FizzBuzzBreeder
    {
        private static Random Chance = new Random();
        private static Random PerformMutationChance = new Random();

        public static FizzBuzzCandidateSolution Mate(FizzBuzzCandidateSolution mother, FizzBuzzCandidateSolution father)
        {
            var child = new FizzBuzzCandidateSolution();
            foreach (var key in mother.Map.Keys)
            {
                var childValue = MateValue(key, mother.Map[key], father.Map[key]);
                child.Map.Add(key, childValue);
            }

            return child;
        }

        private static string MateValue(int key, string motherValue, string fatherValue)
        {
            //Can we just use the mother or father?
            if (FizzBuzzCandidateSolution.Suitable(key, motherValue))
            {
                return motherValue;
            }
            if (FizzBuzzCandidateSolution.Suitable(key, fatherValue))
            {
                return fatherValue;
            }
           

            //Should we use the mutation?
            int performMutation = PerformMutationChance.Next(1000000);
            if (performMutation == 0)
            {
                //Not suitable, let's randomly mutate.
                int mutationChance = Chance.Next(4);
                //Work out what the mutation would be:
                string mutation;
                switch (mutationChance)
                {
                    case 0: mutation = key.ToString(); break;
                    case 1: mutation = "Fizz"; break;
                    case 2: mutation = "Buzz"; break;
                    case 3: mutation = "FizzBuzz"; break;
                    default: mutation = "IMPOSSIBLE"; break;
                }

                return mutation;
            }
            else if (performMutation % 2 == 0)
            {
                return motherValue;
            }
            else
            {
                return fatherValue;
            }
        }
    }
}

It took me about 26 minutes 47 seconds to compute the results on my PC and required 25880962 generations. But next time it could be as much as an hour, as little as 1 second.

Here's how it progressed



(Why yes, I am on holiday)

ninjeff
Jan 19, 2004

Milotic posted:

code:
public static bool Suitable(int i, string value)
        {
            if (i % 15 == 0 && value.Equals("FizzBuzz")) { return true; }
            else if ((i % 15 != 0) && (i % 5 == 0) && value.Equals("Buzz")) { return true; }
            else if ((i % 15 != 0) && (i % 3 == 0) && value.Equals("Fizz")) { return true; }
            else if ((i % 5 != 0) && (i % 3 != 0) && value.Equals(i.ToString())) { return true; }
            return false;
        }
This is the best part by far.

The Saddest Robot
Apr 17, 2007
This is disgusting and almost made me vomit up my coffee.

I think that I may need consoling now. :cry:

Pardot
Jul 25, 2001




Since we're still talking about fizzbuzz, here is the best solution:

code:
  (0..99).map {|i| srand(46308667) if (i%15).zero?; ["FizzBuzz", "Buzz", i+1, "Fizz"][rand(4)]}
Find the seed in your language that causes the random number generator to output the sequence.

PalmTreeFun
Apr 25, 2010

*toot*
^^^^ That is amazing. :golfclap:

All of this goofy FizzBuzz poo poo hurts my head.

There's no place like home good old "x % 3" and "x % 5".

PalmTreeFun fucked around with this message at 21:55 on May 23, 2011

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Pardot posted:

code:
  (0..99).map {|i| srand(46308667) if (i%15).zero?; ["FizzBuzz", "Buzz", i+1, "Fizz"][rand(4)]}

bwahahahahahahaha

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Pardot posted:

Since we're still talking about fizzbuzz, here is the best solution:

code:
  (0..99).map {|i| srand(46308667) if (i%15).zero?; ["FizzBuzz", "Buzz", i+1, "Fizz"][rand(4)]}
Find the seed in your language that causes the random number generator to output the sequence.

Shouldn't rand(4) be the same if you seed it the same every time?

Edit: jiggled by trailing if

Adbot
ADBOT LOVES YOU

qntm
Jun 17, 2009
code:
print ["FizzBuzz", $_, $_, "Fizz", $_, "Buzz", "Fizz", $_, $_, "Fizz", "Buzz", $_, "Fizz", $_, $_ ]->[$_ % 15]."\n" for 0..99
I don't think I'm doing it right :shobon:

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply