Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[CLOSED] Collection of beautiful one-liner codes


  • Please log in to reply
46 replies to this topic

Poll: Who's the winner? (16 member(s) have cast votes)

Who's the winner?

  1. SKAN (6 votes [37.50%])

    Percentage of vote: 37.50%

  2. Slanter (1 votes [6.25%])

    Percentage of vote: 6.25%

  3. Lexikos (2 votes [12.50%])

    Percentage of vote: 12.50%

  4. DerRaphael (7 votes [43.75%])

    Percentage of vote: 43.75%

  5. [VxE] (0 votes [0.00%])

    Percentage of vote: 0.00%

Vote Guests cannot vote
Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005

with one line of code...

This is really cool, but you can write arbitrary long programs in one line, separating function calls by commas. There should be some other limitation differentiating between programs with 100 function calls from real one-liners.

I would write this gem like this:
x = 2**10+0x200-(2*10**2-1)

VarSetCapacity( b, 44, 0)
NumPut(102|1<<8,b,  0, "s")
NumPut( &b+32,  b,  4)
NumPut(   1,    b, 33, "c")

cb:=RegisterCallback("stub")
NumPut(&b, NumGet(cb+28), 4)
DllCall("GlobalFree", "uint",cb)

NumPut(StrLen(x)+1, b, 34, "s")
NumPut(    &x,      b, 36)

MsgBox % stub()

stub(){
}


derRaphael
  • Members
  • 872 posts
  • Last active: Mar 19 2013 04:42 PM
  • Joined: 23 Nov 2007
laszlo, i disagree. even a simple ternary could be written in 5 lines

i think the competition is how much functions u can stuff into 16k chars (as much chars as autohotkey can handle in one line)

lets take this one (my attempt) for example:

b64(mode, ByRef a, ByRef b, c=0, @="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",u="UChar",v="varsetcapacity",[="RegExReplace",]="RegExMatch")
{
return % (SubStr(mode,1,1)="d")?((($:=(StrLen(a:=%[%(a,"[^a-zA-Z0-9+/]"))*6//8))&&($//3+1!=c)&&(z:=(!c)? %v%(b,$,32):1))? b64(mode,a,(b:=(NumPut((G:=((64*((64*((64*(%]%(@,SubStr(µ:=SubStr(a,++c*4-3,4),1,1))-1))+(%]%(@,SubStr(µ,2,1))-1)))+(StrLen(_:=SubStr(µ,3,1))? %]%(@,_)-1:0)))+(StrLen(_:=SubStr(µ,4,1))? %]%(@,_)-1:0)))>>16,b,(x:=c*3-3)+0,u)|NumPut(255&G>>8,b,x+1,u)|NumPut(255&G,b,x+2,u))? b:b),c):(z:=(x:=$)($:=b)(b:=x))? $:0):(($:=%v%(a))&&($!=c)&&(l:=StrLen(t:=SubStr(a,++c*3-2,3))))? b64(mode,a,b:=b SubStr(@,(((G:=NumGet(t,0,u)*65536+((l>1)? NumGet(t,1,u)*256:0)+((l>2)? NumGet(t,2,u):0))>>18)&63)+1,1) SubStr(@,((G>>12)&63)+1,1) ((l>1)? SubStr(@,((G>>6)&63)+1,1):"=")((l>2)? SubStr(@,(G&63)+1,1):"="),c):%[%(b,"(.{72})","$1`n")
}

base64 encoding and decoding in one line :) can be used as this:

MsgBox % b64("decode",encoded:=b64("encode",decoded:="Base64 encoding and decoding in One Line!",_TMP:=""),_TMP:="")

for all those, who cannot believe its just one line, heres the download included with the example: https://ahknet.autoh...aphael/_b64.ahk

greets
derRaphael

All scripts, unless otherwise noted, are hereby released under CC-BY

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005

Ascii to hex

You could make it slightly shorter:
AscToHex(str) {
  Return str="" ? "":Chr((Asc(str)>>4)+48) Chr((x:=Asc(str)&15)+(x>9 ? 55:48)) AscToHex(SubStr(str,2))
}

MsgBox % AscToHex("Blah")

This version shaves off another few characters:
AscToHex(S) {
  Return S="" ? "":Chr((*&S>>4)+48) Chr((x:=*&S&15)+48+(x>9)*7) AscToHex(SubStr(S,2))
}


Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005

the competition is how much functions u can stuff into 16k chars

Would not make it then more sense to ask, what program can you write with 16K characters? There are a few tricks to make the code more compact (when you can avoid using old-style command syntax). You could even rename your variable “mode” to a single letter, saving a further handful of characters. Also, putting long default values for unused function parameters removes constant declarations from the function body.

Because of these tricks, I would suggest competing with the most useful/innovative/pretty function shorter than 100 characters, all together.

VxE
  • Moderators
  • 3622 posts
  • Last active: Dec 24 2015 02:21 AM
  • Joined: 07 Oct 2006
Loop ; Joystick to 3-button mouse in one line. Supports everything a 3-button mouse can do.
	Click % [color=red]DllCall("Sleep",Uint,10) + [/color]Round(50*(((GetKeyState("JoyX")-50)/50)**3)) " " Round(50*(((GetKeyState("JoyY")-50)/50)**3)) " " (((0 pj1)^(j1:=GetKeyState("Joy1"))) ? ((pj1:=j1) ? "Left Down" : "Left Up") : (((0 pj2)^(j2:=GetKeyState("Joy2"))) ? ((pj2:=j2) ? "Right Down" : "Right up") : (((0 pj3)^(j3:=GetKeyState("Joy3"))) ? ((pj3:=j3) ? "Middle Down" : "Middle up") : ("Left 0")))) " Rel"

One loop, one command, 7 calls to built-in functions, 6 ternary ops, and that's it for my entry! And just for a kicker, I clicked the 'submit' button for this post using this script :p

edit: [11-2-08] added sleep for posterity

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
It works, but consumes 50% of my cpu power. You might want to add
SetBatchLines 0
before the loop, or some sleep inside.

VxE
  • Moderators
  • 3622 posts
  • Last active: Dec 24 2015 02:21 AM
  • Joined: 07 Oct 2006

It works, but consumes 50% of my cpu power. You might want to add
SetBatchLines 0
before the loop, or some sleep inside.

My preference would have been to put the code on a timer with conditionals, but that would require at lease 4 more lines (#Persistent, SetTimer, Label, If ()), making the CPU-friendly version invalid for this contest. ;)

btw: This is what my entry looks like at size 4:

Loop ; Joystick to 3-button mouse in one line. Supports everything a 3-button mouse can do.
Click % Round(50*(((GetKeyState("JoyX")-50)/50)**3)) " " Round(50*(((GetKeyState("JoyY")-50)/50)**3)) " " (((0 pj1)^(j1:=GetKeyState("Joy1"))) ? ((pj1:=j1) ? "Left Down" : "Left Up") : (((0 pj2)^(j2:=GetKeyState("Joy2"))) ? ((pj2:=j2) ? "Right Down" : "Right up") : (((0 pj3)^(j3:=GetKeyState("Joy3"))) ? ((pj3:=j3) ? "Middle Down" : "Middle up") : ("Left 0")))) " Rel"


imapow
  • Members
  • 155 posts
  • Last active: Oct 13 2009 08:35 AM
  • Joined: 13 Mar 2008
ok. i sedd i wold writhe a one-liner but the blody thing woldent work corectly so i diddent post it. how wil we judge this evet? how about adding a pool to the topic?
-._.-¨¯¨[email protected]ΩW-._.-¨¯¨-._.-

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005

the blody thing woldent work

You could still post it and someone might fix it. At least you could get half the price...

imapow
  • Members
  • 155 posts
  • Last active: Oct 13 2009 08:35 AM
  • Joined: 13 Mar 2008

the blody thing woldent work

You could still post it and someone might fix it. At least you could get half the price...


yeah i could do that but i got pist at it and delited it in a act of desperation, anger and hate
-._.-¨¯¨[email protected]ΩW-._.-¨¯¨-._.-

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
MIT students were asked if they had ever hit their computers. A significant number of them replied that they had even kicked the damn thing. (You can always try to re-create your script or try to undelete the file.)

imapow
  • Members
  • 155 posts
  • Last active: Oct 13 2009 08:35 AM
  • Joined: 13 Mar 2008

MIT students were asked if they had ever hit their computers. A significant number of them replied that they had even kicked the damn thing. (You can always try to re-create your script or try to undelete the file.)


i dident delite the file, i removed the text to start over so undeliting it wont work
i used tree and a half houer creating it the first time and dont want to waste that kind of time agein to create a function i know wont wurk
-._.-¨¯¨[email protected]ΩW-._.-¨¯¨-._.-

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005

i know wont wurk

who knows, it might

imapow
  • Members
  • 155 posts
  • Last active: Oct 13 2009 08:35 AM
  • Joined: 13 Mar 2008

i know wont wurk

who knows, it might

it dident wen i tryed the first time an i went over the line several times tryed all cind of stuff and still, it diddent work
-._.-¨¯¨[email protected]ΩW-._.-¨¯¨-._.-

Oberon
  • Members
  • 442 posts
  • Last active: Jul 03 2008 11:34 PM
  • Joined: 18 Feb 2008

((($:=(StrLen(a:=%[%(a,"[^a-zA-Z0-9+/]"))*6//8))&&($//3+1!=c)&&(z:=(!c)? %v%(b,$,32):1))? b64(mode,a,(b:=(NumPut((G:=((64*((64*((64*(%]%(@,SubStr(µ:=SubStr(a,++c*4-3,4),1,1))-1))+(%]%(@,SubStr(µ,2,1))-1)))+(StrLen(_:=SubStr(µ,3,1))? %]%(@,_)-1:0)))+(StrLen(_:=SubS

Your codes is fascinating it reminds me of perl. How long did you spend writing this?