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
heresy
  • Members
  • 291 posts
  • Last active: Sep 26 2008 10:47 PM
  • Joined: 11 Mar 2008
Hello Community.
i've prepared a personal event for community to thank and just for fun
if you have any idea for next challenge's goal let me know
hope you guys have fun with it.


EVENT CLOSED



The Goal :
Write any one-liner code that is creative and effective.
Laszlo's base conversion function is good example.
if you prefer function form, will not count function header
Function(args) ;not count it
{              ;not count it neither
  Return "This will be counted"
}              ;not count it neither
Limitation of code :
None.

Limitation of participation :
You have to participate with registered name.
so we can communicate privately when you won.

Event Duration :
Until May. 31 (Sat)

Event Cancellation :
If participants are less than five.

How the winner gets selected :
audience will tell who's the winner except code is stolen one

What Winners Get :
Desired domain name with 1 year registration.
supports standard domain name extensions such as .com/net/org/cc/us/bz/eu...
Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com

derRaphael
  • Members
  • 872 posts
  • Last active: Mar 19 2013 04:42 PM
  • Joined: 23 Nov 2007
i'll participate :)

who else takes the challenge?

greets
derRaphael

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

imapow
  • Members
  • 155 posts
  • Last active: Oct 13 2009 08:35 AM
  • Joined: 13 Mar 2008
not so good at AHK yet but i can trye

[edit] hey this is my 100th post. cool.
-._.-¨¯¨[email protected]ΩW-._.-¨¯¨-._.-

ahklerner
  • Members
  • 1386 posts
  • Last active: Oct 08 2014 10:29 AM
  • Joined: 26 Jun 2006
i'm game
Posted Image
ʞɔпɟ əɥʇ ʇɐɥʍ

trik
  • Members
  • 1317 posts
  • Last active: Jun 11 2010 11:48 PM
  • Joined: 15 Jul 2007
I'm in, let's see what you guys got.
Religion is false. >_>

VxE
  • Moderators
  • 3622 posts
  • Last active: Dec 24 2015 02:21 AM
  • Joined: 07 Oct 2006
I'll give it a whirl, but it would be nice if there were judging criteria (like, what the code is supposed to accomplish?).

>>. do label lines count? (I'm assuming not since function header and brace lines are not counted)

I'll also point out the ternary operator guide link in my sig for anyone interested :D

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

The Goal :
Write any one-liner code that is creative and effective.


I could have participated if it had been generally about short code..
One-liner is not my area .. I guess only Laszlos or Titans would win.

:)

heresy
  • Members
  • 291 posts
  • Last active: Sep 26 2008 10:47 PM
  • Joined: 11 Mar 2008
Sorry for being not so clear. i'm not good at these things but it's very beginning.
as i mentioned pm me if anyone have ideas for next challenges
i can't think of any other seductive goal
btw, here's my one-liner

MsgBox, Show us your card shy girls :)

Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Here is my take:

Null compression algorithm for hex data:

Loop 20
  StringReplace,Hex,Hex,% SubStr("000000000000000000000",A_Index),% Chr(70+21-A_Index),All

what is does:
When we include a binary file as inline hex, it could occupy a lot of space.
The code given can compress the zeroes thereby making the hex compact

The algorithm is as follows:
Hex data uses 0-9 and A thru F which leaves us characters G thru Z

The code searches for:
20 zeroes and replaces it with "Z"
19 zeroes and replaces it with "Y"
18 zeroes and replaces it with "X"
.. and loops on and finally finds
2 zeroes and replaces it with "G"

Decompression:
It is the same procedure with parameter 3 and 4 swapped

Loop 20
  StringReplace,Hex,Hex,% Chr(70+21-A_Index),% SubStr("000000000000000000000",A_Index),All

I use a better three-line version which offers tighter compression rate. This code is for the topic sake.

:)

derRaphael
  • Members
  • 872 posts
  • Last active: Mar 19 2013 04:42 PM
  • Joined: 23 Nov 2007
hey skan ... i always wondered how a one-liner can be used to make a run-time-length encryption ... good one!

greets
derRaphael

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

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

Here is my take:

Null compression algorithm for hex data:

Loop 20
  StringReplace,Hex,Hex,% SubStr("000000000000000000000",A_Index),% Chr(70+21-A_Index),All


dosent loop count as a line??
like


Function(args) ;not count it
{              ;not count it neither
  Loop 20 ;This will be counted
   StringReplace,Hex,Hex,% SubStr("000000000000000000000",A_Index),% Chr(70+21-A_Index),All ;This will be counted
}              ;not count it neither

-._.-¨¯¨[email protected]ΩW-._.-¨¯¨-._.-

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

dosent loop count as a line??

I'd vote no on that, because it's so similar to a recursive function call. i.e.:
Function( CountDown )
{
   Send % (CountDown>0 ? Function( CountDown-1 ) : "blearghghgh")
}
would essentially just call the function X times.

Also, a Q for heresy: does the code have to be useful? or can it be utterly useless yet amusingly diverting ?

heresy
  • Members
  • 291 posts
  • Last active: Sep 26 2008 10:47 PM
  • Joined: 11 Mar 2008

dosent loop count as a line??

sorry for missing clear judgement. loop header will not be counted too.
just feel free to enjoy. since it's very beginning and just for fun. i don't want to make it so tight

does the code have to be useful? or can it be utterly useless yet amusingly diverting ?

The Goal : Write any one-liner code that is creative and effective.

was i too vague? i wished that my word choicing was effective
i'll prepare another event for all the gay codes but not for this time

hope this small event would be a present for community. not vague or complicated problem
Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com

Slanter
  • Members
  • 739 posts
  • Last active: Jul 08 2011 05:26 AM
  • Joined: 28 May 2008
Ascii to hex, though it uses laszlo's code for base change with minor edits so that might disqualify me :p

Anyway, here it is
AscToHex(str,chr=1,n=0,mode=0)
{
   Return !mode ? (AscToHex(1,chr,asc(SubStr(str,chr,1)),1) . (chr < StrLen(str) ? AscToHex(str,chr+1) : "")) : ((n < 16 ? "" : AscToHex(1,chr,n//16,1)) . ((d:=mod(n,16)) < 10 ? d : Chr(d+55)))
}
Usage
AscToHex("Blah")


Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
Dynamically evaluate any expression (without variable references or function calls) with one line of code:
MsgBox % v, x:=[color=green]"2**10+0x200-(2*10**2-1)"[/color], 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), v:=stub()
stub(){
}
:lol: