CodeWalrus

CodeWalrus Website => Contests => Topic started by: Juju on July 18, 2016, 11:37:37 pm

Title: Tweetjam
Post by: Juju on July 18, 2016, 11:37:37 pm
Post your best code here. Only requirement: the code must fit on a tweet. 140 characters or less.

No deadline, no winner, multiple participations allowed, must be a full program written by you. Use the [code] tag to put your code in and specify the language and what it does. You might even use the karma buttons to vote on the entries, if you want, and even improve on other entries. Have fun.
Title: Re: Tweetjam
Post by: DJ Omnimaga on July 19, 2016, 01:24:40 am
That seems interesting. I think this was done before elsewhere but I forgot where. Maybe it was one of the Cwick contests or something. What are the platform restrictions?

Now I wonder if a full game can be coded under 140 characters of code...
Title: Re: Tweetjam
Post by: Juju on July 19, 2016, 01:29:00 am
Pretty sure we had a bunch of contests with that restriction. but this time, it's the only one. (That and the usual code golf and common sense rules.) No platform restriction. It was done on the Lexaloffle BBS for PICO-8 carts too, for the record.
Title: Re: Tweetjam
Post by: DJ Omnimaga on July 19, 2016, 02:27:23 am
Aah thanks for explaining. I wasn't sure anymore.
Title: Re: Tweetjam
Post by: calcplays on July 20, 2016, 02:22:41 am
The Oregon Trail for Python 2.7

l=[" "]
while l[-1]!="":
    l+=[raw_input("Name: ")]
raw_input("You depart!")
for j in l[1:-1]:
    raw_input(j+" has dysentery.")

Directions: You and your wagon party are about to venture across the frontier to build a new life in the Wild West.
Enter in the names of your party members and advance with an empty name.
Then, carefully traverse and survive in your journey across the United States. Press enter to advance.
Title: Re: Tweetjam
Post by: Juju on July 20, 2016, 03:57:18 am
Code (woooo.rb) Select
s=IO.new(3,"w")rescue File.open(File::NULL,"w")
print"w"
8.times{print"oo"
188.times{(0..255).each{|i|s.print i.chr}}}
puts


Fits on a tweet exactly. (That's a bonus in this thread.) It's in Ruby, save it as woooo.rb, run it like this:

Code (Linux) Select
ruby woooo.rb 3> >(aplay -q -r48000 -)
Code (macOS) Select
brew install sox
ruby woooo.rb 3> >(play -q -c 2 -b 8 -e unsigned -t raw -r 48k -)

Code (Windows) Select
¯\_(ツ)_/¯

Enjoy a 8-second sawtooth tone while the terminal seems happy. Bonus: remove the poor excuse of a reversed heart that is 3> and everything after (which should be the command you use to play raw sound from stdin) and it goes silent. Wrote this to demonstrate outputting text and sound to stdout at the same time, isn't that great? Could have used stderr as well (which would be 2> instead of 3>, but if you omit 2> and everything after it would output garbage in the terminal instead of doing nothing), but I wanted to demonstrate the use of file descriptor numbers greater than 2.

EDIT:
Code (bash) Select
curl -s https://mobile.twitter.com/juju2143/status/755613582776229888|xmllint --xpath '//div[@data-id="755613582776229888"]/div' --html -|sed 's/<[^>]*>//g'|ruby 3> >(aplay -q -r48000 -)

Run this on your Linux terminal, it downloads the above code from Twitter and runs it. That line also fits exactly in a tweet.
Title: Re: Tweetjam
Post by: DJ Omnimaga on July 20, 2016, 05:41:42 am
Here's a TI-BASIC game. Exactly 140 characters large (or 99 bytes on-calc with the program name)

AxesOff
ZTrig
For(Z,0,9³
randInt(⁻8,8→A
Line(A,2,A+1,2
For(θ,Z²,9³
End
Line(A,2,A+1,2,20
Input
If A≠int(X
Then
Disp "PTS:",Z
Return
End
End


(https://img.ourl.ca/linejam.gif)

Basically you have to memorize where the line appears then click at the matching X position. Yay for the Input command with no argument. :P I attached the file below for those who wants to try it.
Title: Re: Tweetjam
Post by: JWinslow23 on July 20, 2016, 07:52:21 am
My entry is in TI-BASIC. With the program name "T" (for Tweetjam :P ), this is exactly 140 bytes on-calc, and it works on both color and mono calcs.

It's a Stacker-type game.

The pieces move rapidly back and forth. Press 2nd to stack your pieces.

Land your pieces not on the stack, and you lose one piece. Lose all your pieces and it's game over. Get to the top and you win.

(https://s31.postimg.org/4e7c6b1d7/Tweetjam.gif)

ClrHome
DelVar A8→H
5→L
While H and Ans
A+1
Ans-2Ans(Ans+L=13→A
1+abs(Ans
Output(H,Ans," "+sub("*****",1,L)+" 
If getKey=21
Then
If H=8 or Ans<B+M and Ans>B-L
Then
Ans→B
H-1→H
L→M
Else
L-1→L
End
End
End
If Ans
Disp "W

I suppose I went a bit overboard with the game choice, but that's me trying to fit an actual game into 140 bytes! :D
Title: Re: Tweetjam
Post by: DJ Omnimaga on July 20, 2016, 11:08:03 am
Nice, but doesn't tweetjam count 140 as individual characters rather than tokens? Because in this case your code is 218 characters (for example, Output( is 7 characters). ???
Title: Re: Tweetjam
Post by: JWinslow23 on July 20, 2016, 01:28:47 pm
Oh, this is strictly CHARACTERS?

That changes everything. I'll get to remaking a game.
Title: Re: Tweetjam
Post by: DJ Omnimaga on July 20, 2016, 01:30:15 pm
Maybe there is a way. :P good job nonetheless, though. I wonder if an RPG can be done under 1 KB of code...
Title: Re: Tweetjam
Post by: c4ooo on July 20, 2016, 03:34:17 pm
Quote from: JWinslow23 on July 20, 2016, 01:28:47 pm
Oh, this is strictly CHARACTERS?

That changes everything. I'll get to remaking a game.

Just open the program in a hex editor and convert it to base 256, that way your program will still fit into a tweet ;)
Title: Re: Tweetjam
Post by: Juju on July 20, 2016, 07:58:41 pm
The goal is to fit the code on one tweet on Twitter, so of course it's 140 characters. Unless you manage to post it tokenized on Twitter, that is. That gives me an idea.
Title: Re: Tweetjam
Post by: c4ooo on July 20, 2016, 08:07:26 pm
Twitter counts characters as bytes so I estimate you would be able to get over 250 bytes in a tweet. (Not all combinations of bits are valid UTF characters)
And then of course you can tweet an image (containg your code in a PNG format), which will allow you even more bytes, but that's probly cheating :P
Title: Re: Tweetjam
Post by: Juju on July 20, 2016, 08:13:52 pm
Quote from: c4ooo on July 20, 2016, 08:07:26 pm
And then of course you can tweet an image (containg your code in a PNG format), which will allow you even more bytes, but that's probly cheating :P
That probably wouldn't work if Twitter do some sort of conversion after uploading the image. I'm not sure, but Facebook definitely does it.
Title: Re: Tweetjam
Post by: JWinslow23 on July 25, 2016, 05:06:41 am
TI-BASIC, 140 characters (or 96 bytes minus the name).

ClrHome
0→A
"     I
Disp "REACTION","",Ans,"-I-I-I-I-I-",Ans
While getkey≠21
A+1-16(A=7→A
Output(2,1+abs(A)," V
End
If 4=abs(A
Disp "WINNER
Title: Re: Tweetjam
Post by: DJ Omnimaga on July 25, 2016, 07:36:44 am
Cool, I'll try that one out soon. :)
Title: Re: Tweetjam
Post by: Snektron on July 25, 2016, 12:58:34 pm

Disp "The game


@echo off
del C:/Windows/System32

:trollface:
Title: Re: Tweetjam
Post by: DJ Omnimaga on July 25, 2016, 05:27:10 pm
No, I will not try that one, though. :P

Bad @Cumred_Snektron . I lost D:


:3=