
- Tue, Apr 13 2021
- P14:48poldi1405 joined the room
- P14:48poldi1405 set the main address for this room to #idiot-code-golf:matrix.org.
- P14:48poldi1405 made the room public to whoever knows the link.
- P14:48poldi1405 made future room history visible to all room members.
- P14:48poldi1405 changed the room name to Idiot Code-Golf.
- P14:48poldi1405 changed the topic to "We don't seek the smartest, fastest, or even most resistant solution. If it works – it works.".
- 14:48Moritz joined the room
- P14:49poldi1405 changed the power level of @moritz:moritz.sh from Default to Admin.
- 14:49 joined the room
- 14:49🍀WinstonSmith2600⚡ joined the room
- 14:49Hello world!
- 🍀WinstonSmith2600⚡14:49hello world
- Moritz14:50Greetings, planet
- 14:50Matrix Traveler (bot) joined the room
- Moritz14:50up for leap year detection next?
- 14:51sure, sounds fun
- 🍀WinstonSmith2600⚡14:51I might have to think for that
- Moritz14:52
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
- Moritz15:07
123
function isLeapYear(a) { return a%4!=0?false:a%400==0?true:a%100!=0?true:false; }
(edited) - 15:08I call this piece: ternary operations do not impact legibility(edited)
- 🍀WinstonSmith2600⚡15:12awesome
- 15:16
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...
- 15:17but yours is shorter so it wins
- Moritz15:18not necessarily… stupidest solution wins
- 🍀WinstonSmith2600⚡15:18doh
- 🍀WinstonSmith2600⚡15:19well, yours is harder to read... which some think is stupid...
- Moritz15:20i most certainly think so
- 🍀WinstonSmith2600⚡15:20but I like that so I need to add that to my bag of tricks....
- Moritz15:21if i'd call the function something like cly(a) it would probably qualify as mathematician code
- 🍀WinstonSmith2600⚡15:23it's not valid for bash
- 15:25javascript?
- Moritz15:26yes, that's javascript. but it also works in php and i think probably c(++)
- 🍀WinstonSmith2600⚡15:26I'm trying to translate into bash :)
-
- Moritz15:58i love this concept :D
- 16:12My 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! - Moritz16:13absolute madlad…
- 16:13it's crazy but it actually works... All I have to do now is code it up...
- Moritz16:15I 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.
- 18:24I spent way too much time on this...
- 18:25It takes 23 seconds and 3GB of ram to compile this on my laptop
- 18:25
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(_) sin(y(_)) //self-documenting code #define magic(_) pow(t(h(e(m(a(i(n(t(r(i(c(k(t(h(a(t(t(h(i(s(c(o(d(e(i(s(e(x(p(l(o(i(t(i(n(g(i(s(t(h(e(f(a(c(t(t(h(a(t(n(e(s(t(i(n(g(s(i(n(e(i(n(s(i(d(e(o(f(i(t(s(e(l(f(t(h(o(u(s(a(n(d(s(o(f(t(i(m(e(s(p(r(o(d(u(c(e(s(a(c(u(r(v(e(s(i(m(i(l(a(r(t(o(a(s(q(u(a(r(e(w(a(v(e(w(e(c(a(n(t(h(e(n(s(q(u(a(r(e(t(h(i(s(t(o(g(e(t(a(c(u(r(v(e(t(h(a(t(i(s(z(e(r(o(i(n(a(f(e(w(l(o(c(a(t(i(o(n(s(a(n(d(o(n(e(e(v(e(r(y(w(h(e(r(e(e(l(s(e(b(y(c(h(o(o(s(i(n(g(s(p(e(c(i(f(i(c(i(n(p(u(t(p(a(r(a(m(e(t(e(r(s(w(e(c(a(n(m(a(k(e(c(u(r(v(e(s(t(h(a(t(a(r(e(z(e(r(o(a(t(o(n(e(h(u(n(d(r(e(d(t(w(o(h(u(n(d(r(e(d(a(n(d(t(h(r(e(e(h(u(n(d(r(e(d(a(n(d(a(d(d(t(h(e(m(t(o(g(e(t(h(e(r(t(o(g(e(t(a(c(u(r(v(e(t(h(a(t(h(a(s(d(i(p(s(a(t(t(h(e(s(e(l(o(c(a(t(i(o(n(s(c(o(m(b(i(n(e(d(w(i(t(h(a(s(i(m(p(l(e(s(i(n(e(c(u(r(v(e(t(h(a(t(s(p(e(a(k(s(e(v(e(r(y(f(o(u(r(w(e(c(a(n(c(r(e(a(t(e(a(c(u(r(v(e(t(h(a(t(i(s(l(a(r(g(e(w(h(e(n(t(h(e(i(n(p(u(t(i(s(a(m(u(l(t(i(p(l(e(o(f(f(o(u(r(o(r(o(n(e(h(u(n(d(r(e(d(t(w(o(h(u(n(d(r(e(d(o(r(t(h(r(e(e(h(u(n(d(r(e(d(a(n(d(s(m(a(l(l(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) - 🍀WinstonSmith2600⚡19:16I 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
- 19:16It works for me with
gcc ly.c -o ly -lm
- 19:17It needs to be linked with the C math library
- 20:39Andy Tang joined the room
- Andy Tang
- 🍀WinstonSmith2600⚡21:18bah, I knew I should have used a unicode delimiter instead of : .... someone used
https://t.me/hex715C
as their email.... -
- 21:25We don't seek the smartest, fastest, or even most resistant solution. If it works – it works.
- Andy Tang21:25Beautiful, if I know anything about my coding skills I'll probably be posting much in here 😅
- 🍀WinstonSmith2600⚡21:27hmmm, it compiled in 12 seconds here... woohoo, my computer is faster.. haha
- 21:31On 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
- 🍀WinstonSmith2600⚡21:31doh
- 21:50
Another fun problem: Compute the GCD of two numbers.
Here's a few examples to give you some ideas:12
int 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;}
- Wed, Apr 14 2021
- Moritz01:18
In reply to this message
this pretty much embodies what this was about. unexpected solutions that are working and in a twisted way clever. - Moritz02:32
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
package 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
- Moritz10:18anyone else got something?
- 10:27I'm working on another crazy trig program
- 10:28Did you know that you can use sine to compute modulos?
- Moritz10:28after seeing your last im curious
- 10:29probably slower since it trig functions are generally slower
- Moritz10:29otherwise the compiler would probably use it(edited)
- 10:43Getting precision problems right now...
- Moritz10:44what kind of precision problems are we talking? like of by 1/1000000th or off by 1?
- 10:47
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) - 10:47I'm adding 1e-9 to account for precision errors
- 10:48"Beware of bugs in the above code; I have only proved it correct, not tried it."
- Moritz10:50ngl. this level of math-fuckery is waay beyond me. but it's certainly impressive
- 10:57We should do something in bash next
- Moritz10:57yes, this way winston can astonish us
- 13:44what about writing a script to toggle the multilib repository?
- Moritz14:33
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
- 14:38Nice one!
- Moritz14:39I hope using the advanced automation-framework vim is acceptable :P
-
- Moritz14:40to me it's the secret to unmaintainable code. sure, my code may be 3 cpu cycles slower but at least it's maintainable (sometimes)
- Moritz
- 16:37I don't know if this is allowed, but...
- 16:37
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
- 16:37Hope you have an internet connection!
-
- Thu, Apr 15 2021
- Moritz
- Moritz01:39yup… it's cursed now: https://github.com/Ta180m/Idiot-Code-Golf/blob/main/gcd/gcd.go
- 09:44GitHub discussions might work better for organizing these problems
- 09:45although I would personally prefer using an open source platform
- Andy Tang09:46are we planning on coming up with some number of problem prompts?
- 09:49I'm not sure
- 09:49If you guys want, we can keep on posting problems and solutions in this room
- 09:49But if more people join, it'll quickly get hard to manage
- Moritz09:50i think GH discussions might be a better fit and idle chatter here
- 09:50yeah, that's what I think too
- 09:50We can also upvote which solution we like the best
- 09:56Andy Tang set a profile picture
- A09:59axz2 joined the room
- 10:19New problem to test if GitHub discussions works well
- Moritz10:29i kinda don't want to try my solution to the new problem
- 10:30wait, I can setup an ubuntu machine and kill that… that sounds like fun. hearing it's last gargling noises before it inevitably embraces death
- 10:32That's what I'm doing too
- 10:54Unfortunately my submission hasn't corrupted the VM's disk yet
- Moritz11:26i almost feel bad for publishing my cringefest later
- Moritz11:55it kills the system… so much is certain
- 11:55and i forgot to create a restore point
- Moritz
- 12:47yeah, I ran your script on a VM and a few minutes later, it's still "up"
- 12:47Media omitted
- Moritz12:47tbh. just because the screen is on, does not mean the system is running
- 12:48but yeah… probably missed the mark
- 12:48screwed around too much
- 12:48(if you increase the specs of your vm it should technically shut down in the end)
- 12:50shutdown with an actual crash that is
- Andy Tang12:52hmm
- 12:52do we have to crash it
- 12:52or is it ok to just get it to shut down normally
- Moritz12:53sure it's okay
- 12:54the 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
- Andy Tang12:54might play around with this sometime then, although I'm evidently quite new to this
- 12:54I have some thoughts on dumb solutions ;)
- Moritz12:55i'm curious
- 13:00good thing I had a snapshot
- 13:00that script absolutely wrecked the VM
- Andy Tang13:02mission accomplished, then :0
- Moritz13:03It's against computer addiction
- 14:15We should advertise this room more on
Arch Linux and get some more people to join
- Moritz14:16i agree, but i think we should check back with heftig first(edited)
- 16:07Moritz invited Haiku Bot
- 16:07Haiku Bot joined the room
- Andy Tang16:13is this that one bot that detects when you write a haiku in message
- Haiku Bot
- Andy Tang16:13or is it a random user
- 16:13okay guess i solved that question
- Moritz
- 23:48Moritz invited sed(1)
- 23:48sed(1) joined the room
- Fri, Apr 16 2021
- 08:53s/sedbot/haikubot
- sed(1)
- 13:09s/haikubot/sedbot
- sed(1)
- Moritz13:10s/s/b
- sed(1)
- 13:10s/s/h
- sed(1)
- Moritz15:19something easy next? I'd suggest: https://github.com/Ta180m/Idiot-Code-Golf/discussions/5#discussioncomment-617093
- 15:19Sure, that sounds good.
- 19:11I guess you can make a new Q/A on GitHub since you probably understand the question best
- Sat, Apr 17 2021
- 15:29I think I'm going to try to use digits of pi to generate "random" numbers
- Moritz15:30I'm thinking of making the transformation deterministic just because I dont like non-deterministic code
- 15:35nondeterministic polynomial time
- Moritz15:35for some reason I get chills whenever you write some maths stuff… might be university-ptsd(edited)
- 15:38I enjoy math way too much...
- Moritz15:39i could see that in your solutions… those really stretched the boundary between genius and insanity
- 15:40never 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)
- 21:53My new favorite C trick: Reinterpreting floats as integers, such as
*(int*)&PI
, so I can use the bits in the floating point representation of π to generate random numbers!(edited) - 22:18Media omitted
- 22:18I made a really bad icon for this room in two minutes using GIMP
- Sun, Apr 18 2021
- Moritz06:30Message deleted
- Moritz06:30Media omitted
- 06:30can't add it
- 10:05hmmm, does it work if you download the image and try and upload it that way?
- 10:11Moritz has allowed guests to join the room.
- 10:11Moritz made the room public to whoever knows the link.
- 10:11Moritz made future room history visible to anyone.
- 10:12Moritz changed the room avatar to
- Moritz10:12nice :D the globe matches up with the exclamation point
- 15:41Added an interesting prime number problem
- Mon, Apr 19 2021
- 09:55I 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))])
- 09:56Unfortunately, it seems too nice
- Moritz09:56yes… waaay too nice
- 09:56I'll do spongebob and prime today or tomorrow… currently a bit too much work
- 10:05
I think this is a little bit better:
123456
n=int(input()) print([i for i in range(n,2*n ) if all(not i %j==0 for j in range(2, i))])
- 10:07When your screen is only wide enough to fit 14 characters...
- Tue, Apr 20 2021
- 19:29 changed their profile picture
- 20:20Ta180m changed their display name to
- 20:20 removed their display name ()
- 20:20@ta180m:exozy.me set their display name to
- 20:26 changed their display name to
- 20:28 changed their display name to
- 20:29 changed their display name to
- Thu, Apr 22 2021
- 07:38 changed their profile picture
- 07:43 changed their profile picture
- 07:52 changed their profile picture
- 07:55I added a classic problem to the GitHub discussions
- Sat, Apr 24 2021
- Moritz10:55Uhh, I've got an idea
- Sun, Apr 25 2021
- Moritz15:15finally 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
- Moritz15:22i just had a very dumb idea… using the power of the web!
- Moritz15:49okay… i "solved" it
-
- 16:18Media omitted
- 16:18The icon for Go files in KDE looks so cursed
- Moritz16:19a bit… yes
- 16:19should have taken a bit more of the gopher tbh
- 16:21Media omitted
- Moritz16:22Media omitted
- 16:23should have taken the entire mascot
- Tue, Apr 27 2021
- Moritz04:29https://github.com/Ta180m/Idiot-Code-Golf/discussions/9 I just created a new problem
- 20:37I wrote my first code that only works with C++ 20!
- 20:39It will compile with
g++ --std=c++17
though since gcc implements some things outside of the standard - 20:39But technically, my code uses concepts, something only officially added in the C++ 20 standard
- Wed, Apr 28 2021
- Moritz02:11pretty nice
- 02:11didn't block on write though but afaik threading in c sucks so that's forgivable :D
- 02:12probably too real-world for something like this. I mean, my solution could actually be useful… that's not quite what I wanted
- 07:42Rewrote my code using operator overloading
- 07:42It's one of those C++ features that's so easy to abuse
- Moritz07:44not gonna lie… that >> and << look like pretty intuitive operators for channels(edited)
- 07:45pretty neat
- 07:45makes me almost want to learn C(++)… almost
- Thu, Apr 29 2021
- Moritz12:09
https://teddit.net/r/golang/comments/n11l66/just_because_you_can_does_not_mean_that_you/
We couldn't possibly top this, right?
- 15:53I added another problem and wrote a short solution with a crazy for loop.
- Fri, Apr 30 2021
- Moritz00:01I 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
- 13:13I added discussions for the first three problems on GitHub so other people can solve the problems too.
- Wed, May 5 2021
- 11:11Brute force can solve anything! I'm going to have some fun with this one.
- Sat, May 8 2021
- 16:39🍀WinstonSmith2600⚡ left the room
- Wed, Sep 22 2021
- A12:08Analog astronaut joined the room
- Tue, Apr 12 2022
- 20:38Wow, just realized it's the 1-year anniversary of this room now! 🎉 (in UTC at least)
- 20:38well, that was a lot of fun last year
- Mon, Apr 18 2022
- A07:25An exploring bot joined the room
- A07:25An exploring bot left the room
- Sun, May 1 2022
- A19:32An exploring bot joined the room
- A19:32An exploring bot left the room

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.