#41✎ 922snail_HelperReceived for being very helpful around SmileBASIC SourceAchievementsOSP Contest 2 Contest ParticipantI participated in the second SmileBASIC Source OSP Contest!Night PersonI like the quiet night and sleep late.Express YourselfThis doesnt return a string which could cause an error. Allow me to improve that for you.
DEF RND$()
RETURN FORMAT$("%D",RNDF())
END
Posted
#42✎ 961Y_ackHead AdminThe last answer returned a string which might have numbers in it, which might cause erroneous behavior if the caller does not expect numbers in a string. Allow me to improve that for you.
Edit: I messed up!
DEF RNDWOD$()
VAR S$ = FORMAT$("%F",RNDF())
VAR I = 0, C$
WHILE I < LEN(S$)
C$ = S$[I]
'remove char if it is a digit
IF C$>="0"&&C$<="9" THEN S$[I]="" ELSE INC I,1
WEND
RETURN S$
END
Posted
Edited
by Y_ack
#43✎ 166512Me21Head AdminThird YearMy account is over 3 years oldWebsiteSyntax HighlighterReceived for creating the code syntax highlighter on SBSNight PersonI like the quiet night and sleep late.Express YourselfVAR PI$=STR$(PI())
VAR I
'Returns the next digit of pi when called
DEF RND$()
INC I
I=I%LENGTH(PI$) 'make sure the index doesn't exceed the length of PI$
RETURN PI$[I]
END
'get the length of a string
DEF LENGTH S$
VAR I
WHILE MID$(S$,I,1)!="" 'MID$ returns an empty string when out of range
INC I
WEND
RETURN I
END
Posted
#44✎ 373ChemicalexDrawingI like to draw!HobbiesRNGHiddenEaster EggsThird YearMy account is over 3 years oldWebsiteDoes it have to be Smile🅱️asic code?
Posted
#45✎ 317spaceturtlesVideo GamesI like to play video games!HobbiesAvatar BlockI didn't change my avatar for 30 days.WebsiteIntermediate ProgrammerI can make programs, but I still have trouble here and there. Programming Strengthnah just get a random string like this:
DEF RNDS()
RETURN INPUT
END
or Lua:
local a = "" function rndString(_len) for i = 1, math.random(_len) do a..string.char(math.random(255)) end return a end
Posted
Edited
by spaceturtles
#46✎ 166512Me21Head AdminThird YearMy account is over 3 years oldWebsiteSyntax HighlighterReceived for creating the code syntax highlighter on SBSNight PersonI like the quiet night and sleep late.Express Yourself
nah just get a random string like this:
DEF RNDS()
RETURN INPUT
END
That doesn't even work
Posted
#47✎ 317spaceturtlesVideo GamesI like to play video games!HobbiesAvatar BlockI didn't change my avatar for 30 days.WebsiteIntermediate ProgrammerI can make programs, but I still have trouble here and there. Programming Strength
nah just get a random string like this:
DEF RNDS()
RETURN INPUT
END
That doesn't even work
the idea does?
Posted
#48✎ 166512Me21Head AdminThird YearMy account is over 3 years oldWebsiteSyntax HighlighterReceived for creating the code syntax highlighter on SBSNight PersonI like the quiet night and sleep late.Express Yourself
this is 🅱️ode 🅱️ritique, not 🅱️idea 🅱️ritique
Posted
#49✎ 317spaceturtlesVideo GamesI like to play video games!HobbiesAvatar BlockI didn't change my avatar for 30 days.WebsiteIntermediate ProgrammerI can make programs, but I still have trouble here and there. Programming Strength
this is 🅱️ode 🅱️ritique, not 🅱️idea 🅱️ritique
English with emotes isn't a programming language
Posted
#50✎ 166512Me21Head AdminThird YearMy account is over 3 years oldWebsiteSyntax HighlighterReceived for creating the code syntax highlighter on SBSNight PersonI like the quiet night and sleep late.Express YourselfCan someone please help improve my sorting function? It's too slow...
DEF SORT_ARRAY (ARRAY[] )
DIM NEW [0]
FOR J = 0 TO LEN(ARRAY) -1
FOR I=0 TO LEN(ARRAY) - 1
IF ARRAY[I] == MIN(ARRAY) THEN
PUSH NEW, ARRAY[I]
ARRAY[ I] = MAX( ARRAY )
BREAK
ENDIF
NEXT
NEXT
RETURN NEW
END
Posted
Edited
by 12Me21
#51✎ 961Y_ackHead Admin'sort an array, javascript style, with some lewd easter eggs
DEF jsSort(A[])
DIM N$[0], E$
WHILE LEN(A)
'valentine's day edition <3
IF (A[0]||0)<3 THEN
PUSH N$,STR$(POP(A))
ELSE
PUSH N$,POP(A)
ENDIF
'valentine's day edition OWO
FOR I = LEN(N) -1 TO 1 STEP -1
IF N$[I] <= N$[I-1] THEN
SWAP N$[I], N$[I-1]
ELSE
BREAK
ENDIF
NEXT
WEND
RETURN N$
END
Posted
#52✎ 453kenchicFirst YearMy account is over 1 year oldWebsiteBeginner ProgrammerI'm just starting out! I'm still trying to grasp the basics.Programming Strengthosu! Is Awesome!I love osu!Express Yourself'please dont use 0.00199
DEF NORT(INP[])
DIM RET[LEN(INP)],RES,W,V
FILL RET,0.00199
FOR I=0 TO LEN(INP)-1
RES=0
W=INP[I]
FOR _I=0 TO LEN(INP)-1
V=INP[_I]
INC RES,ABS(0.5+ABS(W-V)/(2*(W-V))*(W-V)/(W-V))
NEXT
IF RET[RES]==INP[I] THEN
REPEAT
INC RES
UNTIL RET[RES] != INP[I]
ENDIF
RET[RES]=INP[I]
NEXT
RETURN RET
END
Posted