Username: 
Password: 
Restrict session to IP 

JS double-codegolf

1 2 3
Global Rank: 202
Totalscore: 101919
Posts: 65
Thanks: 67
UpVotes: 44
Registered: 15y 308d
xen`s Avatar






The User is Offline
RE: JS double-codegolf
Google/translate0Thank You!0Good Post!0Bad Post! link
nice try Smile
but rules are:
1+22+333+4444+55555+666666+7777777+88888888+999999999
without using the numbers themselves.
you must make the numbers and add them.
chmod ---x--x--x,, i'm illiterate!
Global Rank: 227
Totalscore: 93943
Posts: 1680
Thanks: 1358
UpVotes: 920
Registered: 16y 282d




Last Seen: 11s
The User is Online
RE: JS double-codegolf
Google/translate0Thank You!0Good Post!0Bad Post! link
How do you call this number sequence?
The geeks shall inherit the properties and methods of object earth.
Global Rank: 53
Totalscore: 259105
Posts: 47
Thanks: 36
UpVotes: 26
Registered: 16y 264d
alucardo`s Avatar




Last Seen: 6y 35d
The User is Offline
RE: JS double-codegolf
Google/translate0Thank You!1Good Post!0Bad Post! link
Quote from Gizmore
May 24, 2014 - 04:18:57

How do you call this number sequence?


f(x)
Global Rank: 202
Totalscore: 101919
Posts: 65
Thanks: 67
UpVotes: 44
Registered: 15y 308d
xen`s Avatar






The User is Offline
RE: JS double-codegolf
Google/translate0Thank You!0Good Post!0Bad Post! link
Quote from Gizmore
May 24, 2014 - 04:18:57

How do you call this number sequence?


i think your number sequence may be wrong Giz...
f(10) = 1+22+333+4444+55555+666666+7777777+88888888+999999999+10101010101010101010 == 10101010102107494000

#############################################
ungolfed code:
GeSHi`ed javascript code
1
2
3
4
5
function f(x)
 {
  for(s=0,i=x+1;i;s+=+Array(i).join(--i));
  return s
 }


i might be totally wrong, if so then sorry. Sad

*edit*
yeah i'm totally wrong lol!!!!
sorry guys i was rushing a bit there....
chmod ---x--x--x,, i'm illiterate!
Last edited by xen - May 28, 2014 - 19:18:07
Global Rank: 227
Totalscore: 93943
Posts: 1680
Thanks: 1358
UpVotes: 920
Registered: 16y 282d




Last Seen: 11s
The User is Online
RE: JS double-codegolf
Google/translate0Thank You!0Good Post!0Bad Post! link
I generated the values with this code:
GeSHi`ed PHP code
1
2
3
4
56
7
8
9
1011
12
 
function f($n)
{
        $fn = "0";
        for ($n = $n; $n >= 1; $n = $n - 1)        {
                $rep = str_repeat($n, $n);
                $fn = bcadd($fn, $rep);
        }
        return $fn;}
 


Edit: I assume it´s a precision problem in your code Smile
The geeks shall inherit the properties and methods of object earth.
Last edited by gizmore - May 28, 2014 - 19:19:29
Global Rank: 202
Totalscore: 101919
Posts: 65
Thanks: 67
UpVotes: 44
Registered: 15y 308d
xen`s Avatar






The User is Offline
RE: JS double-codegolf
Google/translate0Thank You!0Good Post!0Bad Post! link
written and rewritten from scratch 9 times now to make javascript handle and add as array then print as string for large numbers but each time hit a snag and give up to rewrite and repeat...

therefore my code so far if anybody wants to play about is:
GeSHi`ed javascript code
1
2
3
4
56
function f(n,s=[0]){for(l=n;n>0;n--)
{for(i=0;i<n;s[i++]+=n,s.push(0));}s.length=l
for(t=i=0;i<s.length-1;i++){
t=s[i]+"" ,t2=t.substr(0,1)*1;
s[i+1]+=t2;t3=t.substr(t.length-1,1)s[i]=t3;}return "f("+l + ") = " + s.reverse().join("")}



Giz check f(10) http://www.wolframalpha.com/input/?i=1%2B22%2B333%2B4444%2B55555%2B666666%2B7777777%2B88888888%2B999999999%2B10101010101010101010 different result?
chmod ---x--x--x,, i'm illiterate!
Global Rank: 1
Totalscore: 759079
Posts: 437
Thanks: 496
UpVotes: 469
Registered: 15y 121d












The User is Offline
RE: JS double-codegolf
Google/translate2Thank You!0Good Post!0Bad Post! link
If you look, you can see that WolframAlpha interprets 10101010101010101010 as binary. It also provides a link to have it interpreted as decimal, which results in the correct answer.

Besides properly using proper tooling, you can also quite easily see that the last digit has to be 5. (0 for 1+9, 2+8, 3+7, 4+6 and 10, which only leaves 5)
Global Rank: 202
Totalscore: 101919
Posts: 65
Thanks: 67
UpVotes: 44
Registered: 15y 308d
xen`s Avatar






The User is Offline
RE: JS double-codegolf
Google/translate0Thank You!0Good Post!0Bad Post! link
Quote from dloser
May 31, 2014 - 22:59:23

If you look, you can see that WolframAlpha interprets 10101010101010101010 as binary. It also provides a link to have it interpreted as decimal, which results in the correct answer.

Besides properly using proper tooling, you can also quite easily see that the last digit has to be 5. (0 for 1+9, 2+8, 3+7, 4+6 and 10, which only leaves 5)



i'm still not sure if your even human but thank you, what javascript would you use?
chmod ---x--x--x,, i'm illiterate!
Global Rank: 1
Totalscore: 759079
Posts: 437
Thanks: 496
UpVotes: 469
Registered: 15y 121d












The User is Offline
RE: JS double-codegolf
Google/translate0Thank You!0Good Post!1Bad Post! link
Yeah... reading and calculating with single digits... I should buy a cape. Drool

And I wouldn't use JS, if I had a choice. But if I would, it would surely not look like the stinking mess you posted. Perhaps you should first try to write proper working code before you go all code golf on it.

For your information: 10*10^0+10*10^1+10*10^2+.. is not ...101010
Also: t.substr(0,1)+t.substr(t.length-1,1) is an interesting way to split a string; I'm sure this will work for all cases.

Oh, one more thing: code golfs sucks balls! Smile
Global Rank: 202
Totalscore: 101919
Posts: 65
Thanks: 67
UpVotes: 44
Registered: 15y 308d
xen`s Avatar






The User is Offline
RE: JS double-codegolf
Google/translate0Thank You!0Good Post!0Bad Post! link
A cape that says "DL" and everyone thinks it stands for 'download'! Woot

thats not a mess sir, thats half organised broken chaos...
"t.substr(0,1)+t.substr(t.length-1,1)" was broken Smile lol
when i read your posts i have the voice of siri in mind, and you are still yet to explain how you feel about flipping a tortoise onto its back in a desert then not even gving a helping hand, why would you not?
chmod ---x--x--x,, i'm illiterate!
1 2 3
tunelko, quangntenemy, TheHiveMind, Z, balicocat, Ge0, samuraiblanco, arraez, jcquinterov, hophuocthinh, alfamen2, burhanudinn123, Ben_Dover, stephanduran89, braddie0, SwolloW, dangarbri, csuquvq have subscribed to this thread and receive emails on new posts.
1 people are watching the thread at the moment.
This thread has been viewed 16850 times.