What is the Sandbox?

This "Sandbox" is a place where Code Golf users can get feedback on prospective challenges they wish to post to the main page. This is useful because writing a clear and fully specified challenge on the first try can be difficult. There is a much better chance of your challenge being well received if you post it in the Sandbox first.

See the Sandbox FAQ for more information on how to use the Sandbox.

Get the Sandbox Viewer to view the sandbox more easily

To add an inline tag to a proposal use shortcut link syntax with a prefix: [tag:king-of-the-hill]

Rotations Required

Given input 2 values:

$$\x >= 0\$$ :Distance to travel (float)

$$\r>0\$$ :Radius of wheel (float)

Output the number of rotations required by the wheel to travel that distance.

Constraints:

Your code must not contain any digits.

You cannot use pi functions (math.pi)

Output must be an integer.(In case exact int is not obtained, floor it) 1.0 is not a valid output, it should be 1.

Test Cases

x       r    o/p
50      1    7
0       34   0
50      0.3  26
44      33   0
5.5     5.5  0
105     5    3
155     5    4
6.28318 1    1 #This signifies that pi was approximated to 3.1419


Scoring:

Score= No. of bytes+20/number of digits taken for pi after decimal point

If you have taken more than 10 digits:

Score= No. of bytes

• "You cannot use pi functions" is an unobservable requirement, which is not allowed. You need some test cases. The no-digits rule won't actually make this problem harder for most golflangs. – Nathan Merrill Oct 16 '18 at 12:43
• @NathanMerrill The latter is less problematic (and more objective) than the former. – user202729 Oct 16 '18 at 14:21
• Test cases are not strictly required, but it would make it easier to check if a solution is definitely incorrect. – user202729 Oct 16 '18 at 14:22
• Info: Adding constraints just "because the challenge is too easy" usually doesn't make it more interesting (unless the constraints are the main difficulty of the challenge, for example for radiation-hardened challenges) – user202729 Oct 16 '18 at 14:24
• I will add test cases. @NathanMerrill, there just shouldn't be any inbuilt functions that give pi directly is what I want to say. – Vedant Kandoi Oct 17 '18 at 5:35
• @VedantKandoi I understand what you want, but we allow any language on this site, and it's impossible to define what a "pi-giving function" is to work for all possible languages. – Nathan Merrill Oct 17 '18 at 6:26
• Is there any other way I could word it then, as I don't want python, java etc. users to use math.pi or should I just remove it? – Vedant Kandoi Oct 17 '18 at 7:15
• Also, since pi is in the formula, exact int will never be obtained, and if anyone uses approximate value of pi, they may get exact int at certain value or 1 less than desired answer. What can I add for this? – Vedant Kandoi Oct 17 '18 at 7:48
• I changed the scoring method for the above issue, so should be okay now. – Vedant Kandoi Oct 17 '18 at 8:15
• Why would the output be floored? Surely you should use ceiling so that the wheel is actually travelling that distance. – Jo King Oct 17 '18 at 8:26
• I was thinking of something like how many full rotations need to be completed. – Vedant Kandoi Oct 17 '18 at 8:31
• "Not using a pi function" is a non-observable program requirement, which is one of the things to avoid when writing a challenge. I don't see any way to fix this challenge: fundamentally what it's asking is too trivial to be interesting. My advice would be to delete the body of this answer and then delete the answer (to keep the sandbox tidy) and then to try to come up with a challenge which is inherently interesting enough that it doesn't need that kind of restriction. – Peter Taylor Oct 17 '18 at 14:06

Write a Self-Hosting Ouroboros: each quine produces the next quine AND its interpreter

• Too elaborate or long post?
• Rules too strict? Too lax?

A Quine is a program that prints its own source code as output when it is run.

A Self-Hosting Quine (which is something I just made up, although I'm sure it exists already) is a quine that also produces an interpreter/compiler/emulator/whatever for itself (from now on I will just say "interpreter").

I believe this actually means that a lot of essential functionality must be "circularly defined" - for example, to print output, the interpreter must rely on the parent interpreter's ability to print output. So maybe we should call this a Von Munchausen Quine?

An Ouroboros Program or Quine Relay is a quine that prints a different quine, which then prints yet another program, and so on, until the last quine produces the original quine. See this famous example that cycles through over a hundred languages.

A Self-Hosting Ouroboros, then, is quine that produces a program in another language, and also produces an interpreter for that language. The interpreter should be in the current language, so that the next quine can immediately be run and produce the quine after that.

Tangent: obviously, the idea can also be extended to interpreter multiquines but that can be another challenge. Let's make Von Munchausen's Ouroboros first!

Rules

• The ouroboros must be able to make a complete cycle
• Score by total quines in chain / shortest source code (in bytes) in the chain (bytes to allow non-textual outputs)
• Empty quines and interpreters do not count - two character minimum
• Code-golf languages allowed
• No languages defined just for this challenge - no "I define language x to always produce quine y in C plus the complete GCC compiler when fed any input"-stuff please
• Quines must be valid code in their programming languages
• Interpreters that are partial language implementations are fine, however:
• it must be able to run the quine, and produce the next quine (obviously).
• it should be able to run any other correct code that is limited to the same language subset¹. No hyperfitting²!
• for the sake of code golfing it may accept incorrect code that a normal interpreter should not (the quine is already restricted to correct code anyway)

Clarifications

Yes, you can make a quine that produces itself and its own interpreter

Counts as a 1-chain ouroboros.

What would an "interpreter" for machine code be?

An emulator. Which of course needs some way to load a program and produce the output. You may define a fictional simplified, minimal hardware set-up to do so. For example: a (partial) Z80 emulator where:

• two hardware ports are connected to send output bytes to (one for interpreter, one for quine). Are those bytes interpreted as raw bytes/ASCI/UTF8 text/whatever? Up to you!
• the program is already loaded in memory, at whatever address is most convenient (quine too big to fit in the addressable memory space? Define an input port to scan bytes from I guess :P)
• the PC (program counter), and SP (stack pointer) registers initiate at whatever value is most convenient for creating a quine in Z80 opcode

Obviously, no set-ups with fictional ROM that just happens to contain a new quine, or stuff like that (even though this would be hard to really abuse, since that ROM would still need to be implemented in the emulator).

Am I seriously expecting anyone to create an emulator like this? No, but let's keep the possiblity open (some stack machines might be code golf-friendly enough for the challenge).

"Borrowing" snippets from each other is encouraged, but give accreditation and link to sources!

Because we all really just want to see how long this can get, no? Besides, whatever you take probably has to be heavily modified to fit it in your existing ouroboros chain anyway. Sharing is caring, and accreditation is the decent thing to do.

No dead-line, nor will a winner be selected. Just make as long a chain as possible.

¹ You wrote an interpreter for a subset of Rust, but it doesn't feature the borrow checker? That is fine long as:

• it works with correct Rust code limited to the language subset
• it works with the quine itself
• the quine itself is correct rust code

² Example of what I do and do not consider hyperfitting: if your interpreter can deal with for(var i; i < 10; i++) { a[i] = i; } but crashes without the enclosing {} because it expects them to designate code blocks, that counts as a partial implementation. If var only expects i, or < only expects i and 10? Hyperfitting. If var only accepts single letter names, and < only expects variables on the left and literals on the right? Probably hyperfitting but debatable.

• What would the interpreter of a program written in machine code be? – user202729 Oct 19 '18 at 15:14
• How should we separate the quine output and the interpreter output? – Jo King Oct 21 '18 at 0:10
• @user202729: an emulator – Job Oct 21 '18 at 13:01
• @JoKing: hmm, good question. Two separate calls to whatever output method is chosen? (print or its equivalent) – Job Oct 21 '18 at 13:03

Unicode encoder

Do Invent your own Unicode 7.0.0 encoding (as efficient as possible) with score 317754(the lowest possible score). Shortest encode+decode program win.

You can either write two programs doing encode and decode, or write one with argument/input method difference deciding whether it's encoding or decoding

As you may know, the Unicode standard has room for 1,114,111 code points, and each assigned code point represents a glyph (character, emoji, etc.).

Most code points are not yet assigned.

Current Unicode implementations take a lot of space to encode all possible code points (UTF-32 takes 4 bytes per code point, UTF-16: 2 to 4 bytes, UTF-8: 1 to 4 bytes, etc.)

-

- Write an encoder and a decoder in any language of your choice
- The encoder's input is a list of code points (as integers) and it outputs a list of bytes (as integers) corresponding to your encoding.
- The decoder does the opposite (bytes => code points)
- Your implementation has to cover all Unicode 7.0.0 assigned code points
- It has to stay backwards-compatible with ASCII, i.e. encode Basic latin characters (U+0000-U+007F) on one byte, with 0 as most significant bit.
- Encode all the other assigned code points in any form and any number of bytes you want, as long as there is no ambiguity (i.e. two code points or group of code points can't have the same encoding and vice versa)
- Your implementation doesn't have to cover UTF-16 surrogates (code points U+D800-U+DFFF) nor private use areas (U+E000-U+F8FF, U+F0000-U+10FFFF)
- Your encoding must be context-independant (i.e. not rely on previously encoded characters) and does NOT require self-synchronization (i.e. each byte doesn't have to infer where it's located in the encoding of a code point, like in UTF-8).

To sum up, here are the blocks that you have to cover, in JSON:

[
[0x0000,0x007F], // Basic Latin
[0x0080,0x00FF], // Latin-1 Supplement
[0x0100,0x017F], // Latin Extended-A
[0x0180,0x024F], // Latin Extended-B
[0x0250,0x02AF], // IPA Extensions
[0x02B0,0x02FF], // Spacing Modifier Letters
[0x0300,0x036F], // Combining Diacritical Marks
[0x0370,0x03FF], // Greek and Coptic
[0x0400,0x04FF], // Cyrillic
[0x0500,0x052F], // Cyrillic Supplement
[0x0530,0x058F], // Armenian
[0x0590,0x05FF], // Hebrew
[0x0600,0x06FF], // Arabic
[0x0700,0x074F], // Syriac
[0x0750,0x077F], // Arabic Supplement
[0x0780,0x07BF], // Thaana
[0x07C0,0x07FF], // NKo
[0x0800,0x083F], // Samaritan
[0x0840,0x085F], // Mandaic
[0x08A0,0x08FF], // Arabic Extended-A
[0x0900,0x097F], // Devanagari
[0x0980,0x09FF], // Bengali
[0x0A00,0x0A7F], // Gurmukhi
[0x0A80,0x0AFF], // Gujarati
[0x0B00,0x0B7F], // Oriya
[0x0B80,0x0BFF], // Tamil
[0x0C00,0x0C7F], // Telugu
[0x0D00,0x0D7F], // Malayalam
[0x0D80,0x0DFF], // Sinhala
[0x0E00,0x0E7F], // Thai
[0x0E80,0x0EFF], // Lao
[0x0F00,0x0FFF], // Tibetan
[0x1000,0x109F], // Myanmar
[0x10A0,0x10FF], // Georgian
[0x1100,0x11FF], // Hangul Jamo
[0x1200,0x137F], // Ethiopic
[0x1380,0x139F], // Ethiopic Supplement
[0x13A0,0x13FF], // Cherokee
[0x1400,0x167F], // Unified Canadian Aboriginal Syllabics
[0x1680,0x169F], // Ogham
[0x16A0,0x16FF], // Runic
[0x1700,0x171F], // Tagalog
[0x1720,0x173F], // Hanunoo
[0x1740,0x175F], // Buhid
[0x1760,0x177F], // Tagbanwa
[0x1780,0x17FF], // Khmer
[0x1800,0x18AF], // Mongolian
[0x18B0,0x18FF], // Unified Canadian Aboriginal Syllabics Extended
[0x1900,0x194F], // Limbu
[0x1950,0x197F], // Tai Le
[0x1980,0x19DF], // New Tai Lue
[0x19E0,0x19FF], // Khmer Symbols
[0x1A00,0x1A1F], // Buginese
[0x1A20,0x1AAF], // Tai Tham
[0x1AB0,0x1AFF], // Combining Diacritical Marks Extended
[0x1B00,0x1B7F], // Balinese
[0x1B80,0x1BBF], // Sundanese
[0x1BC0,0x1BFF], // Batak
[0x1C00,0x1C4F], // Lepcha
[0x1C50,0x1C7F], // Ol Chiki
[0x1CC0,0x1CCF], // Sundanese Supplement
[0x1CD0,0x1CFF], // Vedic Extensions
[0x1D00,0x1D7F], // Phonetic Extensions
[0x1D80,0x1DBF], // Phonetic Extensions Supplement
[0x1DC0,0x1DFF], // Combining Diacritical Marks Supplement
[0x1F00,0x1FFF], // Greek Extended
[0x2000,0x206F], // General Punctuation
[0x2070,0x209F], // Superscripts and Subscripts
[0x20A0,0x20CF], // Currency Symbols
[0x20D0,0x20FF], // Combining Diacritical Marks for Symbols
[0x2100,0x214F], // Letterlike Symbols
[0x2150,0x218F], // Number Forms
[0x2190,0x21FF], // Arrows
[0x2200,0x22FF], // Mathematical Operators
[0x2300,0x23FF], // Miscellaneous Technical
[0x2400,0x243F], // Control Pictures
[0x2440,0x245F], // Optical Character Recognition
[0x2460,0x24FF], // Enclosed Alphanumerics
[0x2500,0x257F], // Box Drawing
[0x2580,0x259F], // Block Elements
[0x25A0,0x25FF], // Geometric Shapes
[0x2600,0x26FF], // Miscellaneous Symbols
[0x2700,0x27BF], // Dingbats
[0x27C0,0x27EF], // Miscellaneous Mathematical Symbols-A
[0x27F0,0x27FF], // Supplemental Arrows-A
[0x2800,0x28FF], // Braille Patterns
[0x2900,0x297F], // Supplemental Arrows-B
[0x2980,0x29FF], // Miscellaneous Mathematical Symbols-B
[0x2A00,0x2AFF], // Supplemental Mathematical Operators
[0x2B00,0x2BFF], // Miscellaneous Symbols and Arrows
[0x2C00,0x2C5F], // Glagolitic
[0x2C60,0x2C7F], // Latin Extended-C
[0x2C80,0x2CFF], // Coptic
[0x2D00,0x2D2F], // Georgian Supplement
[0x2D30,0x2D7F], // Tifinagh
[0x2D80,0x2DDF], // Ethiopic Extended
[0x2DE0,0x2DFF], // Cyrillic Extended-A
[0x2E00,0x2E7F], // Supplemental Punctuation
[0x2FF0,0x2FFF], // Ideographic Description Characters
[0x3000,0x303F], // CJK Symbols and Punctuation
[0x3040,0x309F], // Hiragana
[0x30A0,0x30FF], // Katakana
[0x3100,0x312F], // Bopomofo
[0x3130,0x318F], // Hangul Compatibility Jamo
[0x3190,0x319F], // Kanbun
[0x31A0,0x31BF], // Bopomofo Extended
[0x31C0,0x31EF], // CJK Strokes
[0x31F0,0x31FF], // Katakana Phonetic Extensions
[0x3200,0x32FF], // Enclosed CJK Letters and Months
[0x3300,0x33FF], // CJK Compatibility
[0x3400,0x4DBF], // CJK Unified Ideographs Extension A
[0x4DC0,0x4DFF], // Yijing Hexagram Symbols
[0x4E00,0x9FFF], // CJK Unified Ideographs
[0xA000,0xA48F], // Yi Syllables
[0xA4D0,0xA4FF], // Lisu
[0xA500,0xA63F], // Vai
[0xA640,0xA69F], // Cyrillic Extended-B
[0xA6A0,0xA6FF], // Bamum
[0xA700,0xA71F], // Modifier Tone Letters
[0xA720,0xA7FF], // Latin Extended-D
[0xA800,0xA82F], // Syloti Nagri
[0xA830,0xA83F], // Common Indic Number Forms
[0xA840,0xA87F], // Phags-pa
[0xA880,0xA8DF], // Saurashtra
[0xA8E0,0xA8FF], // Devanagari Extended
[0xA900,0xA92F], // Kayah Li
[0xA930,0xA95F], // Rejang
[0xA960,0xA97F], // Hangul Jamo Extended-A
[0xA980,0xA9DF], // Javanese
[0xA9E0,0xA9FF], // Myanmar Extended-B
[0xAA00,0xAA5F], // Cham
[0xAA60,0xAA7F], // Myanmar Extended-A
[0xAAE0,0xAAFF], // Meetei Mayek Extensions
[0xAB00,0xAB2F], // Ethiopic Extended-A
[0xAB30,0xAB6F], // Latin Extended-E
[0xABC0,0xABFF], // Meetei Mayek
[0xAC00,0xD7AF], // Hangul Syllables
[0xD7B0,0xD7FF], // Hangul Jamo Extended-B
[0xF900,0xFAFF], // CJK Compatibility Ideographs
[0xFB00,0xFB4F], // Alphabetic Presentation Forms
[0xFB50,0xFDFF], // Arabic Presentation Forms-A
[0xFE00,0xFE0F], // Variation Selectors
[0xFE10,0xFE1F], // Vertical Forms
[0xFE20,0xFE2F], // Combining Half Marks
[0xFE30,0xFE4F], // CJK Compatibility Forms
[0xFE50,0xFE6F], // Small Form Variants
[0xFE70,0xFEFF], // Arabic Presentation Forms-B
[0xFF00,0xFFEF], // Halfwidth and Fullwidth Forms
[0xFFF0,0xFFFF], // Specials
[0x10000,0x1007F], // Linear B Syllabary
[0x10080,0x100FF], // Linear B Ideograms
[0x10100,0x1013F], // Aegean Numbers
[0x10140,0x1018F], // Ancient Greek Numbers
[0x10190,0x101CF], // Ancient Symbols
[0x101D0,0x101FF], // Phaistos Disc
[0x10280,0x1029F], // Lycian
[0x102A0,0x102DF], // Carian
[0x102E0,0x102FF], // Coptic Epact Numbers
[0x10300,0x1032F], // Old Italic
[0x10330,0x1034F], // Gothic
[0x10350,0x1037F], // Old Permic
[0x10380,0x1039F], // Ugaritic
[0x103A0,0x103DF], // Old Persian
[0x10400,0x1044F], // Deseret
[0x10450,0x1047F], // Shavian
[0x10480,0x104AF], // Osmanya
[0x10500,0x1052F], // Elbasan
[0x10530,0x1056F], // Caucasian Albanian
[0x10600,0x1077F], // Linear A
[0x10800,0x1083F], // Cypriot Syllabary
[0x10840,0x1085F], // Imperial Aramaic
[0x10860,0x1087F], // Palmyrene
[0x10880,0x108AF], // Nabataean
[0x10900,0x1091F], // Phoenician
[0x10920,0x1093F], // Lydian
[0x10980,0x1099F], // Meroitic Hieroglyphs
[0x109A0,0x109FF], // Meroitic Cursive
[0x10A00,0x10A5F], // Kharoshthi
[0x10A60,0x10A7F], // Old South Arabian
[0x10A80,0x10A9F], // Old North Arabian
[0x10AC0,0x10AFF], // Manichaean
[0x10B00,0x10B3F], // Avestan
[0x10B40,0x10B5F], // Inscriptional Parthian
[0x10B60,0x10B7F], // Inscriptional Pahlavi
[0x10B80,0x10BAF], // Psalter Pahlavi
[0x10C00,0x10C4F], // Old Turkic
[0x10E60,0x10E7F], // Rumi Numeral Symbols
[0x11000,0x1107F], // Brahmi
[0x11080,0x110CF], // Kaithi
[0x110D0,0x110FF], // Sora Sompeng
[0x11100,0x1114F], // Chakma
[0x11150,0x1117F], // Mahajani
[0x111E0,0x111FF], // Sinhala Archaic Numbers
[0x11200,0x1124F], // Khojki
[0x11300,0x1137F], // Grantha
[0x11480,0x114DF], // Tirhuta
[0x11580,0x115FF], // Siddham
[0x11600,0x1165F], // Modi
[0x11680,0x116CF], // Takri
[0x118A0,0x118FF], // Warang Citi
[0x11AC0,0x11AFF], // Pau Cin Hau
[0x12000,0x123FF], // Cuneiform
[0x12400,0x1247F], // Cuneiform Numbers and Punctuation
[0x13000,0x1342F], // Egyptian Hieroglyphs
[0x16800,0x16A3F], // Bamum Supplement
[0x16A40,0x16A6F], // Mro
[0x16B00,0x16B8F], // Pahawh Hmong
[0x16F00,0x16F9F], // Miao
[0x1B000,0x1B0FF], // Kana Supplement
[0x1BC00,0x1BC9F], // Duployan
[0x1BCA0,0x1BCAF], // Shorthand Format Controls
[0x1D000,0x1D0FF], // Byzantine Musical Symbols
[0x1D100,0x1D1FF], // Musical Symbols
[0x1D200,0x1D24F], // Ancient Greek Musical Notation
[0x1D300,0x1D35F], // Tai Xuan Jing Symbols
[0x1D360,0x1D37F], // Counting Rod Numerals
[0x1D400,0x1D7FF], // Mathematical Alphanumeric Symbols
[0x1E800,0x1E8DF], // Mende Kikakui
[0x1EE00,0x1EEFF], // Arabic Mathematical Alphabetic Symbols
[0x1F000,0x1F02F], // Mahjong Tiles
[0x1F030,0x1F09F], // Domino Tiles
[0x1F0A0,0x1F0FF], // Playing Cards
[0x1F100,0x1F1FF], // Enclosed Alphanumeric Supplement
[0x1F200,0x1F2FF], // Enclosed Ideographic Supplement
[0x1F300,0x1F5FF], // Miscellaneous Symbols and Pictographs
[0x1F600,0x1F64F], // Emoticons
[0x1F650,0x1F67F], // Ornamental Dingbats
[0x1F680,0x1F6FF], // Transport and Map Symbols
[0x1F700,0x1F77F], // Alchemical Symbols
[0x1F780,0x1F7FF], // Geometric Shapes Extended
[0x1F800,0x1F8FF], // Supplemental Arrows-C
[0x20000,0x2A6DF], // CJK Unified Ideographs Extension B
[0x2A700,0x2B73F], // CJK Unified Ideographs Extension C
[0x2B740,0x2B81F], // CJK Unified Ideographs Extension D
[0x2F800,0x2FA1F], // CJK Compatibility Ideographs Supplement
[0xE0000,0xE007F], // Tags
[0xE0100,0xE01EF]  // Variation Selectors Supplement
]

Total: 116,816 code points.

Scoring
--

Your score is the number of bytes that your encoder outputs when you feed it with all the 116,816 possible code points (in one time or separately).

• I suppose 317754 is the optimal score, right? – user202729 Oct 22 '18 at 9:37
• @user202729 Yes if there are 116,816 code points – l4m2 Oct 22 '18 at 9:38
• p.s. I think you should expand it while it is on the sandbox, just in case somebody don't understand the specification. – user202729 Oct 22 '18 at 9:38

Forcing a kernel panic from a mountaintop

This is a thought resulting from a curious incident where C# code opening file apparently caused a BSOD. In the conclusion, it was due to a faulty driver, but from that a thought came up --- can one cause a kernel panic (or BSOD) using managed code exclusively?

Why?

Typically in such environment, there are many compile-time and run-time checks that safeguard the code from doing something that would cause a kernel panic. For a mature managed environment, it should be impossible to cause the operating system to arrive into a bad state. In the case, though it was C# code, the fact that a faulty driver was involved breached the walled garden. But can we breach it from within?

Rules

• The code must be managed in some fashion (e.g. Java, C#, VB.NET), and normally comes with both compile-time and run-time checks.
• The code should be running in a virtual machine or equivalent. (e.g. Java's JVM or .NET's AppDomain)
• The code should NOT rely on any external anything. No extern declarations, no networking, no dodgy APIs.
• The code should NOT use any construct which allow direct access to resources (e.g. unsafe in C#)
• The code should use only the native libraries & API available as part of its usual environment.
• Throwing an exception is not sufficient. To qualify, the code must result in a kernel panic.

Criteria

Essentially a code-golf -

• The less code to kernel panic, the better
• The fewer dependencies the code uses to make it happen, the better
• The code that consistently causes a kernel panic is better than one that only does it sometimes
• Is the code considered malicious code? – user202729 Nov 10 '18 at 15:26
• What is "managed code"? – user202729 Nov 10 '18 at 15:26
• While it can be used with malicious intent, the goal is more toward proving whether it's possible to unintentionally break through the walled garden. RE: "managed code" --- it might be a .NET-specific term but I use it in general sense to refer to any programming language that usually run in a some kind of sandbox -- I cited Java's JVM or .NET's AppDomain as such examples. Those usually enforce runtime checks in addition to compile-time checks to prevent doing stupid thing like passing a null pointer which usually is a trappable exception. – this Nov 10 '18 at 19:06

Play snake on a 50*50 grid. The snake will start at length 3, heading (2,0) with body (1,0) and (0,0). It shouldn't bump into wall or itself. There is always one food, which increases the length of snake by 1 when eaten.

Smallest amount of steps till there's no space to place food win. Flexible I/O, anyway it doesn't matter.

Vote on whether the food placer is transparent and allow food manipulation(Up for yes, down for no)

• I think there are already quite a few snake challenges. You need to flesh out some more details here. How do you determine where the food will spawn? Will you be given some sampling of the game state (vision?) on each step? – Beefster Dec 28 '18 at 19:22
• @Beefster If "food placer is transparent and allow food manipulation", you just know how it spawns; If not, you get access to the location of current food – l4m2 Dec 29 '18 at 3:44
• If food manip. is allowed, is the optimal score achievable by finding an Hamiltonian path starts with the snake? – user202729 Dec 29 '18 at 8:55
• @user202729 It depends on how strong the manipulation is – l4m2 Dec 29 '18 at 10:54
• -1 for winning entries must be written in one of the 25 top languages. – Jo King Jan 19 '19 at 9:28
• I'm trying to exclude golfing languages with that - this only seems like an interesting challenge to me if you don't allow languages where it's excessively trivial. Any suggestions for how to do that in a more permissive way or other thoughts about that goal? – lahwran Jan 19 '19 at 22:13
• actually, I think this will be quite difficult in many code golf languages as well, as they usually try to get brevity by cramming things into single letters and numbers. there are of course languages where it'll be excessively trivial, but that's fine, those solutions most likely just won't be upvoted. – lahwran Jan 19 '19 at 22:21
• Most golfing languages won't be able to pull sth. from the interconnected-webs afaik, so there's no real need to invent arbitrary restrictions to ban them. – ბიმო Jan 21 '19 at 16:25
• Also "but that's fine, those solutions most likely just won't be upvoted" is too optimistic, usually it's the other way around :( – ბიმო Jan 21 '19 at 16:26
• dang, good to know. – lahwran Jan 21 '19 at 22:55

HTML-tac-toe

Build a one-player tic-tac-toe game with only HTML and CSS.

Introduction

You can do just about anything with a fully-featured programming language, but how much can you accomplish on a Neopets petpage? Inspired by http://www.neopets.com/~vuh

Challenge

Build a one-player tic-tac-toe game with only HTML and CSS.

• Use no more than one file.
• GIFs (including animations), PNGs, and JPEGs are allowed.
• Flash, embedded scripts, iframes, and JavaScript are not allowed.
• It must work in the at least two standard browsers (FF, Chrome, Safari, Opera, IE)

Inputs: The player will click on a space when it's their turn to move there.

Outputs: The page will show the current board state at all times. The page will play an optimal move whenever the player moves, unless the game is over.

You're free to decide who starts and who has X or O.

Scores

• -10 per image
• -1 per opening bracket or brace (< / { )

Brownie points for design, flair, and new tricks!

Example Input and Output

Input:

Click on the top left of an empty grid

Output:

Grid shows my mark where I clicked and the opposite mark in the left middle or top middle.

• I'd recommend against restricting languages, and against score bonuses too – ASCII-only Jan 22 '19 at 4:15
• @ASCII-only I can drop the bonuses without much consequence, but it's not a new challenge without a language or host restriction. Any suggestions? – Qaz Jan 22 '19 at 4:45
• True, but... language restrictions are pretty frowned upon – ASCII-only Jan 22 '19 at 4:47
• Welcome to PPCG! You may want to check this post out, it certainly helped me when starting with writing my own challenges. Also, your post does not have a well-defined objective winning criterion. It seems like it is atomic code-golf or code-challenge [1/2] – ბიმო Jan 22 '19 at 19:32
• , but you will need to define how answers are scored (in this case lower is worse) and how ties are treated. Also why do you disallow GIFs but JPGs not? I know most will know, but maybe explain or at the very least link to somewhere where the rules for tic-tac-toe are explained. What counts as an X, what as an O? There are a lot of open question atm. [2/2] – ბიმო Jan 22 '19 at 19:36
• JPGs are allowed. (That's the same format as JPEG, just a different extension.) I can change it to 'images', but I'm worried about some image format I don't know of that makes the challenge trivial. More points, more better! That seems clear enough, but I can certainly spell it out. Are ties forbidden? Two entries with the same number of points seem equally good to me, but the first posted could be the winner. If I link to tic-tac-toe rules, does that answer "What counts as an X, what as an O?" or are you asking something else? – Qaz Jan 23 '19 at 0:13
• "Standard exceptions are allowed IF they work on Neopets.com." How do we know what works on Neopets.com? If we have to create accounts on a random third party site to test answers and know whether they're valid or not, the question should and probably will end up closed with a lot of downvotes. – Peter Taylor Jan 24 '19 at 15:34
• This isn't very interesting in general. It essentially amounts to creating every possible layout of a tic-tac-toe board and linking them together with clever CSS and HTML hacks so it fits in 25 pages. I think it could be made a bit more interesting by making it atomic code golf scoring on the total number of html files used, lowest scores win rather than limiting the total number of pages. – Beefster Jan 25 '19 at 20:36
• @PeterTaylor very well, dropped that altogether – Qaz Jan 25 '19 at 22:53
• @Beefster The page I link to as the inspiration (neopets.com/~vuh) uses only one html file, and the source isn't too hard to understand, so perhaps I should link to the creator of the page instead, limit the solutions to one page, or both. – Qaz Jan 25 '19 at 22:53
• I highly suggest looking through current codegolf questions to see which are well-received by the community. This question seems highly arbitrary and leaves too much under-specified. – qwr Jan 27 '19 at 20:28

Bit flipper

Given a string s and a positive number n, return the string s with n random bits flipped. (A random number can be generated in any way, including pseudo-random number generators)

Example:

Before:

Hello World


After (n = 2, 2 bits flipped):

Hello wOrld

• How exact are the bytes being 'flipped'? Are we changing the bits? Is the output deterministic? It doesn't look like you're modifying any specific bit of the byte, or reversing it, or doing bitwise negation. – Rɪᴋᴇʀ Mar 21 '19 at 1:55
• @Riker well changing from uppercase to lowercase is just xor 32. But they'rem saying byte flipper not bit flipper which is a bit confusing – ASCII-only Mar 21 '19 at 6:09
• @Riker The bits are flipped – smileycreations15 Mar 21 '19 at 9:42
• @JoKing No, that was an example because I didn’t wanted binary non-unicode characters in the post. – smileycreations15 Mar 21 '19 at 9:44
• What is n? On the basis of what little is specified in the question, I would be tempted to write an implementation for n=0 which consists of the empty program in GolfScript... – Peter Taylor Mar 21 '19 at 16:44
• @PeterTaylor A user defined count of how many bytes will be flipped – smileycreations15 Mar 21 '19 at 18:12
• I think the confusion here is that "bytes" doesn't mean what you think it means. From the lone test case I think what you're trying to ask us is: given a string s and a number n, change the case of n random letters in s - would that be correct? – Shaggy Mar 22 '19 at 0:41
• I assume case was just an example of bit 5 flipping. I'd recommend writing it like Given a string s and a positive number n, return the string s with n random bits flipped. Though from there you run into problems about invalid unicode sequences in the output – Jo King Mar 22 '19 at 3:45
• @JoKing I replaced with your example. – smileycreations15 Mar 22 '19 at 7:47
• What do you mean by Default n = 3? Also, how should programs handle invalid unicode sequences? – Jo King Mar 22 '19 at 9:14
• @JoKing By default, n should be 3. And invalid unicode sequences should not be handled, and the data should be directly printed out to stdout or any output file. – smileycreations15 Mar 22 '19 at 12:35
• When you say random, do you mean of our choice? pseudo-random? fetched from random.org? – Artemis still doesn't trust SE Mar 26 '19 at 23:16
• @ArtemisFowl It is selected by the program. – smileycreations15 Mar 27 '19 at 10:45
• @smileycreations15 It's gonna be hard to make that 100% random – Artemis still doesn't trust SE Mar 27 '19 at 15:46
• @smileycreations15 Maybe you should add that to the question. – Artemis still doesn't trust SE Mar 27 '19 at 20:35

You can't tell me what to do!!!

Intentionally break as many coding conventions as possible while crafting a working Hello World

For each language, a coding convention standard will be selected. The following is the current list:

PHP -> PSR-2

C++ -> ISO C++ Style Guide

Python -> PEP-8

The maximum file length is 6000 characters. Any code beyond the first 6000 will not count towards broken conventions. (Using conventions that you have set to break after the 6000 point, however, will count against you.)

If you do not see your language, you may choose one of the most common coding standards for your language, and use that, and (hopefully) it will be noticed and added to the list. Each language is its own competition. (For example: If your code is in Ruby, you're not competing against C++ code)

This is the coding equivalent of an ugly baby contest, and pushes you to think outside the box (possibly way too far outside the box). The goal is to write a 'simple' Hello World program. However, you have to do it while breaking as many coding conventions as possible, and being as ugly as possible (but still working!)

The advantages of this puzzle are multi-purpose. This is to challenge the coder to separate long-standing habits (which generally follow coding conventions) from functionality - to encourage creativity. Further, it also serves as a reverse example to demonstrate when coding conventions are a help vs a hindrance.

Remember, ugly doesn't have to mean gibberish or unnecessarily long or poorly running. In fact, code length or runtime do not factor into the evaluation.

For example, you could write procedural code using only classes, use an eval() to declare constants, or use only use variable names using characters that have nothing to do with what the variable does, reverse indentation, or rely exclusively on gotos in an interpreted language. The only thing your code has to do is output "Hello World" to the command line or an equivalent.

Each answer should list and link to coding conventions it breaks and receives 1 point for each broken code convention (but instant total of zero points the code follows any coding convention it says its breaking). If a voter agrees it violates all the listed coding conventions, upvote the code that violates the most while still functioning. (Accidentally violating coding conventions, however, does not count. Each one violated coding convention must be documented and intentional.)

Note: For each coding convention taken on, it must be consistently broken across the entire program. Following the convention even once invalidates your entire code. Habits are your enemy. Further note: If you declare you're breaking a convention, you MUST break it. If it's not applicable, it doesn't count.

Alternate Scoring method:

I'm personally not a fan of this scoring method as it allows accidental points and becomes more like it's testing the enforcement hook rather than creative code style breaking, but some like the more computer-controlled scoring method... so there ya go.

Sandbox Reminder: Sandbox is a place for constructive criticism. Saying, "I don't like it" or "I wouldn't do it" isn't constructive criticism. Last time I had this in the sandbox, most criticism was built on disliking the type of challenge, not actually building it properly. If you don't like the challenge concept, then just don't do it. If you have legitimate suggestions on how to make the challenge better then do so. I will do my best to address legitimate points.

My Oh so wrong Hello world - PHP - Attempting 2 points

Breaking conventions in PSR-2:

• breaking "Opening braces for classes MUST go on the next line, and closing braces MUST go on the next line after the body."
• breaking "All PHP files MUST end with a single blank line."

--

<?php
class hiworld{public $printme = "Hello World"}$hiworld = new hiworld;
echo $hiworld->$print;
?>


My Oh so wrong and totally fake Hello world - PHP - Alt.Points(53)

<?php
class hiworld{public $printme = "Hello World"}$hiworld = new hiworld;
echo $hiworld->$print;
?>


Attempted with:

50 pts: PSR-2 Foo's Enforcement Hook: Foo-Checker [http://foo.example.com] (Broke)

3 pts: PSR-2 Bar's Enforcement Hook: Bar-Checker [http://bar.example.com]

Deleted Version

• That just makes it better. – liljoshu Mar 8 '19 at 23:29
• Hate as measured by votes, however, is a discrete value, and therefore objective. – liljoshu Mar 8 '19 at 23:37
• While I disagree that pop cons need an objective criterion for voting (anything objectively measurable wouldn't need votes), pop cons are out of favour for that very reason. It is rare for a pop con to be welcomed. – trichoplax Mar 10 '19 at 10:00
• @trichoplax Fair enough on that. I'll change encouragement to just be on coding style. – liljoshu Mar 10 '19 at 22:25
• The problem is mostly the popularity-contest tag, which are very hard to do correctly. For example, how do you define break as many coding conventions as possible? How do you define convention, especially for esoteric languages where there are no conventions? The amount of conventions broken also depends on the poster's and viewer's standards, and is therefore not objective. – Jo King Mar 12 '19 at 21:38
• If a voter agrees it violates all the listed coding conventions, upvote the code that violates the most while still functioning is still subjective. All conventions are going to be subjective, e.g. Proper indentation, does that mean 4 spaces or a tab? One voter might think one way, and another might think another way. In general, I think you've chosen a very subjective winning criterion, and short of listing and defining the conventions yourself, it's not going to become objective again. – Jo King Mar 13 '19 at 0:06
• I've removed my downvote and the related comment. – trichoplax Mar 13 '19 at 6:59
• The new scoring mechanism is still subjective, but a big improvement. What counts as a convention still seems like a grey area. Does it need to be from an official source, for some definition of official? Does it need to have been posted online prior to the posting of this challenge? Does it need to be stating that coders "must", "should", or something else? – trichoplax Mar 13 '19 at 7:05
• One way to make this objective would be as a language specific challenge, for example with something like JSLint. That way your score is the number of complaints triggered when running it through the linter, and highest wins. Only being able to compete in one language doesn't seem ideal, but I mention it as an example in case someone can come up with a more inclusive approach. – trichoplax Mar 13 '19 at 7:08
• "Whatever makes you feel dirty for having put it through your keyboard" and "Each answer should list and link to coding conventions it breaks" are mutually contradictory. – Peter Taylor Mar 13 '19 at 12:00
• @trichoplax I do like your idea of counting linter complaints to make it more objective, and feel that's on the right track. Maybe bringing some code-cleanup program into it, and seeing how much work it has to do? – liljoshu Mar 13 '19 at 15:33
• I feel like this could work if one language was selected, with associated style guide/linter, and an objective scoring system made for that. Otherwise, you're comparing a lot of apples and shoes. – Spitemaster Mar 14 '19 at 16:36
• I know this probably isn't going anywhere, but the most 'official' python style guide is probably PEP 8. – Artemis still doesn't trust SE Apr 6 '19 at 18:17
• @liljoshu You've got my upvote for what it's worth, though I agree this needs some improvements. – Artemis still doesn't trust SE Apr 8 '19 at 22:35
• Something like codegolf.stackexchange.com/questions/172445/… might be ok – Embodiment of Ignorance Apr 10 '19 at 3:04

Count the Trees

Challenge

Given an input consisting of ASCII art of trees such as

  0            <
|      >       @
|   @          |    0
|   |    #     |    |
|   |    |     |    |
==========================


count the number of trees present (5 in this case).

Rules

Input

• The input might not have all lines at the same length.
• You can take your input from stdin or take it as a string argument.
• There will be a ground as the last line, consisting of = characters.
• All trees have a straight trunk of | characters.
• The crown of the tree can be one of 0@#.
• Each tree will have at least one trunk character.
• You may assume that there is at least one tree.
• Unfortunately, there might be birds (< and >) photobombing the ASCII art. They should be ignored.
• If you find a bird on the ground, then it is dead and another tree will grow in its place tomorrow (carcasses make great fertiliser). In the ASCII art below, there will be two trees tomorrow:
   #
|   <
=========


Output

• Output the number of trees that are present today and those that will be present tomorrow.

Test cases

  0            <
|      >       @
|   @          |    0
|   |    #     |    |
|   |    |     |    |
==========================


(5, 5)

   #
|   <
=========


(1, 2)

 0#@
|||
|||
=====


(3, 3)

• What about languages that can't handle input over multiple lines? Can the input be taken as a list of strings? Or a single string with \n as separators? Also, the task is basically just counting all non-space characters on the second line from the bottom. The birds in the air, different crowns etc. won't affect the answers in any way. MATLAB: @(s)nnz(s(2,:)-32). – Stewie Griffin May 23 '19 at 10:16
• A single string should be fine; a list is not acceptable. And thanks for pointing out the shortcut. Maybe it would be better to require validation? – bb94 May 24 '19 at 15:50

The heights of Natural Numbers

Every number can be expressed as the product of itself and/or smaller numbers. This is a fundamental feature of our world.

For example 10 can be expressed as the product of 5 and 2, or as the product of 1 and 10.

9 can be expressed as the product of 3 and 3, or 1 and 9.

12 can be expressed as the product of 2 and 6. 6, in turn, can be expressed as the product of 2 and 3. It could also be the product of 3 and 4, and in turn 4 is the product of 2 and 2. Lastly there is 1 and 12.

7 can only be expressed as the product 1 and itself.

The numbers in the products are called factors. Every number has at least 2 factors, itself and 1. Numbers with only those two factors are called prime. Numbers with more than 2 are called composite.

These factors can be written as trees. The root begins with the number itself, and factors are written below, by adding branches to the root.

7 has 1 and 7. This is a short tree. It has one prime.

9 has 3 and 3. This is also a short tree, but it has two branches. It has two primes, but they are both at depth of 1 down the tree.

10 has 5 and 2. Again, short. Again, primes are at depth 1.

12 has 6 and 2, 6 has 3 and 2. This tree has two levels of height. Note that at the second level, every factor is prime, but at the first level, some factors are composite. 12 has also 3 and 4, and 4 becomes 2 and 2 - the tree looks similar to when using 6 and 2, this is called Isomorphic, which comes from the Greek language words for same shape.

In other words, every number has several trees of factors, and each tree has leaves that are prime factors. And every tree has a height, the number of branches one must travel between the root and the furthest leaf.

For example, every number has a tree of height 1. Itself and 1. So.

7 has height 1, because 1x7=7

9 also is height 1, because 3x3=9, and 1x9=9, are both of height 1.

12 is height 2. 3x2x2 becomes 3x4, which becomes 12. There are two branches between 12 and either leaf of 2.

But 12 is also height 1 because it has a different tree of height 1: 1x12=12.

16 is height 3, because 16 becomes 2*8 becomes 2*2*4, becomes 2*2*2*2. But 16 is also depth 1 because 1x16=16. However 16 is not depth 2, because no tree of it's factors has primes up two branches from the root.

Write a program that given an integer n, returns a sequence of the first 100 numbers that have prime factor trees of height n.

• The prologue about factors and primes is unnecessary-- we know what they are. A diagram would be nice. You didn't explicitly mention the rules for creating trees-- why can't 16 = 4x4 = (2x2)x(2x2), or 16 = 8x2 = (8x1)x2? Are depth and height the same? – lirtosiast Jun 29 '19 at 7:12

Best Mile Time

Introduction

Your friend has been trying to improve his mile time on. Unfortunately, he isn't very good at keeping a steady pace and constantly speeds up and then slows down. He usually runs for many miles at a time and wants to choose the fastest mile of his run to determine his mile time.

Given your friend's distance versus time, determine his fastest mile time for a contiguous mile stretch.

Input

A list of distances (in miles) sampled at an even interval.

Output

The length of the smallest interval during which a distance of at least one mile was traveled.

Rules

• You may assume that the the total distance traveled is at least 1 mile.
• The mile time must be for a continuous time interval.
• Standard loop-holes are forbidden.
• Standard rules apply.
• This is , so the program with the smallest asymptotic time complexity wins!
• Ties will be broken by fastest run time.

Example

Python 3.7, O(n ^ 2)

Try it online!

from typing import List

def fastest_mile_time(distances):
"""Determines the fastest mile time from a list of distances.

Parameters
----------
distances : List[float]
The list of distances in miles.

Returns
-------
int
The length of the smallest interval during which at least one mile was traveled.
"""
intervals = []
for i in range(len(distances) - 1):
for j in range(i + 1, len(distances)):
if distances[j] - distances[i] >= 1:
intervals.append((i, j))
break

return min(map(lambda x: x[1] - x[0], intervals))

• @FryAmTheEggman how's this? – Billylegota Jul 19 '19 at 2:32
• Unless I'm missing something this is trivially O(n): keep two pointers into the list, advance them keeping them 1 mile apart, and keep track of the running minimum time. I'm downvoting, so ping me if I was mistaken or if this is updated so I can update my vote. – lirtosiast Jul 19 '19 at 2:52
• @lirtosiast O(n) is trivial. I just gave O(n ^ 2) as an example. However it isn't clear to me that O(n) is the lower bound. I think the fact that the sequence is monotonically increasing may be of some use (although I've yet to show that to be the case). – Billylegota Jul 19 '19 at 3:20
• The optimal solution is O(n). You need to iterate two pointers through the entire list one time to ensure that you have found the minimum valid difference. The range of time this will take ranges from Ω(n) to O(2n) in the optimized case. for(i=j=0;j<length;i++){for(;array[j]-array[i]<1&&j<length;j++){}minTime=min(minTime , j-i)} – fəˈnɛtɪk Jul 20 '19 at 17:00
• Consider a list where every element at even index 2n is n, and every element at index 2n+1 is either n+.5 or n+1. If there is an integer at an odd index, the fastest mile time is 1, otherwise it's 2. But we have no way of determining this without reading all n/2 odd indices. – lirtosiast Jul 20 '19 at 18:17
• @lirtosiast +1 thanks for such a clear example! – Billylegota Jul 21 '19 at 6:16

Produce a self-reproducing data structure

Write the shortest code to produce a self-reproducing list, dictionary, array, and so on and so forth. That is, when you index any one of the logically-available items that belongs to the resulting data structure that you have produced, you get the same data structure when you compare the equality between the data structure before you indexed and the data structure after you indexed.

• In order to verify your code with automatically-provided constructions in programming languages, you should pick an operator that compares whether two values are equal (or does type-comparisons, if available).
• If your language does not provide an equality operator, you should simulate an equality operator yourself using operators like - or other operators that do the job of comparing values (as in Acc!, where an explicit comparison operator is not provided.)

Example

This is an example of a validity/equality test of a possible solution in a Python REPL (when you have already produced a list, namely list, where it produces itself at its 0th item). This test simply compares the equality between the non-indexed list and the indexed list:

>>> list
[[...]]
>>> list[0]
[[...]]
>>> list==list[0]
True


However, if the result of the last line (the equality comparison) is not a truthy value in your language (for example False and 0 in Python), then your answer is invalid and should be improved.

Rules

• Your program does not have to take input; neither does it have to explicitly output the data structure. However, your resulting data structure has to be accessible in some way.
• This is a contest; the shortest answer will win.
• In this challenge, the values on both operands in the equality check should have the same type.
• Your code (both your testing code and your producing code) should not produce any errors; any outputs to stderr are considered non-truthy values and demonstrates that your code is invalid.
• What does "compare it" mean? There are many many types of comparison one can perform, and they don't necessarily give the same result for the same values. – Peter Taylor Jul 24 '19 at 7:11
• @A__ For JavaScript, is it == or ===? Either way, people will be angry. – wizzwizz4 Jul 24 '19 at 13:16
• @A__ Because either the challenge is trivial (['']) or you're arbitrarily restricting a language. Work on your definition of "equality operator". – wizzwizz4 Jul 24 '19 at 13:46
• @A__ So, basically, you want (x=[])[0]=x? No clever tricks? Just a bog-standard recursive data structure? (Though, it might be interesting in languages where those aren't allowed.) – wizzwizz4 Jul 24 '19 at 14:07
• @wizzwizz4 In fact, your program is a clever trick that I have not thought of. Mine is 13 bytes, yours is 11 bytes. Yes, what I want is a bog-standard recursive data structure, as long as it is not a duplicate of another question. (My program is a=[];a.push(a)) – user85052 Jul 24 '19 at 14:10
• @U10-Forward 0 bytes – tjjfvi Jul 24 '19 at 14:32
• @tjjfvi I thought about that one, but I didn't think it'd be syntactically valid. It does, however, work. – wizzwizz4 Jul 24 '19 at 15:19
• @wizzwizz4 How do you know which language? – tjjfvi Jul 24 '19 at 15:31
• @tjjfvi I just assumed it was a language where the "null" / "undefined" singleton was indexable, returning the very same value. – wizzwizz4 Jul 24 '19 at 15:34
• @wizzwizz4 No, JS: window.window === window :) – tjjfvi Jul 24 '19 at 15:38
• @tjjfvi I read the challenge differently to you. I thought it meant "any one of the logically-available items". By this rule, (x={}).x=x is the shortest I can think of, other than the trivial case. – wizzwizz4 Jul 24 '19 at 15:53
• @tjjfvi Well i do it in Python so no such a thing called 0 bytes in python – U10-Forward Jul 25 '19 at 1:08
• Alternative: window["window"]===window – user85052 Jul 25 '19 at 4:06

Recursive Sum Up The Digits

Produce the shortest code that sums up all the digits in a number, and after if it still has more than one digit, sum it up again and again until it's with one digit, example: 987 would become 6 since 9 + 8 + 7 is 24, whereas 2 + 4 is 6.

• I have the feeling I've seen this challenge before, but I'm unable to find it. It could be that I'm confusing it with two similar loose challenges, since there are more challenges where we continue doing something until a single digit remains, and there are also loads of challenges summing the digits of an integer. I'm not 100% sure anymore whether there is already one with both combined. – Kevin Cruijssen Aug 5 '19 at 6:37
• This is just "Given n output n % 9". – Peter Taylor Aug 5 '19 at 7:46
• @PeterTaylor Ah, now I remember where I've seen it before: here in the sandbox, and you (or someone else) made that same comment. :) – Kevin Cruijssen Aug 5 '19 at 12:24
• Isnt this just a duplicate of codegolf.stackexchange.com/q/1775/87923? – EdgyNerd Aug 6 '19 at 8:19
• @EdgyNerd It's related, but not a dupe. That challenge takes multiple integers as input simultaneously, instead of a single input. And it outputs the amount of iterations for each of those integers to become a single digit, instead of the resulting digit itself. In addition, it has rather cumbersome output-format.. So that challenge would result in 987 2 for input [987]. The core part of both challenges is the same though: continue summing the digits of an integer until a single digit remains. – Kevin Cruijssen Aug 6 '19 at 9:16

Make it improbable... BUT NOT IMPOSSIBLE

You must make a program that outputs truly once in a while. However, making it have output falsy all the time is not acceptable.

Rules

• Standard loopholes are forbidden.
• You may use any of accepted I/O formats.
• Your program must be possible to output a truly value.
• When not outputting a truly value, you may either output a falsy value or not output anything at all.
• You may output two or more values, however if it contains a truly value, then the output is considered truly.
• The probability of outputting a truly value must be at most 1/2.
• Your program must not take/use an input.
• Using non-deterministic but non-random(Such as getting the time) is prohibited. However, if date etc. is used in the builtin random function, it is allowed.
• The program must theoretically always terminate or stop outputting anything.
• You may assume that you have a fast enough computer and large enough memory.
• Your program should not be affected by raising the maximum value of a data type. You may still use unaffected constants.
• Data types must be following its spec: ie. for an unbounded arbituary precision integer type, you may assume that it can go as high as you want(but you are not allowed to increment until an error as in the rule above), but a double-precision floating-point format still has 22-bit fraction and 8-bit exponent.
• Score is calculated as: Pl-1.5l, where P is the probability and l is the byte length.

Example(s)

JavaScript
P=0.1, l=24 => Score=23.534


The lowest score wins!

• So is it acceptable for just a program that always outputs truly? You need to define improbable. (I assume this probability must be at least lest than 1/2.) Providing a few examples will be helpful. So is there only output and no input? In addition, you need an objective winning criterion, which is a criterion that posts for this challenge will need to comply in order for it to be a valid answer. (Usually this criterion is making the source code shortest.) – user85052 Sep 24 '19 at 13:37
• Sorry, I posted this incomplete. – Naruyoko Sep 24 '19 at 16:14
• I don't think your scoring method works particularly well, unless I'm making an error. For any $l > 1$ your score cannot be less than 1. Achieving a score arbitrarily close to 1 is relatively easy. So the only way to beat that is to have a one or zero byte solution. It is easy to make the probability increase exponentially with linear code additions. It might be necessary to penalise length massively, like $P \times e^{l!}$, to avoid similar problems. – FryAmTheEggman Sep 24 '19 at 18:39
• I see. I guess P^l^k is too penalizing but Pk or Pe^k is too forgiving. Pe^l! looks simple enough but is is the middle so it may work. – Naruyoko Sep 24 '19 at 20:11
• The problem with any of scoring methods for this challenge is that it is possible for any increasing computable function f, a program with length l can have P around 1/f(l). The only non-broken formula could be uncomputable, i.e. P/BB(l), where BB is the busy beaver function. – Naruyoko Sep 24 '19 at 20:15

I reverse the source code, you keep the output

Yet another blatant rip-off of a rip-off of a rip-off of a rip-off. Go upvote those!

Your task, if you wish to accept it, is to write a program/function that outputs/returns its own output. The tricky part is that if I reverse your source code, the output must be preserved.

Examples

Let's say your code is ABC and the corresponding output is XYZ. If I run CBA, the output must also be XYZ

• What's to prevent a trivial solution of just 1 in many (many) languages? – AdmBorkBork Sep 25 '19 at 18:30
• Or trivial comment abuse? – S.S. Anne Sep 25 '19 at 20:39
• @JL2210 This works in codegolf.stackexchange.com/questions/193315/… print("ABC")#("ABC")tnirp – gadzooks02 Sep 26 '19 at 15:21
• @AdmBorkBork This works in codegolf.stackexchange.com/questions/193315/… too: 1 is the reverse of 1 – gadzooks02 Sep 26 '19 at 15:22
• And to both of you: why did these not stop that code golf becoming a challenge? – gadzooks02 Sep 26 '19 at 15:23
• I didn't say it couldn't be a challenge. I just wanted to point out that this is trivial in many languages. And for what it's worth, I downvoted the challenge you linked for the same reason. – AdmBorkBork Sep 26 '19 at 15:48
• @gadzooks02 That challenge requires you to reverse the input. The input can be anything in that challenge. – S.S. Anne Sep 26 '19 at 15:49
• @JL2210 Ah yes. Would preserve the input work better? – gadzooks02 Sep 26 '19 at 16:02
• No, then it would be trivial in Bash and BrainFuck and C and, well, you get the point. – S.S. Anne Sep 26 '19 at 16:26
• @JL2210 Yes, OK. Do I need to do something if I've decided against a challenge? Delete the post? – gadzooks02 Sep 26 '19 at 16:29
• No idea. Read over the guidelines, they might help. – S.S. Anne Sep 26 '19 at 16:31

print 1000 digits of $$\\pi\$$ base 3

The question was on hold for "unclear what you're asking". Really? What was the real reason?

No input. We need to compute and print the values of $$\\pi\$$ and Euler constant $$\\gamma\$$
to $$\1000\$$ digits after decimal point
in base $$\3\$$ with digits $$\-1,0,1\$$ represented as -,0,+ respectively.

For $$\\pi\$$ output is likely starts with +0.0++-+++-000-0++-++0+-++++++00--++.
$$\\pi\$$ can be computed as series of $$\\tan^{-1}\$$, $$\\gamma\$$ -- like here, or any other method will do if fast enough to provide needed accuracy for at most $$\60\$$ seconds for both numbers.

Storing or using entire pre-computed values are forbidden.
One may though use wolframalpha regular-base-3 values for checking their output -- for $$\\pi\$$ and $$\\gamma\$$ (hit "More digits" some times to get $$\1000\$$).

Scoring method is code-golf, but TIO should run at most $$\60\$$ seconds.
Good luck. Please fell free to improve this post.

• "Storing or using entire pre-computed values are forbidden" is definitely one source of unclarity. What amount of pre-computation could be done? All but the last digit? All but two? Further there doesn't seem to be any reason to ask for two numbers, nor is there a on-site way to check the results. You shouldn't make your answerers have to go to an external site to verify their submission. – FryAmTheEggman Nov 21 '19 at 19:43

Introduction

As programming languages reproduce are created, documentation is even more important for programmers. Your task is simple: output the esolangs.org documentation for your programming language.

With wikis being wikis, languages are heavily penalized in this challenge for being used often and for being interesting to write about, the goal here is to draw attention to languages that may not get utilized otherwise.

Challenge

For this task, you will need to output the source for the article on esolangs.org for your language, with greater than or equal to 95% accuracy. Your score is your program length in bytes, as in other challenges.

Languages not on this multi-page list of languages as of the time of this posting are ineligible.

Standard loopholes are forbidden.

None

Output

The source (as of this challenge being posted), for the esolangs wiki page for your language, with at least 95% accuracy.

Example

Language: ///

Output:

{{featured language}}
'''///''' (pronounced "slashes") is a minimalist [[Turing-complete]] esoteric programming language, invented by Tanner Swett ([[User:Ihope127]]) in 2006 based on [[wikipedia:sed|the "s/foo/bar/" notation that everybody seemed to be using in IRC]]. The only operation is repeated string substitution, using the syntax <code>/''pattern''/''replacement''/</code>. Despite its extreme simplicity – there isn't even an obvious way to create a loop – it was proved [[Turing-complete]] by [[Ørjan Johansen]] in 2009, who created [[#Bitwise Cyclic Tag interpreter|an interpreter]] for the Turing-complete language [[Bitwise Cyclic Tag]].
...

• -1: Interesting idea, but I don't think it can work as a challenge. I'm not convinced that kolmogorov-complexity-ing a volatile data source is a good idea. What happens if the page is edited two weeks from now? – Beefster Dec 13 '19 at 22:39
• Loophole. I blanked the esolangs.org documentation of my language. Therefore I can output nothing to achieve my goal. – user85052 Dec 18 '19 at 4:07
• @A̲̲ nope, you have to output what it was at the time of posting – iPhoenix Dec 18 '19 at 11:53
• Obviously, you blank the page and then post before it gets fixed. – my pronoun is monicareinstate Dec 19 '19 at 13:55

Background

"The finite element method (FEM), is a numerical method for solving problems of engineering and mathematical physics." -Wikipedia

One of the elementary formulations of fem in structural engineering is the truss. They are very basic, but have a lot of utility.

When one designs a truss, especially in the preliminary stages some assumptions are usually made to simplify the procedure. For instance, members are assumed to carry only tension or compression load. This means that we can only load the truss at the nodals points. Depending on how the connection is designed and detailed, these assumptions can be quite close to how the structure actually will behave in the real world.

So, what's so special about having a member with only axial loading? Well, there's a property of the material itself we can take advantage of. Most materials have a property of 'linear elasticity' when the material is stretched or compressed a very small amount. A material like steel is quite ductile, and so this range of linear elasticiticy is quite large, as compared to something like ceramics. This means if we push or pull on some steel with a small force, it will displace a proportional amount. If we double our applied force, its displacement will double as well. Also if we release our force, the material will go back to its original configuration. So as long as we deform the material elastically, we won't waste any energy deforming it plastically.

If you have ever taken a physics class, you may know that a spring has these exact same properties. Therefore, we can idealize all the members in our truss as just simple springs.

Building up to direct stiffness method

A zero dimensional spring equation looks like this. $$K \cdot u = F$$ This relates the force required to any deformation of the spring. The force and deformation are linearly proportional by $$\K\$$, the spring constant. The constant $$\K\$$ has units of [force/distance] e.g. [pounds/in] or [kilograms/meter]. For example, if $$\K = 50 lb/in\$$, it would take $$\50lb\$$ of force to displace the spring $$\1\$$ inch, and $$\100lb\$$ to displace the spring $$\2\$$ inches. The stiffness in our truss members is similar:

$$K = \frac{EA}{L}$$

$$\E\$$ is Young's Modulus, $$\A\$$ is the cross sectional area, and $$\L\$$ is the length of the bar. The only scary thing here is probably $$\E\$$, but it's not too crazy. It's kind of like stiffness, but it's normalized. Instead of [force/distance] we have [stress/strain]. Stress is like the normalized force, it's the amount of force over the area of the element. Strain is like the normalized displacement, it's calculated by (change in length/original length) or percent elongation.

Let's develop this a bit more and put it in matrix form. This will allow us to relate the force on one side of the bar to force on the other.

$$\frac{EA}{L} \left[\begin{array}{cc} 1 & -1\\ -1 & 1 \\ \end{array}\right] \cdot \left[\begin{array}{c} u_1 \\ u_2 \\ \end{array}\right] = \left[\begin{array}{c} f_1 \\ f_2 \\ \end{array}\right]$$

Now we have our one dimensional spring equation. Instead of a single displacement, we have a displacement vector. We can displace both sides of the spring independently and find what the resultant forces on each side will be.

Examples:

Displace the right node 1 unit to the right $$\frac{EA}{L} \left[\begin{array}{cc} 1 & -1\\ -1 & 1 \\ \end{array}\right] \cdot \left[\begin{array}{c} 0 \\ 1 \\ \end{array}\right] = \left[\begin{array}{c} f_1 \\ f_2 \\ \end{array}\right]\\ f_1 = \frac{-E A}{L}, f_2 = \frac{E A}{L}$$

This makes sense, because if we displace the right side by a unit, we need a force in the equal and opposite direction on the left side to not drag that side along.

Displace both nodes $$\1\$$ unit to the right $$\frac{EA}{L} \left[\begin{array}{cc} 1 & -1\\ -1 & 1 \\ \end{array}\right] \cdot \left[\begin{array}{c} 1 \\ 1 \\ \end{array}\right] = \left[\begin{array}{c} f_1 \\ f_2 \\ \end{array}\right]\\ f_1 = 0, f_2 = 0$$

This makes sense, because if we displace both sides at the same time, the distance between them does not change. It would be as if we just translated the spring across the table and did not strech it. We don't need some force holding it in a deformed configuration.

That's cool, but one dimensional structures are lame. I want a two dimensional structure to build a bridge! Well, it's not that much more difficult. We just need to add a $$\y\$$ degree of freedom (dof) on each side of the spring. We can also couple our $$\x\$$ and $$\y\$$ dofs into one angle from the $$\+x\$$ direction to simplify our matrix. And so with some magic (rotational matrix) we can get the following:

Step 1 - Local Stiffnes Matrix

This is our local stiffness matrix, also known as $$\K^e\$$. It has all the same properties as our one dimensional stiffness matrix, but it takes into account $$\(x,y)\$$ displacements at each side of the spring. This gives us a total of four degrees of freedom.

You may begin to see how powerfull this method can be. We can now iterate through all of our elements and just calculate the angle and length from its nodes. This will give us $$\i\$$ local stiffness matrices, where $$\i\$$ is the number of elements. For example if we have $$\3\$$ elements in our truss, we can calculate our $$\3\$$ local matrices for each element.

Let's go through an example.

If we calcualted the local stiffness matrices for the figure above ($$\EA = 1\$$, $$\L(1,2)=1\$$), you would find: $$\hspace{50pt}\begin{array}{cccc}1 & 2 & 3 & 4\\\end{array} \\ K(1) = \begin{array}{c} 1 \\ 2 \\ 3 \\ 4 \\ \end{array} \left[\begin{array}{cccc} 1 & 0 & -1 & 0\\ 0 & 0 & 0 & 0\\ -1 & 0 & 1 & 0\\ 0 & 0 & 0 & 0\\ \end{array}\right]$$ $$\hspace{50pt}\begin{array}{cccc}3 & 4 & 5 & 6\\\end{array} \\ K(2) = \begin{array}{c} 3 \\ 4 \\ 5 \\ 6 \\ \end{array} \left[\begin{array}{cccc} 0 & 0 & 0 & 0\\ 0 & 1 & 0 & -1\\ 0 & 0 & 0 & 0\\ 0 & -1 & 0 & 1\\ \end{array}\right]$$ $$\hspace{50pt}\begin{array}{cccc}1 & 2 & 5 & 6\\\end{array} \\ K(3) = \begin{array}{c} 1 \\ 2 \\ 5 \\ 6 \\ \end{array} \left[\begin{array}{cccc} 0.64 & 0.48 & -0.64 & -0.48\\ 0.48 & 0.36 & -0.48 & -0.36\\ -0.64 & -0.48 & 0.64 & 0.48\\ -0.48 & -0.36 & 0.48 & 0.36\\ \end{array}\right]$$

Where the numbers outside the array correspond to the global matrix indicies.

Step 2 - Assemble local matrices into the global matrix

These local matricies are uncoupled, and so they don't really tell us much about the global system of the truss, or how to solve for the displacements with given forces. However, we can do something called matrix assembly to put them all into one big global stiffness matrix. This will couple all of our local element equations so we can solve our system of equations.

We do this by matching the local degrees of freedom to our global degrees of freedom, then add our local to our global matrix.

Since our global truss has 3 nodes and each node has $$\2\$$ dofs $$\(x,y)\$$, our global matricies are of size 6. $$\K \in \mathbb R^{6 \times 6}, F \in \mathbb R^{6 \times 1}, u \in \mathbb R^{6 \times 1}\$$. If we layed out the dof number for each row/column of our stiffness matrix we would get the following:

$$\hspace{35pt}\begin{array}{cccccc}1 & 2 & 3 & 4 & 5 & 6\\\end{array} \\ K = \begin{array}{c} 1 \\ 2 \\ 3 \\ 4 \\ 5 \\ 6 \\ \end{array} \left[\begin{array}{cccccc} 0 & 0 & 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 0 & 0 & 0\\ \end{array}\right]$$

From step 1, the global dofs of $$\k(1)\$$ were $$\1,2,3,4\$$. This means we just add them index by index into our global stiffness matrix.

$$\hspace{35pt}\begin{array}{cccc}1 & 2 & 3 & 4\\\end{array} \\ k(1) = \begin{array}{c} 1 \\ 2 \\ 3 \\ 4 \\ \end{array} \left[\begin{array}{cccc} k_{11} & k_{12} & k_{13} & k_{14}\\ k_{21} & k_{22} & k_{23} & k_{24}\\ k_{31} & k_{32} & k_{33} & k_{34}\\ k_{41} & k_{42} & k_{43} & k_{44}\\ \end{array}\right]$$

If we match up the indicies, we can just add: $$K_{11} += k_{11}\\ K_{12} += k_{12}\\ K_{13} += k_{13}\\ K_{14} += k_{14}\\ K_{21} += k_{21}\\ ...$$

We can see if we do this for all three elements, we can match up where they will go in the global matrix with colors. This is shown in the figure below.

Step 3 - Add bounds on the stiffness matrix, and modify the force vector

We are almost done! But there is one final important step. If we were given an arbitrary force vector and tried to find the displacements, our truss would just fly away to infinity. This is because there are no boundary conditions! There is nothing yet holding on to it, resisting the forces. But guess what? There's another neat trick we can use. This will keep everything in matrix form and give us the answers we want when we solve our system of equations.

All we do is remove the influence of the node on the force vector. For this example, we will assume the constraint on dof1 is set to $$\g\$$.

For the general case, we just set $$\dof1 = g\$$ in the force vector, and subtract g* the column of $$\K\$$ with dof1 = 0. If $$\g=0\$$, we just need to set $$\dof1 = 0\$$ in the force vector.

$$F = \left[\begin{array}{c} F_1\\ F_2\\ F_3\\ \vdots\\ F_n\\ \end{array}\right] \Rightarrow \left[\begin{array}{c} g\\ F_2\\ F_3\\ \vdots\\ F_n\\ \end{array}\right] - g \left[\begin{array}{c} 0\\ K_{21}\\ K_{31}\\ \vdots\\ K_{n1}\\ \end{array}\right]$$

Then we just restrain our stiffness matrix. This can be done by zeroing out the row and column of $$\dof1\$$, then setting $$\(dof1,dof1)=1\$$ as shown below.

$$K = \left[\begin{array}{cccc} K_{11} & K_{12} & \cdots & K_{1n}\\ K_{21} & K_{22} & \cdots & K_{2n}\\ \vdots & \vdots & \ddots & \vdots\\ K_{n1} & K_{n2} & \cdots & K_{nn}\\ \end{array}\right] \Rightarrow \left[\begin{array}{cccc} 1 & 0 & \cdots & 0\\ 0 & K_{22} & \cdots & K_{2n}\\ \vdots & \vdots & \ddots & \vdots\\ 0 & K_{n2} & \cdots & K_{nn}\\ \end{array}\right]$$

Step 4 - Solve with linear algebra

Now we are finally back to our equation of a spring. However, in this case each variable below is an array or vector of size $$\n\$$, where $$\n\$$ is the number of $$\nodes \times 2\$$.

$$\mathbf{K} \cdot \mathbf{u} = \mathbf{F}$$

We can simply solve this system of equations by taking the inverse of the stiffness matrix. This gives us:

$$\mathbf{u} = \mathbf{K}^{-1} \cdot \mathbf{F}$$

This can be easily solved by a computer. For example Python:

    u = np.linalg.solve(K, F)


Rules

• Input data type can for the most part be changed for your needs. However, it should be human-readable, or at least reasonable to be able to change the input for a new structure easily.

Example input

E = .
A = .
nodes = [., ., ...]
elements = [., ., ...]
forces = [., ., ...]
bounds = [., ., ...]


Example output

[., ., ...]

• Output can be in any form, as long as it's in order of dof.
• Inbuilt FEM functions not allowed. You must construct and assemble your matrices yourself. Inbuilt linear algebra is fine.

Test Cases

From UNM example in references:

E = 29500
A = 1
nodes = [[0,0],[40,0],[40,30],[0,30]]
elements = [[1,2],[2,3],[1,3],[3,4]]
forces = [[0,0],[20,0],[0,-25],[0,0]]
bounds = [[0,0],[None,0],[None,None],[0,0]]


Output:

[0.0 0.0 0.027 0.0 0.006 -0.022 0.0 0.0]


Large Truss Input:

E = 29000
A = 25
nodes = [[0,0],[100,0],[200,0],[300,0],[0,100],[100,100],[200,100],[300,100],[400,100]]
elements = [[1,2],[1,5],[1,6],[2,3],[2,6],[2,7],[3,4],[3,7],[3,8],[4,8],[4,9],[5,6],[6,7],[7,8],[8,9]]
forces = [[0,-10],[0,-10],[0,-10],[0,-10],[0,0],[0,0],[0,0],[0,0],[0,-10]]
bounds = [[0,0],[None,None],[None,None],[None,None],[-0.01,0],[None,None],[None,None],[None,None],[None,None]]


Output:

[ 0.     0.    -0.008 -0.025 -0.012 -0.061 -0.014 -0.1   -0.01   0.     0.004 -0.019  0.012 -0.057  0.016 -0.098  0.018 -0.136]


Here is what the geometry and displacement looks like for the test cases so you can visualize it.

References

Here are some references that may be useful if you are looking for some more in-depth information.

http://www.unm.edu/~bgreen/ME360/Finite%20Element%20Truss.pdf

https://engineering.purdue.edu/~aprakas/CE474/CE474-Ch5-StiffnessMethod.pdf

http://people.duke.edu/~hpgavin/cee421/truss-method.pdf

http://ocw.ump.edu.my/pluginfile.php/9806/mod_resource/content/2/7_Plane_Truss_Example.pdf

https://nptel.ac.in/content/storage2/courses/105105109/pdf/m4l24.pdf

And lastly, here is some working python 3 code that I wrote. It should lay out all the steps cleanly.

import numpy as np
from math import sqrt,sin,cos,acos

def ex_unm():
"""Example - Verification from UNM"""
print("Example UNM")
# Material Properties
E = 29500 # (units = ksi)
A = 1 # (units = in^2)
# Node locations (units = in)
nodes = {1:(0,0), 2:(40,0), 3:(40,30), 4:(0,30)}
# Element connections
elements = {1:(1,2), 2:(3,2), 3:(1,3), 4:(4,3)}
# Nodal forces (units = kips)
forces = {2:(20,0), 3:(0,-25)}
# Nodal Boundaries (units = in)
bounds = {1:{'x':0,'y':0},2:{'y':0},4:{'x':0,'y':0}}
# Run Analysis
displacements = analyze(E,A,nodes,elements,forces,bounds)
for i,disp in enumerate(displacements):
print("Node {},{}: {}".format(int(i/2)+1,['x','y'][i%2],round(disp,5)))

plot_truss(nodes, elements, displacements, 200)

def ex_big_boi():
"""Example - Large Truss"""
print("Example BIG BOI")
# Material Properties
E = 29000 # (units = ksi)
A = 25 # (units = in^2)
# Node locations (units = in)
nodes = {1:(0,0), 2:(100,0), 3:(200,0), 4:(300,0),
5:(0,100), 6:(100,100), 7:(200,100), 8:(300,100), 9:(400,100)}
# Element connections
elements = {1:(1,2), 2:(1,5), 3:(1,6),
4:(2,3), 5:(2,6), 6:(2,7),
7:(3,4), 8:(3,7), 9:(3,8),
10:(4,8), 11:(4,9),
12:(5,6), 13:(6,7), 14:(7,8), 15:(8,9)}
# Nodal forces (units = kips)
forces = {1:(0,-10), 2:(0,-10), 3:(0,-10), 4:(0,-10), 9:(0,-10)}
# Nodal Boundaries (units = in)
bounds = {1:{'x':0,'y':0}, 5:{'x':-0.01,'y':0}}
#bounds = {1:{'x':0,'y':0}, 5:{'x':0,'y':0}}
# Run Analysis
displacements = analyze(E,A,nodes,elements,forces,bounds)
for i,disp in enumerate(displacements):
print("Node {},{}: {}".format(int(i/2)+1,['x','y'][i%2],round(disp,5)))

plot_truss(nodes, elements, displacements, 500)

"""Visualization, not really needed but may be good to see"""
import matplotlib.pyplot as plt

def plot_truss(nodes, elements, u, scale):
"""A very simple plot to show geometry and displacements of nodes"""
x = [coords[0] for node,coords in nodes.items()]
y = [coords[1] for node,coords in nodes.items()]
ux = x + u[::2] * scale
uy = y + u[1::2]* scale

fig,ax = plt.subplots()
# Plot original Points
ax.plot(x,y,'o',color=(0.5,0.5,0.5))
# Plot original Elements (Theres probably a better way to do this)
for element,eleNodes in elements.items():
ex = [x[i-1] for i in eleNodes]
ey = [y[i-1] for i in eleNodes]
ax.plot(ex,ey,color=(0.5,0.5,0.5))

# Plot displaced Points
ax.plot(ux,uy,'o',color=(0,0,1))
# Plot displaced Elements (Theres probably a better way to do this)
for element,eleNodes in elements.items():
ex = [ux[i-1] for i in eleNodes]
ey = [uy[i-1] for i in eleNodes]
ax.plot(ex,ey,color=(0,0,1))

# Make plot have same xy scale
ax.axis('equal')
#fig.tight_layout()
ax.set_title("Truss Geometry and Displacement, Scale = {}".format(scale))

def analyze(E, A, nodes, elements, forces, bounds):
"""Analyze a given system and return the nodal displacements"""
# Assemble global matricies
K = gen_global_K(E,A,nodes,elements)
F = gen_global_F(nodes,forces)
#F = restrain_stiffness(K, F, bounds)
restrain_stiffness(K, F, bounds)
# Solve K*u=F -> u=K^-1*F
u = np.linalg.solve(K, F)
# return the nodal displacements
return u

def gen_global_K(E, A, nodes, elements):
"""Generate the Global stiffness Matrix"""
# Initialize Global Stiffness Matrix
size = len(nodes)*2
K = np.zeros([size,size])

# Itterate through each element and add its local stiffness to global stiffness
for element,(node_1,node_2) in elements.items():
node_1_xy = nodes[node_1]
node_2_xy = nodes[node_2]
# Element length
L = sqrt((node_2_xy[0]-node_1_xy[0])**2 + (node_2_xy[1]-node_1_xy[1])**2)
# Get this element's local stiffness roated into global plane
K_local = (E*A/L) * gen_local_K(node_1_xy, node_2_xy)
# Assemble local matrix into global
assemble(K, K_local, node_1, node_2)
return K

def gen_local_K(n1, n2):
"""Create a local stiffness matrix from two nodes' angle"""
angle = gen_angle(n1,n2)
c  = cos(angle)**2
s  = sin(angle)**2
cs = cos(angle) * sin(angle)
# Create the local K matrix
K_local = np.array([[ c , cs,-c ,-cs],
[ cs, s ,-cs,-s ],
[-c ,-cs, c , cs],
[-cs,-s , cs, s ]])
return K_local

def gen_angle(n1, n2):
"""Find angle between two nodes and +x axis"""
v1 = np.array([n2[0]-n1[0],n2[1]-n1[1]])
v2 = np.array([1,0])
return acos(np.dot(v1,v2) / (np.linalg.norm(v1) * np.linalg.norm(v2)))

def assemble(K, K_local, n1, n2):
"""Assemble a local element stiffness matrix into the global stiffness"""
# Degrees of freedom of our local element
dofs = [2*(n1-1), 2*(n1-1)+1, 2*(n2-1), 2*(n2-1)+1]
# Go element by element to add matrix
for i_local,i_global in enumerate(dofs):
for j_local,j_global in enumerate(dofs):
K[i_global,j_global] += K_local[i_local,j_local]

def gen_global_F(nodes, forces):
"""Generate the global force vector"""
F = np.zeros(2*len(nodes))
for node,(f_x,f_y) in forces.items():
dof = 2*(node-1)
F[dof] = f_x
F[dof+1] = f_y
return F

def restrain_stiffness(K, F, bounds):
"""Use a given displacement bound to modify matricies"""
dir = {'x':0, 'y':1}
for node,this_bound in bounds.items():
for coord,disp in this_bound.items():
# Get what dof the bound is
dof = (node-1)*2 + dir[coord]

"""Move the fixed displacement over to F (since it's constant)"""
# Get displaced F by reducing by given displacement * stiffness column
# Must use -= to ensure python evaluates in-place
#   We don't need to return the array if it's passed by reference
F -= disp * K[:,n]
# Set the Force value at that dof to the given displacment
F[n] = disp
# Clear stiffness matrix dof row & col

"""Zero out row and col of dof, then make [n,n] = 1"""
for i in range(np.size(K,0)):
K[n,i] = 0
K[i,n] = 0
K[n,n] = 1

if __name__ == "__main__":
# Set print options if you want to print an array nicely (easier for debug)
np.set_printoptions(precision=2, suppress=True, linewidth=np.inf)
ex_unm()
ex_big_boi()

plt.show()


Good Luck!

• Really cool introduction to FEM! I allowed myself to make some corrections and convert some more equations to mathjax, I hope you are ok with that. Some points I noticed that I would suggest improving: If you introduce a new variable, always describe what it is: It doesn't seem clear from the start what $u$ is (displacement?) or how $\beta$ is defined. Then I'd also try to make the indexing consistent: I'd always use the indices like $K_i$ insetad of $K(i)$. – flawr Dec 28 '19 at 14:32
• Similarly I'd avoid reusing the same symbol: For example for $k(1)$ you reuse the symbol $k$ for its entries, so I'd recommend rewriting it as maybe $\vec k_1$. – flawr Dec 28 '19 at 14:35
• You talk about the degrees of freedom "dofs", aren't these just the entries of $u$? – flawr Dec 28 '19 at 14:37
• And what type of challenge is it anyway? code-golf or something else? – flawr Dec 28 '19 at 14:37
• Thanks! Yea, the u vector is the displacement of each node. It is common to have it in the form {node1 x, node1 y, node2 x, node2 y.,,,}. Each element of the vector would be a degree of freedom, and together they would be the degrees of freedom of the entire structure. However, the u vector is not the actual degrees of freedom, it is just the displacements at each degree of freedom. For instance, the force vector would have a force at each degree of freedom. I think it wold be standard code-colf, least bytes wins, however I'm not sure if there's a better challenge it should go into. – WretchedLout Dec 29 '19 at 4:21

101 Hello Worlds

I have a project where I'm trying to collect 101 versions of "Hello, World" using obscure and over-engineered approaches in JavaScript/Node.js:

https://github.com/georgemandis/101-hello-worlds

We're up to 38 so far and I've really enjoyed the community contributions.

I recognize the way this is phrased at the moment isn't compatible with the way Code Golf is setup, but I feel like there could be a large overlap with people who might be interested and this community.

Does this seem like something that would be welcome here? Would others have suggestions for how I might re-word this to create a suitable entry for Code Golf?

If it's not suitable or welcome here I respect being downvoted into oblivion and can remove the answer.

Thanks!

• Thanks for using the Sandbox. The answer is that no, this isn't really suited to the Code Golf site. The closest winning criterion to use would be popularity-contest, but that was retired a while ago, since it wasn't really objective. If you want inspiration though, you can look at the hello-world tag, which has a lot of interesting restrictions on hello world programs. For example, there's no repetition, radiation-hardened, polyglots, palindromes etc. – Jo King Feb 11 at 4:52
• Thanks @JoKing. I'll take a look at that tag. I think I'll add a tag to it in my project's README as well to give other people inspiration. – George Mandis Feb 11 at 14:28

Hello, World, but looong

I couldn't find out that this challenge exists

If this challenge exists, let me know

Write a simple Hello, World! program.

The winner is the person who has the longest code.

However, any subsequence except itself cannot be the answer.

Input

You can have input in which way.

Output

Hello, World!

• – Adám Feb 13 at 13:07

Check if There is a Valid Path in a Grid

Given a m x n grid. Each cell of the grid represents a street. The street of $$\grid[i][j]\$$ can be:

• 1 which means a street connecting the left cell and the right cell.
• 2 which means a street connecting the upper cell and the lower cell.
• 3 which means a street connecting the left cell and the lower cell.
• 4 which means a street connecting the right cell and the lower cell.
• 5 which means a street connecting the left cell and the upper cell.
• 6 which means a street connecting the right cell and the upper cell.

You will initially start at the street of the upper-left cell $$\(0,0)\$$. A valid path in the grid is a path that starts from the upper left cell $$\(0,0)\$$ and ends at the bottom-right cell $$\(m - 1, n - 1)\$$. The path should only follow the streets.

Notice that you are not allowed to change any street.

Return true if there is a valid path in the grid or false otherwise

Test Case 1:

Input: grid = [[2,4,3],[6,5,2]]
Output: true
Explanation: As shown you can start at cell (0, 0) and visit all the cells of the
grid to reach (m - 1, n - 1).


Test Case 2:

Input: grid = [[1,2,1],[1,2,1]]
Output: false
Explanation: As shown you the street at cell (0, 0) is not connected with any street of
any other cell and you will get stuck at cell (0, 0)


Testcase 3:

Input: grid = [[1,1,2]]
Output: false
Explanation: You will get stuck at cell (0, 1) and you cannot reach cell (0, 2).


Testcase 4:

Input: grid = [[1,1,1,1,1,1,3]]
Output: true


Test Case 5:

Input: grid = [[2],[2],[2],[2],[2],[2],[6]]
Output: true


This is code-golf so shortest submission in bytes wins! If you liked this challenge, consider upvoting it... And happy golfing!

• May I use a different numbering/encoding to encode the six tiles? One example could be using 3, 5, 6, 9, 10, 12 to utilize bitwise ops, or a 4-element array per tile e.g. [0, 0, 1, 1], [0, 1, 0, 1], etc. – Bubbler Mar 24 at 8:13
• You might want to clarify that the path is not required to cover every single cell (or the opposite). Also, are the top left and bottom right corners guaranteed to have a single side connected to the outside, e.g. 4 or 5 will never appear at the top left? – Bubbler Mar 24 at 8:19
• Nothing to add to Bubbler's comments other than maybe make the images smaller and/or replace them with ASCII or Unicode diagrams. (imgur is blocked by some networks). – Adám Mar 24 at 15:40
• This also has the issue of being a LeetCode problem, which you presumably don't have permission to post here. – xnor Mar 25 at 0:56

Longest happy prefix

A prefix of a string is a happy prefix if it's also a suffix of that string, but not if it's the entire string. This means that the string both begins and ends with it.

Given a non-empty string s, return the longest happy prefix of s. Note that this can be the empty string.

Test Cases:

Case 1:

Input: s = "level"
Output: "l"

Explanation: s contains 4 prefix excluding itself ("l", "le", "lev", "leve"), and suffix
("l", "el", "vel", "evel"). The largest prefix which is also suffix is given by "l".


Case 2

Input: s = "ababab"
Output: "abab"

Explanation: "abab" is the largest prefix which is also suffix.
They can overlap in the original string.


Case 3:

Input: s = "a"
Output: ""


This is code-golf so shortest submission in bytes wins! If you liked this challenge, consider upvoting it... And happy golfing!

• Would answering with the length not be reasonable? – Adám Mar 24 at 9:19
• What else Should I ask to return?? – Pluviophile Mar 24 at 15:31
• "Given a string s. Return the longest happy prefix of s ." → "Given a string s. Return the longest happy prefix of s or its length." – Adám Mar 24 at 15:32
• If you remove "non-empty" you can also remove "Return an empty string if no such prefix exists." – Adám Mar 24 at 15:35
• I tried to clear up the wording a bit. – xnor Mar 25 at 0:52
• Wait, this is also a LeetCode problem! Are all of your challenges really copy-pasted from LeetCode and similar sites? That's not OK to do, unless you've been somehow given explicit permission to post them here. – xnor Mar 25 at 1:07

A malbolge interpreter

The challenge today is to write a Malbolge interpreter.

Specification

Malbolge

I hereby relenquish any and all copyright on this language,
documentation, and interpreter; Malbolge is officially public domain.

------------------------------------------------------------------------

Malbolge

Introduction
^^^^^^^^^^^^

It was noticed that, in the field of esoteric programming languages,
there was a particular and surprising void: no programming language
known to the author was specifically designed to be difficult to program
in.

Certainly, there were languages which were difficult to write in, and
far more were difficult to read (see: Befunge, False, TWDL, RUBE...).
But even INTERCAL and BrainF***, the two kings of mental torment, were
designed with other goals: INTERCAL to have nothing in common with any
major programming language, and BrainF*** to be a very tiny, yet still
Turing-complete, language.

INTERCAL's constructs are certainly tortuous, but they are all too
flexible; you can, for instance, quite easily assign any number to a
variable with a single statement.

BrainF*** is lacking the flexibility which is INTERCAL's major weakness,
but it fails in that its constructs are far, far too intuitive.
Certainly, there are only 8 instructions, none of which take any
arguments--but it is quite easy to determine how to use those
instructions.  Subtract 8 from the current number?  With a simple
'--------' you are done!  This kind of simple answer was unacceptable to
the author.

Hence the author created Malbolge.  It borrows from machine, BrainF***,
and tri-INTERCAL, but put together in a unique way.  It was designed to
be difficult to use, and so it is.  It is designed to be
incomprehensible, and so it is.

So far, no Malbolge programs have been written.  Thus, we cannot give an
example.

"Malbolge" is the name of Dante's Eighth Circle of Hell, in which
practitioners of deception (seducers, flatterers, simonists, thieves,
hypocrites, and so on) spend eternity.

Environment
^^^^^^^^^^^

In many languages, the environment is easy to understand.  In Malbolge,
it is best to understand the runtime environment before you ever see a
command.

The environment is, roughly, that of a primitive trinary CPU.  Both code
and data share the same space (the machine's memory segment), and there
are three registers.  Machine words are ten trits (trinary digits) wide,
giving a maximum possible value of 59048 (all numbers are unsigned).
Memory space is exactly 59049 words long.

The three registers are A, C, and D.  A is the accumulator, used for
data manipulation.  A is implicitly set to the value written by all
write operations on memory.  (Standard I/O, a distinctly non-chip-level
feature, is done directly with the A register.)

C is the code pointer.  It is automatically incremented after each
instruction, and points the instruction being executed.

D is the data pointer.  It, too, is automatically incremented after each
instruction, but the location it points to is used for the data
manipulation commands.

All registers begin with the value 0.

When the interpreter loads the program, it ignores all whitespace.  If
it encounters anything that is not one of an instruction and is not
whitespace, it will give an error, otherwise it loads the file, one non-
whitespace character per cell, into memory.  Cells which are not
initialized are set by performing op on the previous two cells
repetitively.

Commands
^^^^^^^^

When the interpreter tries to execute a program, it first checks to
see if the current instruction is a graphical ASCII character (33
through 126).  If it is, it subtracts 33 from it, adds C to it, mods it
by 94, then uses the result as an index into the following table of 94
characters:

+b(29e*j1VMEKLyC})8&m#~W>qxdRp0wkrUo[D7,XTcA"lI
.v%{gJh4G\-=O@5_3i<?Z';FNQuY]szf$!BS/|t:Pn6^Ha It then checks it against the characters listed below, and performs an appropriate action. If the result is not one of the characters listed below, it is treated as a nop. If the original character is not graphic ASCII, the program is immediately ended. When the interpreter parses the input file, it checks each non- whitespace character with the process above. If any result is not one of the eight characters below, the file will be rejected. After the instruction is executed, 33 is subtracted from the instruction at C, and the result is used as an index in the table below. The new character is then placed at C, and then C is incremented. 5z]&gqtyfr$(we4{WP)H-Zn,[%\3dL+Q;>U!pJS72FhOA1C
B6v^=I_0/8|jsb9m<.TVacuY*MK'X~xDl}REokN:#?G"i@

j
sets the data pointer to the value in the cell pointed to by the
current data pointer.

i
sets the code pointer to the value in the cell pointed to be the
current data pointer.

*
rotates the trinary value of the cell pointed to by D to the right 1.
The least significant trit becomes the most significant trit, and all
others move one position to the left.

p
performs a tritwise "op" on the value pointed to by D with the
contents of A.  The op (don't look for pattern, it's not there) is:

| A trit:
________|_0__1__2_
0 | 1  0  0
*D  1 | 1  0  2
trit 2 | 2  2  1

Di-trits:
00 01 02 10 11 12 20 21 22

00  04 03 03 01 00 00 01 00 00
01  04 03 05 01 00 02 01 00 02
02  05 05 04 02 02 01 02 02 01
10  04 03 03 01 00 00 07 06 06
11  04 03 05 01 00 02 07 06 08
12  05 05 04 02 02 01 08 08 07
20  07 06 06 07 06 06 04 03 03
21  07 06 08 07 06 08 04 03 05
22  08 08 07 08 08 07 05 05 04

<
reads an ASCII value from the stdin and converts it to Trinary, then
stores it in A.  10 (line feed) is considered 'newline', and
2222222222t (59048 dec.) is EOF.

/
converts the value in A to ASCII and writes it to stdout.  Writing
10 is a newline.

v
indicates a full stop for the machine.

o
does nothing, except increment C and D, as all other instructions do.

Turing-Completeness
^^^^^^^^^^^^^^^^^^^

Though I have not proven it, I _think_ Malbolge to be Turing-complete.
To be Turing-complete, there must be some data construct which can be
used to do any mathematical calculation.  I believe that using *p in
various clever ways on the tritwords can fulfill this requirement.

Turing-completeness also requires three code constructs: sequential
execution (which Malbolge obviously has), repetition (provided by the
i and, indirectly, j instructions), and conditional-execution (provided,
I believe, by self-modifying code and altering i destinations).

I do have my doubts, particularly about data constructs, but I *think*
this works...

Appendix: Trinary Conversion Table
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Trinary to ASCII to decimal to hex table, provided, strangely enough,
for the convenience of Malbolge programmers.

00000 NUL 000 00    01012   032 20    02101 @ 064 40    10120  096 60
00001 SOH 001 01    01020 ! 033 21    02102 A 065 41    10121 a 097 61
00002 STX 002 02    01021 " 034 22    02110 B 066 42    10122 b 098 62
00010 ETX 003 03    01022 # 035 23    02111 C 067 43    10200 c 099 63
00011 EOT 004 04    01100 $036 24 02112 D 068 44 10201 d 100 64 00012 ENQ 005 05 01101 % 037 25 02120 E 069 45 10202 e 101 65 00020 ACK 006 06 01102 & 038 26 02121 F 070 46 10210 f 102 66 00021 BEL 007 07 01110 ' 039 27 02122 G 071 47 10211 g 103 67 00022 BS 008 08 01111 ( 040 28 02200 H 072 48 10212 h 104 68 00100 HT 009 09 01112 ) 041 29 02201 I 073 49 10220 i 105 69 00101 LF 010 0a 01120 * 042 2a 02202 J 074 4a 10221 j 106 6a 00102 VT 011 0b 01121 + 043 2b 02210 K 075 4b 10222 k 107 6b 00110 FF 012 0c 01122 , 044 2c 02211 L 076 4c 11000 l 108 6c 00111 CR 013 0d 01200 - 045 2d 02212 M 077 4d 11001 m 109 6d 00112 SO 014 0e 01201 . 046 2e 02220 N 078 4e 11002 n 110 6e 00120 SI 015 0f 01202 / 047 2f 02221 O 079 4f 11010 o 111 6f 00121 DLE 016 10 01210 0 048 30 02222 P 080 50 11011 p 112 70 00122 DC1 017 11 01211 1 049 31 10000 Q 081 51 11012 q 113 71 00200 DC2 018 12 01212 2 050 32 10001 R 082 52 11020 r 114 72 00201 DC3 019 13 01220 3 051 33 10002 S 083 53 11021 s 115 73 00202 DC4 020 14 01221 4 052 34 10010 T 084 54 11022 t 116 74 00210 NAK 021 15 01222 5 053 35 10011 U 085 55 11100 u 117 75 00211 SYN 022 16 02000 6 054 36 10012 V 086 56 11101 v 118 76 00212 ETB 023 17 02001 7 055 37 10020 W 087 57 11102 w 119 77 00220 CAN 024 18 02002 8 056 38 10021 X 088 58 11110 x 120 78 00221 EM 025 19 02010 9 057 39 10022 Y 089 59 11111 y 121 79 00222 SUB 026 1a 02011 : 058 3a 10100 Z 090 5a 11112 z 122 7a 01000 ESC 027 1b 02012 ; 059 3b 10101 [ 091 5b 11120 { 123 7b 01001 FS 028 1c 02020 < 060 3c 10102 \ 092 5c 11121 | 124 7c 01002 GS 029 1d 02021 = 061 3d 10110 ] 093 5d 11122 } 125 7d 01010 RS 030 1e 02022 > 062 3e 10111 ^ 094 5e 11200 ~ 126 7e 01011 US 031 1f 02100 ? 063 3f 10112 _ 095 5f 11202 128 80 12221 160 a0 21010 192 c0 22022 224 e0 11210 129 81 12222 161 a1 21011 193 c1 22100 225 e1 11211 130 82 20000 162 a2 21012 194 c2 22101 226 e2 11212 131 83 20001 163 a3 21020 195 c3 22102 227 e3 11220 132 84 20002 164 a4 21021 196 c4 22110 228 e4 11221 133 85 20010 165 a5 21022 197 c5 22111 229 e5 11222 134 86 20011 166 a6 21100 198 c6 22112 230 e6 12000 135 87 20012 167 a7 21101 199 c7 22120 231 e7 12001 136 88 20020 168 a8 21102 200 c8 22121 232 e8 12002 137 89 20021 169 a9 21110 201 c9 22122 233 e9 12010 138 8a 20022 170 aa 21111 202 ca 22200 234 ea 12011 139 8b 20100 171 ab 21112 203 cb 22201 235 eb 12012 140 8c 20101 172 ac 21120 204 cc 22202 236 ec 12020 141 8d 20102 173 ad 21121 205 cd 22210 237 ed 12021 142 8e 20110 174 ae 21122 206 ce 22211 238 ee 12022 143 8f 20111 175 af 21200 207 cf 22212 239 ef 12100 144 90 20112 176 b0 21201 208 d0 22220 240 f0 12101 145 91 20120 177 b1 21202 209 d1 22221 241 f1 12102 146 92 20121 178 b2 21210 210 d2 22222 242 f2 12110 147 93 20122 179 b3 21211 211 d3 12111 148 94 20200 180 b4 21212 212 d4 12112 149 95 20201 181 b5 21220 213 d5 12120 150 96 20202 182 b6 21221 214 d6 12121 151 97 20210 183 b7 21222 215 d7 12122 152 98 20211 184 b8 22000 216 d8 12200 153 99 20212 185 b9 22001 217 d9 12201 154 9a 20220 186 ba 22002 218 da 12202 155 9b 20221 187 bb 22010 219 db 12210 156 9c 20222 188 bc 22011 220 dc 12211 157 9d 21000 189 bd 22012 221 dd 12212 158 9e 21001 190 be 22020 222 de 12220 159 9f 21002 191 bf 22021 223 df  Notes Note that the original specification has one quirk: after encountering an illegal instruction, the interpreter hangs. You may choose which behaviour do you want to implement (hang or exit). I/O rules The program or function has to take input in any reasonable way (for the program), and somehow supply the input and output features to the malbolge program (either by return value / parameter, tty or a file). Sandbox stuff note: I'm a bit unsure about the scoring criterion: would popularity-contest be good? I'm mostly looking for creative answers • add interpreter ? – Wezl Apr 30 at 22:00 • I think popularity-contest would be adding Do X creatively to an already relatively non-interesting challenge [unless if you somehow managed to create a Malbolge self-interpreter and that is the trick you're planning to use to win your own competition with it :) ] – my pronoun is monicareinstate May 1 at 2:15 • hmm right; I'm not planning on submitting a malbolge interpreter on malbolge :P, I'd like to see what people can think of. Also I've been thinking about fastest-code contest that would possibly allow me to switch my tolling a bit :P – Krzysztof Szewczyk May 1 at 10:54 • I'd probably participate if this was [fastest-code], but I doubt there are enough interesting optimizations here. – my pronoun is monicareinstate May 2 at 3:26 • there is a lot of room for optimization, you just need to investigate the challenge a little bit further – Krzysztof Szewczyk May 2 at 17:46 Print all sequenced variants of the SARS-CoV-2 (COVID-19) genome in FASTA format https://www.ncbi.nlm.nih.gov/genbank/sars-cov-2-seqs/ The FASTA format has the name of the sequence data following a >, a newline, 60 characters of As, Ts, Cs, and Gs, a newline, 60 characters of As, Ts, Cs, and Gs, and so on. You need only print the name of the, not the location it came from. For example: >XX-NNNNNN.N GENOMIC DATA GOES HERE >XX-NNNNNN.N MORE GENOMIC DATA GOES HERE  • I can't imagine what good does requiring newlines every 60 characters do to the challenge. That site also has very many files linked, and you have not specified which ones we need to use, nor you provided us with the expected output (a plain link to a random website where we have to scrape and parse several thousands of files you haven't told us about is not enough). Since there are thousands of them, I strongly suspect suspect that zpaq will win this time. – my pronoun is monicareinstate Jun 14 at 8:13 Code-challenge: Guess my number The challenge You have a number from 1 to 10 in mind, and your program should ask questions to find out which number. These questions can be any questions, the program only has to find out the number as fast as possible. Your program should ask a question, such as "Is the number a prime?", and the user must answer either y or n (yes or no). Ask questions until you know the number. The scoring To calculate the score, you need to take the sum of the question count for each number. For example, if you need 1 question to find the number 1, 2 questions to find the number 2, and so on, the score is 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10, so the score is 55. Important note: the question count for a specific number must always be the same. For example, if you need 4 questions to find out the number 10, then you have to ask always 4 questions to find out the number 10, otherwise it is impossible to calculate the score. • boooring. The Huffman tree for a uniform set is any perfectly balanced tree. The question asks us to perform a binary search on the usr device. Is the number greater than 5? Is the number greater than 2? Is the number greater than 1? Hey' I think it's 1. – John Dvorak Jan 2 '14 at 11:49 • Maybe if this were a pop-contest and the goal was to make the most original set of questions while still keeping the score at its theoretical minimum. – John Dvorak Jan 3 '14 at 5:28 Bovine Ignorance I'm curious about code which still works after being mangled by figlet, toilet, cowsay et al, but I'm not sure whether this in any way sane. What I'm toying with is a challenge in which a participant may submit any program in any language. It should be possible to use this program's source code as input to cowsay or whatever, and the result should be another valid program in any language, which still does a similar thing. For instance, the following bf program prints Hello world! with no newline: +++++ +++++ [ > +++++ ++ > +++++ +++++ > +++ > + <<<< - ] > ++ . > + . +++++ ++ . . +++ . > ++ . << +++++ +++++ +++++ . > . +++ . ----- - . ----- --- . > + . +++++++++++++++++++++++++++++++++++++++++  Running cat ./prog.bf | cowsay -e .. -T$'>.' yields the following output:

 _________________________________________
/ +++++ +++++ [ > +++++ ++ > +++++ +++++  \
| > +++ > + <<<< - ] > ++ . > + . +++++   |
| ++ . . +++ . > ++ . << +++++ +++++      |
| +++++ . > . +++ . ----- - . ----- --- . |
| > + .                                   |
| +++++++++++++++++++++++++++++++++++++++ |
\ ++                                      /
-----------------------------------------
\   ^__^
\  (..)\_______
(__)\       )\/\
>. ||----w |
||     ||


Which is itself a valid bf program which prints Hello world!!!, followed by a newline.

The problem with using bf here is that it ignores most of the cow, making this a bit too easy. The problem with using any other language is that it doesn't ignore most of the cow, making this far too difficult. Is there a sensible middle ground I could pick for this? I don't think it's impossible, I'm fairly sure you can exploit cowsay's behavior on one-liners to produce valid svgs, but I'm not sure how best to pose this challenge. Any ideas?

• I could not think of any language that falls in the middle ground. Even brainfuck is affected by the -----------------------------------------..>.---- inserted by cowsay. Most languages have strong parsing rules that would not cope with being post-processed by cowsay. The few exceptions for this will be either completely unaffected or badly affected, making the challenge uninteresting. – Victor Stafusa Feb 19 '14 at 12:32
• Actually, you can't transform just any brainfuck program to cowsay-brainfuck. Namely those that can output fewer than three characters cannot be transformed at all. – John Dvorak Feb 19 '14 at 14:52
• @JanDvorak, I was intending to allow competitors to choose the parameters of their calls to cowsay. For the uninitiated, -e controls the string used for eyes and defaults to oo, and -T controls the string used for the tongue, defaulting to  U. This is all yak-shaving, though, and having written this up and read the comments, I suspect that this idea has neither legs, horns nor udders. – ymbirtt Feb 19 '14 at 23:19
• If I could propose a variant that is more feasible, you could do a challenge like "Write a program in your language of choice that draws ASCII art of a cow saying something (does not have to be identical or even similar to the cowsay art). The entire drawing must itself be valid source code that does something other than no-op. Post results of both programs." That gives people more leeway to work around the specific restrictions of their compiler. – Jonathan Van Matre Feb 21 '14 at 23:22
• Ok, I found a language that falls within the middle ground: whitespace. Anyway, this question has a too narrow scope to develop an interesting challenge. – Victor Stafusa Feb 22 '14 at 18:31
• @JonathanVanMatre That would be a subjective validity criterion, and would probably be closed as too broad. – wastl Jul 2 '18 at 13:55

99 Bottles of Errors

While there are already many versions of "print 99 Bottles of Beer," I thought another one wouldn't hurt.

The challenge is fairly simple: print the lyrics to 99 bottles of Beer to STDERR. I don't care how you do it, so long as the entire lyrics show up. An entire program is required, so the following Java program would be invalid (even if it did do the correct thing):

System.out.println("99 Bottles of Beer on the Wall, take one down and pass it around...");


The scoring:

• This challenge is , so shortest code by byte count wins.
• If necessary, assume UTF-8 is the character encoding used.

The rules

• All the code must be in one file.
• Any language is allowed.
• Reading input, whether it is from STDIN`, a file, or the web, is not allowed.
• This is trivial in some languages (Java), where it reduces to a simple kolmogorov challenge, and impossible in others (those that have no distinct STDERR) – John Dvorak Mar 27 '14 at 7:42

Create an Identicon Generator

The challenge is to create an identicon generator. The identicons must be randomly generated, so we get a new identicon for each key the program receives. You can input a key using std-in or you can use your language's random number generator for the key.

In order to make your identicon look reasonably nice, it must generate a picture, then rotate that picture around the bottom right corner, the way this mockup shows:

The output must be to a PNG file. Shortest code wins.

• Far too broad. As this stands I can create a 1-pixel image whose colour is just the key. I don't think this question will be ready to go until you've found a way to prevent me from making the images differ only in their palette (and to pre-empt, I think that adding a rule "Images may not differ only in their palette" isn't a real fix). – Peter Taylor Mar 28 '14 at 14:50
• If you just ask for "random" images, you'll get images that are either hardly random at all (a solitary pixel in a random location), or completely random (noise). To get something "reasonably nice", you'll have to provide very clear instructions on how to produce these images. I suggest you try creating a few of these yourself, and find a minimal set of rules that produces results that look OK. Include requirements on dimensions (100x100px?), selection of colours (at least 2, not too similar), and drawing method (e.g., "five triangles with random vertices and a minimum area of 20 px²"). – r3mainer Mar 28 '14 at 15:25
• How important is the PNG file output? This will be a challenge in itself for many languages. Would you accept an uncompressed non-interlaced format like PPM? – trichoplax Apr 16 '14 at 9:45

Underhand Bejewled

Help me to write a game of bejewled, which cannot be lost!

Bejewled game rules

If you ever played bejewled, you can skip this, but for those who did not see it ever:

• Playing field of 8*8 grid is filled in with gems of 7 different types randomly
• By swapping two adjective stones, your goal is to create a line of at least three same type of stones in the either vertical or horizontal line
• If did so, the gems will dissappear, points are added (say 20 points for a matching) and new gems are provided randomly from the top
• image related:

Provide me a game which cannot be lost. In other words, the gems falling from the top are not random at all, but are falling in order that there is always at least one possibility to match three gems

But, from looking at the code at level of newbie programmer, it should look like that game acts as if it was random

Output

Playable game. As long as it is the grid of 8*8 filled in with 7 different types of "gems" the game is ok. It does not to have killer graphics, neither it does not need to be playable by mouse. (But in that case please make sure you show which "gem" is hovered and then selected)

Winning criteria

This is popularity contest. So highest rated game wins

• I think this is too big a task to work well for an underhanded contest. The programs will be way too large for anyone to actually read the source and try to find what's underhanded about it. – Martin Ender Nov 11 '14 at 8:32
• Thats what I was also afraid of. I will either take it as lesson to progress on my programming skill, or abandon the idea completly – Pavel Janicek Nov 11 '14 at 8:38