• (disco) in reply to Zemm

    Javascript feels left out, so...

    var s = Array(4097).join("0");
    

    [spoiler]Although with support for ES6 you'll be able to write "0".repeat(4096)[/spoiler]

  • (disco) in reply to Gaska

    That's why we're afraid

  • (disco) in reply to abarker
    abarker:
    I didn't read that far into the article

    So, this is some previously unknown definition of TL;DR then? :P

  • (disco) in reply to isthisunique

    Any excuse to use the CodeDom to over-complicate a problem. Now you can generate a "better" solution in the .NET language of your choice! ;)

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.CodeDom;
    using System.CodeDom.Compiler;
    
    namespace LongStringGeneratorCreator
    {
        class Program
        {
            static void Main(string[] args)
            {
                CompilerInfo[] langInfo = CodeDomProvider.GetAllCompilerInfo();
                Console.WriteLine("Please choose a language:");
                Console.WriteLine("".PadLeft(30, '='));
                for (int i = 0; i < langInfo.Length; i++)
                    if (langInfo[i].IsCodeDomProviderTypeValid)
                        Console.WriteLine("{0} - {1}", i + 1, langInfo[i].CodeDomProviderType.Name);
                Console.WriteLine();
                ConsoleKeyInfo nullKey = new ConsoleKeyInfo('.', ConsoleKey.Decimal, false, false, false);
                ConsoleKeyInfo langSelKey = nullKey;
                while (langSelKey == nullKey)
                {
                    Console.Write("\nPlease choose: ");
                    ConsoleKeyInfo tempKeyInfo = Console.ReadKey();
                    int iKeyCharVal;
                    if (int.TryParse(tempKeyInfo.KeyChar.ToString(), out iKeyCharVal) && iKeyCharVal > 0 && iKeyCharVal <= langInfo.Length)
                        langSelKey = tempKeyInfo;
                    else
                        Console.WriteLine("?");
                }
                int iKeyCharValAgain = -1;
                if (langSelKey.KeyChar != null)
                    int.TryParse(langSelKey.KeyChar.ToString(), out iKeyCharValAgain);
    
                bool compile = false;
                Console.Write('\n');
                Console.Write('\n');
                ConsoleKeyInfo nullKey2 = new ConsoleKeyInfo('0', ConsoleKey.NumPad0, false, false, false);
                ConsoleKeyInfo chooseCompileKey = nullKey2;
                while (chooseCompileKey == nullKey2)
                {
                    Console.Write('\n');
                    Console.Write("Compile output? ");
                    ConsoleKeyInfo tempKeyInfo2 = Console.ReadKey();
                    if (tempKeyInfo2.Key == ConsoleKey.Y || tempKeyInfo2.Key == ConsoleKey.N)
                        chooseCompileKey = tempKeyInfo2;
                    else
                        Console.WriteLine("?");
                }
                if (chooseCompileKey.Key == ConsoleKey.Y)
                    compile = true;
                else
                    compile = false;
    
                // Now we generate the actual code.
                CodeNamespace ns = new CodeNamespace("com.wtf.LongStringGen");
                ns.Imports.Add(new CodeNamespaceImport("System"));
    
                CodeTypeDeclaration lsGen = new CodeTypeDeclaration("LongStringGen");
                lsGen.TypeAttributes = System.Reflection.TypeAttributes.Public | System.Reflection.TypeAttributes.Class;
                lsGen.IsClass = true;
    
                CodeMemberField maxField = new CodeMemberField(
                    new CodeTypeReference(new CodeTypeParameter("System.Int32")), "_maxLen"
                );
                maxField.Attributes = MemberAttributes.Private;
                lsGen.Members.Add(maxField);
    
                CodeMemberField charField = new CodeMemberField(
                    new CodeTypeReference(new CodeTypeParameter("System.Char")), "_strChar"
                );
                charField.Attributes = MemberAttributes.Private;
                lsGen.Members.Add(charField);
    
                CodeConstructor cstr = new CodeConstructor();
                cstr.Attributes = MemberAttributes.Public;
                cstr.Parameters.Add(
                    new CodeParameterDeclarationExpression(
                        new CodeTypeReference(new CodeTypeParameter("System.Char")), "char"));
                cstr.Parameters.Add(
                    new CodeParameterDeclarationExpression(
                            new CodeTypeReference("System.Int32"), "max"));
                cstr.Statements.Add(new CodeAssignStatement(
                    new CodeFieldReferenceExpression(
                        new CodeThisReferenceExpression(),
                        "_strChar"
                    ), new CodeArgumentReferenceExpression("char")
                ));
                cstr.Statements.Add(new CodeAssignStatement(
                    new CodeFieldReferenceExpression(
                        new CodeThisReferenceExpression(),
                        "_maxLen"
                    ), new CodeArgumentReferenceExpression("max")
                ));
                lsGen.Members.Add(cstr);
    
                CodeMemberMethod meth = new CodeMemberMethod();
                meth.Name = "GetLongString";
                meth.Attributes = MemberAttributes.Public;
                meth.ReturnType = new CodeTypeReference(new CodeTypeParameter("System.String"));
                meth.Parameters.Add(
                    new CodeParameterDeclarationExpression(
                        new CodeTypeReference(new CodeTypeParameter("System.Char")),
                        "strChar"
                    )
                );
                meth.Parameters.Add(
                    new CodeParameterDeclarationExpression(
                        new CodeTypeReference(new CodeTypeParameter("System.Int32")),
                        "strLen"
                    )
                );
                
                CodeVariableDeclarationStatement dec = new CodeVariableDeclarationStatement(new CodeTypeReference(new CodeTypeParameter("System.Char")),"s");
                meth.Statements.Add(dec);
    
                CodeAssignStatement ass = new CodeAssignStatement(
                    new CodeVariableReferenceExpression("s"),
                    new CodeArgumentReferenceExpression("strChar")
                );
                meth.Statements.Add(ass);
    
                CodeVariableDeclarationStatement opt = new CodeVariableDeclarationStatement(new CodeTypeReference(new CodeTypeParameter("System.String")), "o");
                meth.Statements.Add(opt);
    
                CodeAssignStatement oas = new CodeAssignStatement(
                    new CodeVariableReferenceExpression("o"),
                    new CodePropertyReferenceExpression(new CodeTypeReferenceExpression(new CodeTypeReference(new CodeTypeParameter("System.String"))), "Empty")
                );
                meth.Statements.Add(oas);
    
                CodeIterationStatement flp = new CodeIterationStatement(
                    new CodeSnippetStatement(),
                    new CodeBinaryOperatorExpression(
                        new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("o"), "Length"),
                        CodeBinaryOperatorType.LessThan,
                        new CodeArgumentReferenceExpression("strLen")
                    ),
                    new CodeSnippetStatement());
                flp.Statements.Add(
                    new CodeAssignStatement(
                        new CodeVariableReferenceExpression("o"),
                        new CodeMethodInvokeExpression(
                            new CodeMethodReferenceExpression(new CodeTypeReferenceExpression(new CodeTypeReference(new CodeTypeParameter("System.String"))), "Concat"),
                            new CodeVariableReferenceExpression("o"),
                            new CodeCastExpression(
                                new CodeTypeReference(new CodeTypeParameter("System.String")),
                                new CodeMethodInvokeExpression(
                                    new CodeMethodReferenceExpression(
                                        new CodeVariableReferenceExpression("s"),
                                        "ToString"
                                    )
                                )
                            )
                        )
                    )
                );
                meth.Statements.Add(flp);
    
                meth.Statements.Add(
                    new CodeMethodReturnStatement(
                        new CodeVariableReferenceExpression("o")
                    )
                );
                lsGen.Members.Add(meth);
    
                ns.Types.Add(lsGen);
    
                CodeCompileUnit cdCmpUnt = new CodeCompileUnit();
                cdCmpUnt.Namespaces.Add(ns);
    
                CodeDomProvider provider = langInfo[iKeyCharValAgain - 1].CreateProvider();
                CodeGeneratorOptions opts = new CodeGeneratorOptions();
                opts.BlankLinesBetweenMembers = false;
                opts.ElseOnClosing = true;
    
                StringBuilder sbOutput = new StringBuilder();
                using (System.IO.StringWriter sr = new System.IO.StringWriter(sbOutput))
                    provider.GenerateCodeFromCompileUnit(cdCmpUnt, sr, opts);
    
                Console.WriteLine(sbOutput);
    
                Console.Write('\n');
                Console.Write('\n');
                Console.Write("\nSpecify file name: ");
                string outFileNm = Console.ReadLine();
                string outPath = System.IO.Path.Combine(Environment.CurrentDirectory, outFileNm);
                if (compile)
                {
                    CompilerParameters compParams = new CompilerParameters();
                    compParams.ReferencedAssemblies.Add("System.dll");
                    compParams.WarningLevel = 3;
                    compParams.CompilerOptions = "/optimize";
                    compParams.GenerateExecutable = true;
                    compParams.IncludeDebugInformation = false;
                    compParams.GenerateInMemory = false;
                    compParams.OutputAssembly = outPath + ".dll";
                    CompilerResults compResult = provider.CompileAssemblyFromDom(compParams, cdCmpUnt);
                    if (compResult.Errors.Count == 0)
                        Console.WriteLine("File created at: " + compResult.PathToAssembly);
                    else
                    {
                        Console.WriteLine("This following errors occured durring compilation:");
                        for (int i = 0; i < compResult.Errors.Count; i++)
                            Console.WriteLine("\t- {0}", compResult.Errors[i].ErrorText);
                    }
                }
                else
                {
                    using (System.IO.FileStream fs = new System.IO.FileStream(outPath, System.IO.FileMode.Create, System.IO.FileAccess.Write))
                    using (System.IO.StreamWriter sr = new System.IO.StreamWriter(fs))
                        sr.Write(sbOutput.ToString());
                }
    
                Console.WriteLine();
                Console.WriteLine("".PadLeft(30, '='));
                Console.WriteLine("ALL DONE!  Press <Enter> to exit.");
                Console.ReadLine();
            }
        }
    }
    

    Resulting output (C#):

    namespace com.wtf.LongStringGen
        {
            using System;
    
            public class LongStringGen
            {
                private int _maxLen;
                private char _strChar;
                public LongStringGen(char @char, int max)
                {
                    this._strChar = @char;
                    this._maxLen = max;
                }
                public virtual string GetLongString(char strChar, int strLen)
                {
                    char s;
                    s = strChar;
                    string o;
                    o = string.Empty;
                    for (
                    ; (o.Length < strLen);
                    )
                    {
                        o = string.Concat(o, ((string)(s.ToString())));
                    }
                    return o;
                }
            }
        }
    
  • (disco) in reply to abarker
    abarker:
    public String ZeroedBitString(double megaBytes)
    {
        int z = (int)Math.Floor(megaBytes * 1024);
        z = z * 2;
        var s;
        var c = 0;
        var l = 0;
        while (z-- > c++)
        {
            var s = l.ToString() + s;
        }
    
        return (string)s;
    }
    

    It's also off-by-one1.


    1: I hesistate to call it an error, given the number of intentional :wtf:s in this place.

    EDIT: Nevermind, I am TRWTF.

  • (disco) in reply to PWolff
    const int stringLength4096 = 4096;
    
    public IEnumerable<string> repeatedZeroString<T>(T stringLength4096) 
    {
    	foreach(var s in String.Join("", Enumerable.Repeat(new List<double> { 0 }, wtf.stringLength4096 / 2).SelectMany(x => x)).Split().TakeWhile(x => DateTime.IsLeapYear(DateTime.Now.Year) ? new Random().Next(0, 10000) > 2 : true).SelectMany(x => x.ToCharArray()).Zip(Enumerable.Range(0, wtf.stringLength4096 / 2).AsEnumerable().Distinct().Aggregate<int, string, string>("", (string y, int x) => y + "0", (string x) => x.ToString()).Where(s => s.GetHashCode() == '0'.GetHashCode()), (char m1, char m2) => m1 + "" + (DateTime.UtcNow.Millisecond == 246 ? 'O' : m2)).SelectMany(x => x).Select(x => x.ToString().Normalize(NormalizationForm.FormKD)))
    	{
    		yield return s;
    	}
    }
    

    This is a much more robust version

    1. It uses both our methods for maximum data redundancy.
    2. It provides multiple guards against bit rot, gamma rays, and the like.
    3. Unicode normalization, because normal is always better. 45645456456456456456. You can take as many zeros at a time as you like. Don't want all of them at once? No problem!
    4. Generic methods are always more flexible.
  • (disco)
    const (
    	zero1    = "0"
    	zero2    = zero1 + zero1
    	zero4    = zero2 + zero2
    	zero8    = zero4 + zero4
    	zero16   = zero8 + zero8
    	zero32   = zero16 + zero16
    	zero64   = zero32 + zero32
    	zero128  = zero64 + zero64
    	zero256  = zero128 + zero128
    	zero512  = zero256 + zero256
    	zero1024 = zero512 + zero512
    	zero2048 = zero1024 + zero1024
    	zero4096 = zero2048 + zero2048
    )
    

    http://play.golang.org/p/PD62rlSZDk

  • (disco)
    uint64_t zero = 1;
    
    while (true)
    {
        (*zero) = '0';
        zero++;
    }
    
  • (disco) in reply to ben_lubar

    Not enterprisey enough

    const string zero0 = "";
    const string zero1 = zero0 + "0";
    const string zero2 = zero1 + "0";
    const string zero3 = zero2 + "0";
    const string zero4 = zero3 + "0";
    const string zero5 = zero4 + "0";
    const string zero6 = zero5 + "0";
    [elided to prevent post text overflow. thank discourse for that. 
    i was going to make you scroll for the whole thing]
    const string zero4094 = zero4093 + "0";
    const string zero4095 = zero4094 + "0";
    const string zero4096 = zero4095 + "0";
    

    in other news pasting that entire script before eliding causes chrome to shit its pants for about a minute trying to render the preview.... Maybe it';s something to do with the 160kb of text it tried to format?

  • (disco)

    or as anonymous097646764589806 pointed out to me OOB:

    Math.Pow(10, 4096).ToString().Trim('1')
    
  • (disco) in reply to presidentsdaughter

    http://i.kinja-img.com/gawker-media/image/upload/s--eRk9T9Pz--/wtwgjhsf8d9hk3wry96y.jpg

  • (disco) in reply to powerlord

    That game BETTER have some Zero III action in it. Even if it wouldn't make any sense, being a direct sequel.

    Zero III is the best.

  • (disco) in reply to blakeyrat

    Speaking of Zero III action, Aksys finally fixed the Virtue's Last Reward intro on Youtube.

    https://www.youtube.com/watch?v=4h4xPoe4w1g

  • (disco) in reply to powerlord

    Was it broken?

    EDIT: Alice's outfit is such a huge failure at being sexy, it blows my mind.

  • (disco) in reply to blakeyrat
    blakeyrat:
    Was it broken?

    It was marked as Private at some point and thus no one could view it. Now it's just marked as unlisted, but it's linked from the main Virtue's Last Reward web page.

  • (disco)
    [image] http://community.usvsth3m.com/2048/wtdwtf-edition/ The text length limit gets in the way, but the idea survives.
  • (disco) in reply to powerlord

    https://en.wikipedia.org/wiki/Zero_Escape:_Virtue%27s_Last_Reward#Characters

    I like how the Wiki page shows Zero III right there in the lineup of characters as if he were playable.

    And yet it does not include this screenshot:

    [image]

    which is the best thing ever.

    [image]
  • (disco) in reply to blakeyrat

    Hmm, I've only played 999, so this may be interesting. But it's probably too anime.

  • (disco)

    I don't see the WTF here. Generating 4096 zeros at runtime comes with a performance penalty. This guy is writing compiler-efficient code!

  • (disco) in reply to mruhlin
    mruhlin:
    Generating 4096 zeros at runtime comes with a performance penalty.

    yes, but how much of one? are we generating those 4k zeros ONCE and then using the same set of zeros for the entire lifetime of the program? in which case that cost can be amortized to zero. are we generating those 4k zeros multiple times, but for periodic operations like a nightly or hourly task? in which case that cost can be amortized to nearly zero.

    Are we generating those zeros many thousands of times but the compiler is able to optimize the call to hand out the same set of immutable zeros each time in which case the performance cost is negligable (and a decent JIT compiler will do just this)

    finally: is the performance hit significant enough to justify the developers and maintainers time in counting and verifying that exactly the right number of zeros is created for the operation, time and time, and time over througthout the years long lifecycle of the application? if not then fuck the cost because the dev and maintenance time costs are higher than the cost for the inefficiency.

    Remember:

    • premature optimization is the root of all evil
    • optimization before performing benchmarks and profiling including cost/benefit analysis is premature optimization
    • optimization not followed by benchmarks and profiling to measure quantitatively the improvements with cost/benefit analysis against future maintenance tasks is retroactively premature optimization.
  • (disco) in reply to ben_lubar
    function s(total, ch){
        if(total == 1)
            return ch;
        else
            return s(total/2,ch)+s(total/2,ch);
    }
    
  • (disco) in reply to presidentsdaughter
    presidentsdaughter:
    TRWTF is nobody being afraid WHY there is a 4K '0'-filled string in the first place.

    It's so you can select a random character from the string and know what to expect. It's probably used in a magic trick (pick an integer between 0 and 4095...any integer. Now, is this the string you selected in the first place? )

  • (disco) in reply to Magus

    It is way too anime, but the writing and localization are good enough that it's worth a playthrough.

  • (disco) in reply to Placeholder

    +212 that's brillant

  • (disco) in reply to Jarry

    Ok, firstly, omitting curly braces is terrible style, second, that fails for odd numbers.

    function s(total, success, error) {
      if (total & 1 == 1) { return error("odd"); }
      else if (total == 1) { return "0"; }
      else { return success(s(total, function(n) { return s(n/2); }, error) + success(s(total, function(n) { return s(n/2); }, error); }
    }
    
  • (disco) in reply to blakeyrat
    blakeyrat:
    It is way too anime, but the writing and localization are good enough that it's worth a playthrough.

    To take this one step farther:

    The writing and English localization were good enough to save the third game in the series from cancellation.

    It was originally canceled due to Virtue's Last Reward's poor sales in Japan.

    Edit: It's clear from the timing of the announcement that Aksys Games saved it... it's otherwise unusual for the localizer to announce that a new game exists.

  • (disco) in reply to powerlord
    powerlord:
    It was originally canceled due to Virtue's Last Reward's poor sales in Japan.

    There's nothing really they're doing that absolutely requires a Nintendo DS or PS Vita to run the game; if they were smart, they'd port the thing to every platform under the sun.

  • (disco) in reply to blakeyrat

    In Japan, only indie devs care about PC. Which is why all the ports are so bad.

  • (disco) in reply to Magus

    I'm not even talking PC, although it would be nice. I'm talking iPad and Android and Samsung and Kindle and yada yada.

  • (disco) in reply to blakeyrat

    That's still PC as far as they're concerned. 90% of that is android anyway.

    But Japan doesn't believe in ports. Then too, Aksys and Arc System Works, who are best friends, consider PC to be equivalent to 'filthy pirates'. They're getting slightly better now.

  • (disco) in reply to Magus
    Magus:
    In JapanOn Earth, only indie devs care about PC. Which is why all the ports are so bad.

    Japan ain't special.

  • (disco) in reply to Buddy

    No, that's not true at all. There are still companies that make RTS games, and Sid Meyer always makes sure we get things. So does Blizzard.

    But yes, there are definitely companies that ignore PC. Most of them just don't make Tokiden Kiwami.

  • (disco) in reply to Magus

    Have you played D3 on console? So much better.

    Magus:
    Physics locked to rendering, the game only works at 30 fps

    Give it a year or two.

  • (disco) in reply to Buddy
    Buddy:
    Repressed your AH memories so soon? Can't blame you for that.

    I didn't buy it until well after they'd stopped that.

    blakeyrat:
    In that the game started ruined and only gradually after months of patches became less ruined? Is that what you mean?

    Because of the above, yes :smiley: I missed out on the worst bits, so it was just a fairly alright game when I played it.

    It was somewhat boring, though.

  • (disco) in reply to Buddy

    Ok, Firstly, had a parameter to customize the character, second, the fail was intended so WONTFIX_WORKS_AS_DESIGNED third, you are imposing your heteronormative styles as the only way. :tropical_fish:

  • (disco) in reply to Magus

    [quote="Magus, post:87, topic:50112] Blizzard didn't ruin the PC experience at all. [/quote] Repressed your AH memories so soon? Can't blame you for that.

    [quote] At which point the physics will still be locked to the framerate, because Tecmo Koei doesn't care. [/quote] No, other way. I'm saying that batman was just the beginning.

  • (disco) in reply to Jarry

    :rolleys:

  • (disco) in reply to Buddy

    if you ain't gonna play this isn't fun

  • (disco)
    Placeholder:

    This is a much more robust version

    1. It uses both our methods for maximum data redundancy.
    2. It provides multiple guards against bit rot, gamma rays, and the like.
    3. Unicode normalization, because normal is always better.
    4. You can take as many zeros at a time as you like. Don't want all of them at once? No problem!
    5. Generic methods are always more flexible.

    It would be even more flexible and robust if we'd

    1. Define a constant for the empty string - you never know whether the empty string will be redefined some day
    2. For compiler opitmization, divisions by powers of 2 should be done by the >> operator. This is easier to understand, too, for us old ones that still know assembler.
    3. As someone already pointed out (allegedly @abarker, but I found only the quote by @Dreikin), the "0" should be created by 0.ToString(). For additional robustness (maybe some time a zero will be represented by an empty string), by 0.ToString("0").
    4. We should alternately use stringLength5096, wtf.stringLength4096, and 4096, just in case a gamma burst flipped one of the bits of one of these quantities.
    accalia:
    Math.Pow(10, 4096).ToString().Trim('1')
    

    We should use System.Numerics.BigInteger, otherwise rounding errors could interfere with the result:

    BigInteger.Pow(new BigInteger(10), 4096).ToString().TrimStart('1')
    
    Jarry:
    WONTFIX_WORKS_AS_DESIGNED
    So does
    Buddy:
    function s(total, success, error) {
        // ...
    }
    
      - it throws an exception for any integer passed into total.

    (there seems to be no way to properly quote code...

  • (disco) in reply to Magus
    Magus:
    But still, Blizzard didn't ruin the PC experience at all.

    In that the game started ruined and only gradually after months of patches became less ruined? Is that what you mean?

  • (disco) in reply to blakeyrat
    blakeyrat:
    Magus:
    But still, Blizzard didn't ruin the PC experience at all.

    In that the game started ruined and only gradually after months of patches became less ruined? Is that what you mean?

    Maybe he meant with non-ruined PC experience the ruined game experience?

  • (disco) in reply to Buddy
    Buddy:
    Repressed your AH memories so soon? Can't blame you for that.

    The nightmare was over before I bothered buying the game.

    blakeyrat:
    In that the game started ruined and only gradually after months of patches became less ruined? Is that what you mean?

    It's no real D2 sequel, but it works alright on PC. What brokenness there was didn't appear to be the result of forcing a console game on PC users.

  • (disco) in reply to accalia

    I tried to put it on play.golang.org, but I got Failed to load resource: the server responded with a status of 413 (Request Entity Too Large).

  • (disco) in reply to Jarry

    I'm sorry, it's just, there were so many things wrong with what I posted, and your response is that it's too ‘heteronormative’? I don't know what to do with that.

  • (disco) in reply to accalia
    accalia:
    s = '0' * 4096
    

    if you're looking to golf, python is even better.

    Even though not shorter Julia is still better:

    s = "0"^4096
    

    Clearly string concatenation behaves more like multiplication (e.g. summation is supposed to be commutative, which concatenation clearly isn't). Therefore you get exponentiation when repeating concatenations.

  • (disco) in reply to Buddy

    Clearly you haven't been keeping up with the times. It must be nice being so privileged that you can ignore the world around you.

    <No, I'm not serious.

  • (disco) in reply to bitti

    Multiplication is commutative as well. You gain nothing and require two different operators to "add" things together.

  • (disco) in reply to ben_lubar

    You never exceeded behind primary school math? Noncommutative multiplication algebras are used all the time. Look up matrixes. Or just try out a Rubik's cube.

  • (disco) in reply to bitti

    And we use noncommutative addition for strings. Any more questions?

  • (disco) in reply to ben_lubar

    Exactly. That's the reason why Julia is saner, because it adheres mathematical conventions.

Leave a comment on “The New Zero”

Log In or post as a guest

Replying to comment #:

« Return to Article