FORMULA CHALLENGE shortest wins !

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
Hi, everyone !!
just a little idea

In this threadwe came up with some formulas to get a random character choosen from
a, b, c ... z, A, B, C, ... Z, 0, 1, 2 ... 9
so 62 possibilities

wouldn't it be nice to make a little sport of it :-D

the one who generates the shortest formula, may launch the next formulachallenge

OBJECTIF
GENERATE randomly 1 LCASE or UCASE or INTEGER
rules:
1. formula in english
2. acurate = all characters must occur about as much as the others when formula is tested (for instance 20000 times, copied down or "evaluate"-macrotest)
3. posts must be generated within 7 days (168 hours) from now
4. no replies with comments about the other formulas
5. jury = moderators ?

what do you think ?

kind regards,
Erik
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Actually,
When I delete the hard returns from my formula (which I just like to use for readability), the formula is 86 characters long, or two shorter than the formula using Mid.


=CHAR(INT(CHOOSE(MATCH(RAND(),{0,10,36}/62),10*RAND()+47,26*RAND()+64,26*RAND()+96))+1)
 
Upvote 0
Although I agree a native function would probably be better, there is nothing in the rules that prohibits add-ins:

1. formula in english
2. acurate = all characters must occur about as much as the others when formula is tested (for instance 20000 times, copied down or "evaluate"-macrotest)
3. posts must be generated within 7 days (168 hours) from now
4. no replies with comments about the other formulas
5. jury = moderators ?
 
Upvote 0
As per Barrie's formula above, you don't need INT.....

=CHAR(CHOOSE(MATCH(RAND(),{0,10,36}/62),10*RAND()+48,26*RAND()+65,26*RAND()+97))
 
Upvote 0
Shorter still at 70 characters:

Code:
=CHAR(INDEX(RAND()*{10;26;26}+{48;65;97},MATCH(RAND(),{0,10,36}/62),1))

[edit] 68 Characters:
Code:
CHAR(INDEX(RAND()*{10;26;26}+{48;65;97},MATCH(RAND(),{0,10,36}/62)))
 
Upvote 0
I was also looking for a shorter way - I didn't consider INDEX - very nice :)

...tiny bit shorter..

=CHAR(INDEX(RAND()*{10;26;26}+{48;65;97},MATCH(RAND(),{0,5,18}/31)))

:wink:
 
Upvote 0
A bit shorter :

=CHAR(LOOKUP(RAND(),{0,5,18}/31,RAND()*{10;26;26}+{48;65;97}))
 
Upvote 0
Hi, guys,

I'm testing the formulas this way:
(if you want a copy of the workbook just email me)
copy 20000 times to sheet (
Code:
Sub paste_formula()
Range("formulas").Formula = ActiveCell.Formula
End Sub
generate a sheetcalculation just by copying the counts for 1 loop of each character to the general count
Range("results_once").Copy
Range("results_loops").PasteSpecial Paste:=xlPasteValues, Operation:=xlAdd

Code:
Sub test()
Dim j As Integer
Dim loops As Integer

loops = Application.InputBox("how many loops of 20.000 formula-tests?" & Chr(10) & "MAX: 500", "LOOPS", "10")
If loops > 500 Then loops = 500

With Application
.ScreenUpdating = False
    For j = 1 To loops
    Application.StatusBar = "total loops to do :" & loops & " ... loops done:" & j - 1
    Range("results_once").Copy
    Range("results_loops").PasteSpecial Paste:=xlPasteValues, Operation:=xlAdd
    Next j
    Application.StatusBar = False
.CutCopyMode = False
.ScreenUpdating = True
End With
End Sub

part of the results using Teachers formula (68 characters "=" not counted)
formulachallenge.xls
BCDEFGHIJK
2generateitemsappearedafter loopstestslowesthighest
3Wa331809441,619%50000007987981540
4Bb342798791,598%1,598%1,631%
59c358801271,603%difference
6Zd307805841,612%1661
71e337805691,611%2,02%
8sf315807151,614%
93g316808011,616%ideal
10Nh321815401,631%1,613%
test


kind regards,
Erik
 
Upvote 0
Hello, guys,

the original rules were
1. formula in english
2. acurate = all characters must occur about as much as the others when formula is tested (for instance 20000 times, copied down or "evaluate"-macrotest)
3. posts must be generated within 7 days (168 hours) from now
4. no replies with comments about the other formulas
5. jury = moderators ?
after one week no valid answer was given, in fact there was only one answer
after a little bump from my side you were coming up with answers
so rule 3. was not applied
rule 4. was perhaps not a good one ?
5. jury ? if everybody agrees bosco_yip is the winner using 61 characters (=sign not counted) then we don't need a jury
I let run a macro to do 10.000.000 tests (500 - 20.000) and the result was OK, as you could all see looking to the formula :huh:
Code:
tests	   lowest	highest
10000000	160255	162047
           1,603%   1,620%

if nobody has an objection ...
bosco_yip, are you ready to invent a new formula-challenge?
What's the shortest formula to ...


kind regards,
Erik
(offline for a week starting 24 hours from now)
 
Upvote 0
How about this?? I think this should pass your test.
A little different thinking process.

=CHAR(IF(RAND()<10/62,RAND()*10+48,N(RAND()>.5)*32+RAND()*26+65))

64 characters
 
Upvote 0

Similar threads

Forum statistics

Threads
1,223,896
Messages
6,175,264
Members
452,627
Latest member
KitkatToby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top