Search found 47 matches

by ganache
Sep 24, 2021 5:28
Forum: General
Topic: list comprehensions in FB?
Replies: 5
Views: 1053

list comprehensions in FB?

I know that FB doesn't have any built-in syntax for list comprehensions like python or
some functional programming languages.
But can they be simulated. Examples would be nice.
by ganache
Feb 15, 2021 8:44
Forum: Sources, Examples, Tips and Tricks
Topic: Guess what the output of this code is?
Replies: 4
Views: 1132

Guess what the output of this code is?

Here is some code from a golf code challenge, that I translated to FB.

Code: Select all


  Dim As Integer i, j, k
  for i=-8 to 8
  for j=-8 to 9
  k=abs(i)+abs(j)
  if k > 8 then
  print " ";
  else
  print chr(57-k); 
  end if 
  next j
  print
  next i
  Sleep
  End
  
[code]

Run it!
by ganache
Oct 06, 2020 6:06
Forum: Beginners
Topic: Convert vbscript to FB
Replies: 10
Views: 2085

Convert vbscript to FB

Hi, how do I translate this to FB with messagebox

Code: Select all

num1=Cint(InputBox("Enter the no. of rotten apples: "))
num2=Cint(InputBox("Enter the total no. of apples: "))
msgbox ( "The percentage is:" & num1/num2*100 &"%")
by ganache
Nov 06, 2019 6:13
Forum: General
Topic: count of digits in large number
Replies: 5
Views: 1098

Re: count of digits in large number

thanks guys for the suggestions. But it seems that the log method is incorrect. Tried it in c. The code below works for numbers that fit into the largest numeric data type supported by FB. After that I guess the integers start to overflow... Dim As Ulongint number Dim As Integer count input "En...
by ganache
Nov 05, 2019 9:21
Forum: General
Topic: count of digits in large number
Replies: 5
Views: 1098

count of digits in large number

here is some code works in c language function countDigit(n As Ulongint) As Integer return INT(log(10(n)) + 1) end function Dim As Integer n input "Enter number: ";n print countDigit(n) Sleep But compiler says expected '' ( " in return statement. No matter how i try to balance the bra...
by ganache
Jul 24, 2019 9:09
Forum: Game Dev
Topic: Chaze in the Maze (Demo)
Replies: 2
Views: 5807

Re: Chaze in the Maze (Demo)

Very nice work JJFlash!
But how to control the white asterix? Pressing arrow keys does not affect the movement. It is random movement, right?
by ganache
Jul 24, 2019 8:51
Forum: Beginners
Topic: remove duplicates (repeat) characters/letters from a string
Replies: 7
Views: 6260

Re: remove duplicates (repeat) characters/letters from a string

Thank you fxm. But suppose I want the second string (i.e. s2) to be appended with * (asterix or star character) to indicate that the rest of the characters are duplicates.How do i do that ? I tried adding a print "*" after If s1[i] = s2[j] Then duplicate = True But that didn't work. by the...
by ganache
Jul 24, 2019 7:05
Forum: Beginners
Topic: remove duplicates (repeat) characters/letters from a string
Replies: 7
Views: 6260

remove duplicates (repeat) characters/letters from a string

Hi, how to remove duplicates from a string?
What if string is randomly generated?
see code

Code: Select all

Dim As String s(49) ' string has 50 characters
Dim As Integer i, c
Randomize Timer
for i=0 to 49
c=INT(RND(1) +26 
list(i)=CHR(c+65) 'upper case letters
print list(i);
next i
Sleep
by ganache
Nov 05, 2018 4:32
Forum: General
Topic: Print string as x pattern
Replies: 2
Views: 789

Re: Print string as x pattern

Thanks, srvaldez. The sub and printPattern seem to be throwing up a few errors. But anyways, thanks. I'll see if I can resolve the issues.
by ganache
Nov 02, 2018 14:27
Forum: General
Topic: Print string as x pattern
Replies: 2
Views: 789

Print string as x pattern

My attempt Dim As String s Dim As Integer i, j Input " enter string with odd no of characters:",s For i = 0 to len(s)-1 For j = 0 to len(s) - 1 If i = j or i + j =len(s) - 1 then Print chr(i), ' semicolon Else Print " ", End if Next j Next i Sleep There will be a point of interse...
by ganache
Jan 03, 2018 6:07
Forum: Sources, Examples, Tips and Tricks
Topic: GCD(Greatest Common Divisor) of two numbers
Replies: 3
Views: 1134

Re: GCD(Greatest Common Divisor) of two numbers

In fact, knowing the GCD, we can also find the LCM(Least Common Multiple) Here is a complete program that will find both GCD and LCM of two numbers. declare function gcd(p As Integer, q As Integer) As Integer declare function lcm(p As Integer, q As Integer) As Integer Dim As Integer p, q ' recursive...
by ganache
Jan 03, 2018 5:50
Forum: Sources, Examples, Tips and Tricks
Topic: GCD(Greatest Common Divisor) of two numbers
Replies: 3
Views: 1134

GCD(Greatest Common Divisor) of two numbers

' Program to find GCD(Greatest Common Divisor) of two numbers.

Code: Select all

declare function gcd(p As Integer, q As Integer) As Integer
Dim As Integer p, q

' recursive Euclidean algorithm
function gcd(p As Integer, q As Integer) As Integer
if q = 0 then
return p
end if
return gcd(q, p mod q)
end function

by ganache
Dec 02, 2017 5:29
Forum: Community Discussion
Topic: Passing command line arguments to FB programs
Replies: 20
Views: 4458

Re: Passing command line arguments to FB programs

Add arguments together as numbers(integers)... Dim As Integer i=0, sum=0 Do Dim As String arg = Command(i) If Len(arg) = 0 Then Exit Do print "command line argument " & i & " = """ & arg & """" i += 1 sum+= val(Command(i)) ' val is us...
by ganache
Nov 30, 2017 6:03
Forum: Community Discussion
Topic: Passing command line arguments to FB programs
Replies: 20
Views: 4458

Re: Passing command line arguments to FB programs

argc and argv are macros in FreeBASIC Joshy Yes, those are macros. But I am talking of non-macro usage perhaps. An example: Dim As Integer i = 0 Dim As String arg = command(1) print "Hello ";command(1); " how are you?" Sleep Run like this: if program name is helloarg.exe then ty...