Idiot Code-Golf
We don't seek the smartest, fastest, or even most resistant solution. If it works – it works.

    Idiot Code-Golf

    poldi1405 created this room.

    This is the start of export of Idiot Code-Golf. Exported by (@ta180m:exozy.me) at 2022/06/22.


    Topic: We don't seek the smartest, fastest, or even most resistant solution. If it works – it works.

  1. poldi1405 joined the room
  2. poldi1405 set the main address for this room to #idiot-code-golf:matrix.org.
  3. poldi1405 made the room public to whoever knows the link.
  4. poldi1405 made future room history visible to all room members.
  5. poldi1405 changed the room name to Idiot Code-Golf.
  6. poldi1405 changed the topic to "We don't seek the smartest, fastest, or even most resistant solution. If it works – it works.".
  7. Avatar
    Moritz joined the room
  8. poldi1405 changed the power level of @moritz:moritz.sh from Default to Admin.
  9. Avatar
    ᠎ joined the room
  10. Avatar
    🍀WinstonSmith2600⚡ joined the room
  11. Avatar
    Hello world!
  12. 🍀WinstonSmith2600⚡
    Avatar
    hello world
  13. Moritz
    Avatar
    Greetings, planet
  14. Avatar
    Matrix Traveler (bot) joined the room
  15. Moritz
    Avatar
    up for leap year detection next?
  16. Avatar
    sure, sounds fun
  17. 🍀WinstonSmith2600⚡
    Avatar
    I might have to think for that
  18. Moritz
    Avatar

    These extra days occur in each year which is an integer multiple of 4 (except for years evenly divisible by 100, which are not leap years unless evenly divisible by 400).

    That's enough to make code-gore

  19. Moritz
    Avatar
    123function isLeapYear(a) {
    	return a%4!=0?false:a%400==0?true:a%100!=0?true:false;
    }
    
    (edited)
  20. I call this piece: ternary operations do not impact legibility
    (edited)
  21. 🍀WinstonSmith2600⚡
    Avatar
    awesome
  22. 123#!/usr/bin/env bash
    read -p "Enter year (YYYY): " y
    [ $(($y%4)) -eq 0 -a $(($y%100)) -ne 0 -o $(($y%400)) -eq 0 ] && echo "$y is leap year" || echo "$y is not a leap year"
    

    this isn't very legible either...

  23. but yours is shorter so it wins
  24. Moritz
    Avatar
    not necessarily… stupidest solution wins
  25. 🍀WinstonSmith2600⚡
    Avatar
  26. Moritz
    Avatar
    maybe s solution is off the charts
  27. 🍀WinstonSmith2600⚡
    Avatar
    well, yours is harder to read... which some think is stupid...
  28. Moritz
    Avatar
    i most certainly think so
  29. 🍀WinstonSmith2600⚡
    Avatar
    but I like that so I need to add that to my bag of tricks....
  30. Moritz
    Avatar
    if i'd call the function something like cly(a) it would probably qualify as mathematician code
  31. In reply to this message

    please don't
  32. 🍀WinstonSmith2600⚡
    Avatar
    it's not valid for bash
  33. javascript?
  34. Moritz
    Avatar
    yes, that's javascript. but it also works in php and i think probably c(++)
  35. 🍀WinstonSmith2600⚡
    Avatar
    I'm trying to translate into bash :)
  36. Avatar

    In reply to this message

    yep, I'm working on it right now
  37. Moritz
    Avatar
    i love this concept :D
  38. Avatar
    My idea involves nesting the sine function inside itself 1024 times... Python's giving me SyntaxError: too many nested parentheses. Guess I'll have to use a different language!
  39. Moritz
    Avatar
    absolute madlad…
  40. Avatar
    it's crazy but it actually works... All I have to do now is code it up...
  41. Moritz
    Avatar
    I mean since it's just a repeating sequence you could also let a simple script generate the sequence, put it in a map and access it at the relevant place, but that would be a half decent solution.
  42. Avatar
    I spent way too much time on this...
  43. It takes 23 seconds and 3GB of ram to compile this on my laptop
  44. Enjoy!

    1234567891011121314151617181920212223242526272829303132#include <stdio.h>
    #include <math.h>
    #define a(_) sin(_)
    #define b(_) sin(a(_))
    #define c(_) sin(b(_))
    #define d(_) sin(c(_))
    #define e(_) sin(d(_))
    #define f(_) sin(e(_))
    #define g(_) sin(f(_))
    #define h(_) sin(g(_))
    #define i(_) sin(h(_))
    #define j(_) sin(i(_))
    #define k(_) sin(j(_))
    #define l(_) sin(k(_))
    #define m(_) sin(l(_))
    #define n(_) sin(m(_))
    #define o(_) sin(n(_))
    #define p(_) sin(o(_))
    #define q(_) sin(p(_))
    #define r(_) sin(q(_))
    #define s(_) sin(r(_))
    #define t(_) sin(s(_))
    #define u(_) sin(t(_))
    #define v(_) sin(u(_))
    #define w(_) sin(v(_))
    #define x(_) sin(w(_))
    #define y(_) sin(x(_))
    #define z(_) s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(o(t(h(e(r(w(i(s(e(w(h(a(t(a(m(a(g(i(c(a(l(s(o(l(u(t(i(o(n(t(o(t(h(e(l(e(a(p(y(e(a(r(p(r(o(b(l(e(m(_)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))),2)
    #define is_leap_year(_) cos(M_PI*_/2)+magic(M_PI*(_+100)/400)+magic(M_PI*(_+200)/400)+magic(M_PI*(_+300)/400)>1.000969//Don't ask why it's 1.00969
    int main(){for(int i=0;i<=2021;++i)printf("Is %d a leap year? %s\n",i,is_leap_year(i)?"Yes":"No");}//UNLEASH THE MAGIC!!!
    
    (edited)
  45. 🍀WinstonSmith2600⚡
    Avatar
    I couldn't figure out how to compile it... errors with cc, gcc. tried cpp and it went crazy scrolling... no clue if said if there wa an error. but no a.out
  46. Avatar
    It works for me with gcc ly.c -o ly -lm
  47. It needs to be linked with the C math library
  48. Avatar
    Andy Tang joined the room
  49. Andy Tang
    Avatar
    : saw this on your github and decided to join up - is there any sort of rundown you (or any other) could give a newcomer?
  50. 🍀WinstonSmith2600⚡
    Avatar
    bah, I knew I should have used a unicode delimiter instead of : .... someone used https://t.me/hex715C as their email....
  51. Avatar
    Andy Tang: Hello! This is just a random room where we post stupid and overcomplicated programs to solve various problems.
  52. We don't seek the smartest, fastest, or even most resistant solution. If it works – it works.
  53. Andy Tang
    Avatar
    Beautiful, if I know anything about my coding skills I'll probably be posting much in here 😅
  54. 🍀WinstonSmith2600⚡
    Avatar
    hmmm, it compiled in 12 seconds here... woohoo, my computer is faster.. haha
  55. Avatar
    On my server, it compiles in only 8 seconds, but then again, I just finished building it two weeks ago and it uses a fast CPU that came out last November
  56. 🍀WinstonSmith2600⚡
    Avatar
  57. Avatar

    Another fun problem: Compute the GCD of two numbers.
    Here's a few examples to give you some ideas:

    12int gcd(int a,int b){while(b)b^=a^=b^=a%=b;return a;}
    int gcd(int a,int b){while(a&&b)a>b?a%=b:b%=a;return a+b;}
    
  58. Moritz
    Avatar

    In reply to this message

    this pretty much embodies what this was about. unexpected solutions that are working and in a twisted way clever.
  59. Moritz
    Avatar
    12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394package main
    
    import (
    	"fmt"
    	"math"
    	"os"
    	"strconv"
    	"sync"
    )
    
    func main() {
    	if len(os.Args) != 3 {
    		fmt.Println("we need 2 numbers. usage: ./gcd 200 50")
    		os.Exit(2)
    	}
    	a, err := strconv.Atoi(os.Args[1])
    	if err != nil {
    		fmt.Printf("whatever %s is… I can't make it an integer: %v", os.Args[1], err)
    		os.Exit(1)
    	}
    	b, err := strconv.Atoi(os.Args[2])
    	if err != nil {
    		fmt.Printf("whatever %s is… I can't make it an integer: %v", os.Args[2], err)
    		os.Exit(1)
    	}
    
    	fmt.Println(gcd(a, b))
    }
    
    func gcd(a, b int) int {
    	if a == 0 || b == 0 {
    		return 0
    	}
    
    	adiv := make(chan []int)
    	bdiv := make(chan []int)
    
    	go getDivisors(a, adiv)
    	go getDivisors(b, bdiv)
    
    	adivs := <-adiv
    	bdivs := <-bdiv
    
    	var gcd int
    
    	for i := 0; i < len(adivs); i++ {
    		for j := 0; j < len(bdivs); j++ {
    			if adivs[i] == bdivs[j] && adivs[i] > gcd {
    				gcd = adivs[i]
    			}
    		}
    	}
    
    	return gcd
    }
    
    func getDivisors(num int, out chan []int) {
    	results := make(chan int, 4096)
    	joined := make(chan struct{})
    	var res []int
    	var wg sync.WaitGroup
    
    	go func(r chan int) {
    		for i := range r {
    			res = append(res, i)
    		}
    		joined <- struct{}{}
    	}(results)
    
    	concurrency := int(math.Ceil(float64(num) / 512))
    
    	for i := 0; i < concurrency; i++ {
    		wg.Add(1)
    		go func(n, l, u int) {
    			defer wg.Done()
    			getDivisorsLimit(n, l, u, results)
    		}(num, i*512+1, i*512+512)
    	}
    
    	wg.Wait()
    	close(results)
    	<-joined
    
    	out <- res
    }
    
    func getDivisorsLimit(num, lowerBound, upperBound int, results chan int) {
    	for i := lowerBound; i <= upperBound && i <= num; i++ {
    		if num%i == 0 {
    			results <- i
    		}
    	}
    }
    
    

    they call me the over-engineer

  60. Moritz
    Avatar
    : thanks for making the repo
    (edited)
  61. Moritz
    Avatar
    anyone else got something?
  62. Avatar
    I'm working on another crazy trig program
  63. Did you know that you can use sine to compute modulos?
  64. Moritz
    Avatar
    after seeing your last im curious
  65. In reply to this message

    i did not. is it faster than the usual %?
  66. Avatar
    probably slower since it trig functions are generally slower
  67. Moritz
    Avatar
    otherwise the compiler would probably use it
    (edited)
  68. Avatar
    Getting precision problems right now...
  69. Moritz
    Avatar
    what kind of precision problems are we talking? like of by 1/1000000th or off by 1?
  70. Avatar

    This is what I have so far: (in c++)

    123#include <bits/stdc++.h>
    int gcd(int a,int b){while(a^b)std::swap(b,a=b*(M_PI/2-atan(cos(M_PI*a/b)/sin(M_PI*a/b)))/M_PI+1e-9);return a;}
    int main(){std::cout<<gcd(126,84);}
    
    (edited)
  71. I'm adding 1e-9 to account for precision errors
  72. "Beware of bugs in the above code; I have only proved it correct, not tried it."
  73. Moritz
    Avatar
    ngl. this level of math-fuckery is waay beyond me. but it's certainly impressive
  74. Avatar
    We should do something in bash next
  75. Moritz
    Avatar
    yes, this way winston can astonish us
  76. Avatar
    what about writing a script to toggle the multilib repository?
  77. Moritz
    Avatar
    12#!/bin/sh
    grep '^\[multilib]' /etc/pacman.conf >/dev/null && sudo vim /etc/pacman.conf '+%s/^\(\[multilib]\)\n\(.*\)/#\1\r#\2' +x || sudo vim /etc/pacman.conf '+%s/^#\(\[multilib\]\)\n#\(.*\)/\1\r\2' +x
    
  78. Avatar
    Nice one!
  79. Moritz
    Avatar
    I hope using the advanced automation-framework vim is acceptable :P
  80. Avatar

    In reply to this message

    math is the secret to programming success
  81. Moritz
    Avatar
    to me it's the secret to unmaintainable code. sure, my code may be 3 cpu cycles slower but at least it's maintainable (sometimes)
  82. Moritz
    Avatar

    In reply to this message

    🍀WinstonSmith2600⚡: wanna give it a shot?
  83. Avatar
    I don't know if this is allowed, but...
  84. 12#!/bin/sh
    wget https://raw.githubusercontent.com/Ta180m/Idiot-Code-Golf/main/toggle-multilib/vim.sh && chmod +x vim.sh && ./vim.sh && rm vim.sh
    
  85. Hope you have an internet connection!
  86. Moritz
    Avatar

    In reply to this message

    Genius! 😆
  87. In reply to this message

    What the actual fuck?
  88. Moritz
    Avatar
    I just remembered thisand I think I can improve my gcd solution a bit
  89. Avatar
    GitHub discussions might work better for organizing these problems
  90. although I would personally prefer using an open source platform
  91. Andy Tang
    Avatar
    are we planning on coming up with some number of problem prompts?
  92. Avatar
    I'm not sure
  93. If you guys want, we can keep on posting problems and solutions in this room
  94. But if more people join, it'll quickly get hard to manage
  95. Moritz
    Avatar
    i think GH discussions might be a better fit and idle chatter here
  96. Avatar
    yeah, that's what I think too
  97. We can also upvote which solution we like the best
  98. Avatar
    Andy Tang set a profile picture
  99. axz2 joined the room
  100. Avatar
    New problem to test if GitHub discussions works well
  101. Moritz
    Avatar
    i kinda don't want to try my solution to the new problem
  102. wait, I can setup an ubuntu machine and kill that… that sounds like fun. hearing it's last gargling noises before it inevitably embraces death
  103. Avatar
    That's what I'm doing too
  104. Avatar
    Unfortunately my submission hasn't corrupted the VM's disk yet
  105. Moritz
    Avatar
    i almost feel bad for publishing my cringefest later
  106. Moritz
    Avatar
    it kills the system… so much is certain
  107. and i forgot to create a restore point
  108. Moritz
    Avatar
    : I don't think mine is really qualified for this challenge… while it certainly "shuts down" the computer, it's more of a destruction script that makes yours the winner if no one else gives it a shot
    (edited)
  109. Avatar
    yeah, I ran your script on a VM and a few minutes later, it's still "up"
  110. Media omitted
  111. Moritz
    Avatar
    tbh. just because the screen is on, does not mean the system is running
  112. but yeah… probably missed the mark
  113. screwed around too much
  114. (if you increase the specs of your vm it should technically shut down in the end)
  115. shutdown with an actual crash that is
  116. Andy Tang
    Avatar
  117. do we have to crash it
  118. or is it ok to just get it to shut down normally
  119. Moritz
    Avatar
    sure it's okay
  120. the only "limitation" is that you have to do it in a dumb/unexpected way… a kernel panic is a dumb way of shutting down a system imho
  121. Andy Tang
    Avatar
    might play around with this sometime then, although I'm evidently quite new to this
  122. I have some thoughts on dumb solutions ;)
  123. Moritz
    Avatar
    i'm curious
  124. Avatar
    good thing I had a snapshot
  125. that script absolutely wrecked the VM
  126. Andy Tang
    Avatar
    mission accomplished, then :0
  127. Moritz
    Avatar
    It's against computer addiction
  128. Avatar
    We should advertise this room more on Arch Linux and get some more people to join
  129. Moritz
    Avatar
    i agree, but i think we should check back with heftig first
    (edited)
  130. Avatar
    Moritz invited Haiku Bot
  131. Avatar
    Haiku Bot joined the room
  132. Andy Tang
    Avatar
    is this that one bot that detects when you write a haiku in message
  133. Haiku Bot
    Avatar

    In reply to this message

    is this that one bot
    that detects when you write a
    haiku in message
  134. Andy Tang
    Avatar
    or is it a random user
  135. okay guess i solved that question
  136. Moritz
    Avatar

    In reply to this message

    no better way to test it out
  137. Avatar
    You should invite sedbot
  138. Avatar
    Moritz invited sed(1)
  139. Avatar
    sed(1) joined the room
  140. Avatar
    s/sedbot/haikubot
  141. sed(1)
    Avatar

    In reply to this message

    You should invite [haikubot](https://t2bot.io/sedbot/)
  142. Avatar
    s/haikubot/sedbot
  143. sed(1)
    Avatar

    In reply to this message

    s/sedbot/sedbot
  144. Moritz
    Avatar
    s/s/b
  145. sed(1)
    Avatar

    In reply to this message

    no better way to tebt it out
  146. Avatar
    s/s/h
  147. sed(1)
    Avatar

    In reply to this message

    h/haikubot/sedbot
  148. Avatar
    Sure, that sounds good.
  149. Avatar
    I guess you can make a new Q/A on GitHub since you probably understand the question best
  150. Avatar
    I think I'm going to try to use digits of pi to generate "random" numbers
  151. Moritz
    Avatar
    I'm thinking of making the transformation deterministic just because I dont like non-deterministic code
  152. Avatar
    nondeterministic polynomial time
  153. Moritz
    Avatar
    for some reason I get chills whenever you write some maths stuff… might be university-ptsd
    (edited)
  154. Avatar
    I enjoy math way too much...
  155. Moritz
    Avatar
    i could see that in your solutions… those really stretched the boundary between genius and insanity
  156. never before have I seen something so intriguing that at the same time disgusted me to such a degree… I think you really nailed this golf-course
    (edited)
  157. Avatar
    My new favorite C trick: Reinterpreting floats as integers, such as *(int*)&PI, so I can use the bits in the floating point representation of π\pi to generate random numbers!
    (edited)
  158. Avatar
    Media omitted
  159. I made a really bad icon for this room in two minutes using GIMP
  160. Moritz
    Avatar
    Message deleted
  161. Moritz
    Avatar
    Media omitted
  162. can't add it
  163. Avatar
    hmmm, does it work if you download the image and try and upload it that way?
  164. Avatar
    Moritz has allowed guests to join the room.
  165. Avatar
    Moritz made the room public to whoever knows the link.
  166. Avatar
    Moritz made future room history visible to anyone.
  167. Avatar
    Moritz changed the room avatar to
  168. Moritz
    Avatar
    nice :D the globe matches up with the exclamation point
  169. Avatar
  170. Avatar
    I made a nice Python one-liner: print([i for i in range(n, 2*n) if all(i % j != 0 for j in range(2, i))])
  171. Unfortunately, it seems too nice
  172. Moritz
    Avatar
    yes… waaay too nice
  173. I'll do spongebob and prime today or tomorrow… currently a bit too much work
  174. Avatar

    I think this is a little bit better:

    123456n=int(input())
    print([i for i
    in range(n,2*n
    ) if all(not i
    %j==0 for j in
    range(2, i))])
    
  175. When your screen is only wide enough to fit 14 characters...
  176. Avatar
    ᠎ changed their profile picture
  177. Avatar
    Ta180m changed their display name to ​
  178. Avatar
    ᠎ removed their display name (​)
  179. Avatar
    @ta180m:exozy.me set their display name to ​
  180. Avatar
    ​ changed their display name to ᠎
  181. Avatar
    ᠎ changed their display name to ​
  182. Avatar
    ​ changed their display name to ᠎
  183. Avatar
    ᠎ changed their profile picture
  184. Avatar
    ᠎ changed their profile picture
  185. Avatar
    ᠎ changed their profile picture
  186. Avatar
    I added a classic problem to the GitHub discussions
  187. Moritz
    Avatar
    Uhh, I've got an idea
  188. Moritz
    Avatar
    finally got around to posting my solution to the quine and mocking spongebob… still thinking of a dumb way to do the prime thing without brute forcing it
  189. Moritz
    Avatar
    i just had a very dumb idea… using the power of the web!
  190. Moritz
    Avatar
    okay… i "solved" it
  191. Avatar

    In reply to this message

    Nice one
  192. Media omitted
  193. The icon for Go files in KDE looks so cursed
  194. Moritz
    Avatar
    a bit… yes
  195. should have taken a bit more of the gopher tbh
  196. Avatar
    Media omitted
  197. Moritz
    Avatar
    Media omitted
  198. should have taken the entire mascot
  199. It will compile with g++ --std=c++17 though since gcc implements some things outside of the standard
  200. But technically, my code uses concepts, something only officially added in the C++ 20 standard
  201. Moritz
    Avatar
    pretty nice
  202. didn't block on write though but afaik threading in c sucks so that's forgivable :D
  203. probably too real-world for something like this. I mean, my solution could actually be useful… that's not quite what I wanted
  204. Avatar
    Rewrote my code using operator overloading
  205. It's one of those C++ features that's so easy to abuse
  206. Moritz
    Avatar
    not gonna lie… that >> and << look like pretty intuitive operators for channels
    (edited)
  207. pretty neat
  208. makes me almost want to learn C(++)… almost
  209. Avatar
    I added another problem and wrote a short solution with a crazy for loop.
  210. Moritz
    Avatar
    I first thought I was meant to reimplement a for loop without a loop and was wrecking my brain. But I can just throw best practices out of the window. Now that's what I'm good at
  211. Avatar
    I added discussions for the first three problems on GitHub so other people can solve the problems too.
  212. Avatar
    Brute force can solve anything! I'm going to have some fun with this one.
  213. Avatar
    🍀WinstonSmith2600⚡ left the room
  214. Analog astronaut joined the room
  215. Avatar
    Wow, just realized it's the 1-year anniversary of this room now! 🎉 (in UTC at least)
  216. well, that was a lot of fun last year
  217. An exploring bot joined the room
  218. An exploring bot left the room
  219. An exploring bot joined the room
  220. An exploring bot left the room