none
Challenge of the Month - December 2011 RRS feed

  • General discussion

  • Welcome to the monthly SmallBasic Challenge!

    These challenges are intended for people who are learning to program or for more experienced programmers who want to start using SmallBasic after using a different language.  Some will be easy, some will be hard - but they will all make you think, and more importantly be GREAT FUN!

    Please post your solutions / partial solutions / questions / feedback etc. into this thread that will remain 'sticky' for the month.  The only rule is that your solution must use standard SmallBasic methods (no extensions).

    It would be good if people could post their problems with these challenges so that a discussion can start so that everyone can learn from each other.

    Easy Challenge 1

    Write a program to calculate the value of a savings account.  The input should be the initial value invested, the number of years the saving will be for, and an interest rate percent.  The output is the value of the savings at the end of the term.

    Remember compound interest!
    (http://www.moneychimp.com/articles/finworks/fmfutval.htm)

    Easy Challenge 2

    Get the Turtle to draw a Christmas tree or other festive shape (e.g. a star).

    Intermediate Challenge

    Import the following code sample (XMW920), there are a number of errors - fix these.  Most of the errors prevent the sample compiling so it should be relatively easy to identify these from the compiler error reports.  Click on these to take you to the offending line.

    There is also one other error that allows the code to run, but doesn't work as expected, so you will need to test the code.

    When all the errors are detected, the code works fine, but it is not 'good' code.  It jumps all-over-the-place using GoTo statements and is very hard to follow.

    The remainder of this challenge is to rewrite the code with a good structure using no GoTo statements if possible, using any methods you think make the code clearer (possibly Arrays, While or Subroutines etc), also comment it.

    Advanced Challenge 1

    Write a program or sequence of programs to discover the largest integer that SmallBaic can handle before it crashes.  Put another way, what is the value for 'largeNumber' written out below, such that the following line adding 1 to it causes a crash.

    TextWindow.WriteLine("This number is OK "+largeNumber)
    largeNumber = largeNumber + 1

    Supplemental, what is the significance of this number?

    Advanced Challenge 2

    How many positive integer solutions are there to this equation?

    1000+x+y+z = x*y*z

    Each solution is a set of values for x, y and z that satisfy the equation, such as x=10, y=4, z=26.

    How fast can you get SmallBasic to calculate the answer?


    Do you have an idea for a future challenge? Please post it here!

    Wednesday, November 30, 2011 7:20 PM
    Moderator

All replies

  • My entry for the hardest challenge;

     

    LargestNumber = 0
    start:
    TextWindow.Clear()
    TextWindow.Write(LargestNumber)
    File.WriteContents("C:\Users\largest.number", LargestNumber)
    LargestNumber = LargestNumber + 1
    Goto start

    It goes faster without the writing of content, but then it doesn't record the largest number.
    You'll still have to leave it for a while.

    • Edited by LMCSHERRY Wednesday, November 30, 2011 7:45 PM
    Wednesday, November 30, 2011 7:44 PM
  • LMcSherry,

    So do you know what the largest number is?

    While your program will work, it will take longer than the age of the Universe (much longer) on my PC with no TextWIndow output.

    Wednesday, November 30, 2011 7:55 PM
    Moderator
  • LMcSherry,

    So do you know what the largest number is?

    While your program will work, it will take longer than the age of the Universe (much longer) on my PC with no TextWIndow output.

    Removing TextWindow.Clear() gives a slight speed-boost.

    I will re-think/improve the speed of the program.

    EDIT: Small Basic is really slow compared to C#. I did the same challenge with some C# code, and by the time SB had got to 3000 C# was at over 10000.

    • Edited by LMCSHERRY Thursday, December 1, 2011 4:53 PM
    Wednesday, November 30, 2011 8:02 PM
  • I know that my entry to the Largest Number challenge does not follow the requested format, but, I am treating this as a learning exercise.  I have uploaded RLV949 which shows my conclusions as I struggled with this challenge.  I would appreciate any feedback nonetheless.

     

    Thursday, December 1, 2011 1:35 AM
  • My revised entry to the XMW920 challenge.

     

    'Entry in December challenge to improve XMW920.
    another = "Y"
    While another <> "N" And another <> "n"
      TextWindow.Clear()  
      count = 0  'Initialise counter
      Instructions() 'Display user instructions
      enterNumber() 'Get first number
      enterNumber() 'Get second number
      operation = " "  'Clear previous operation for multiple passes
      getOperation()  'Get Operation
      TextWindow.WriteLine(" " + num1 + " " + operation + " " + num2 + " = " + result) 'Write result
      TextWindow.WriteLine("Do you wish to perform another calculation? Y / N")
      another = TextWindow.Read()
    EndWhile
    
    Sub enterNumber  'Subroutine to get user input. with test to see if it is pass one or two (numbered 0 and 1).
      TextWindow.WriteLine("Enter a number")
      If count = 0 Then
        num1 = TextWindow.ReadNumber()
      ElseIf count = 1 Then 
        num2 = TextWindow.ReadNumber()
      EndIf
      count = count + 1  
    EndSub
    
    Sub getOperation 'Subroutine to get user input. Using while to ensure a valid operation type.  
      While (operation <> "+" And operation <> "-" And operation <> "*" And operation <> "/") 
        TextWindow.WriteLine("Enter an operation (+,-,*,/)")    
        operation = Textwindow.Read()    
        If (operation = "+") Then
          result = num1 + num2
        ElseIf (operation = "-") Then
          result = num1 - num2
        ElseIf (operation = "/") Then
          result = num1 / num2
        ElseIf (operation = "*") Then      
          result = num1 * num2    
        EndIf
      EndWhile  
    EndSub
    
    Sub Instructions  'Subroutine to display instructions.
      TextWindow.WriteLine("Please key your first number and Enter")
      TextWindow.WriteLine("Then key your second number and Enter")
      TextWindow.WriteLine("Then key the operation you wish to perform + - * /")
      TextWindow.WriteLine("")
    EndSub

    Thursday, December 1, 2011 8:02 AM
  • My answer to the Easy Challenge #1.

    My first try had the formula wrong, but this answer seems to work right.

    ' 1st try Publish code: KTP276
    ' 2nd try Publish code: VFC996

    TextWindow.WriteLine("Please enter your initial deposit:")
    principle = TextWindow.ReadNumber()
    TextWindow.WriteLine("Please enter your APR:")
    apr = TextWindow.ReadNumber()
    TextWindow.WriteLine("Please enter the number of years:")
    years = TextWindow.ReadNumber()

    futureValue = principle * Math.Power((1 + (apr * .01)), years)

    TextWindow.WriteLine("Your account:")
    TextWindow.WriteLine("  Principal: $" + principle)
    TextWindow.WriteLine("  Interest rate: " + apr + "%")
    TextWindow.WriteLine("  Number of years: " + years + " yrs")
    TextWindow.WriteLine("  Future Value: $" + futureValue)


    Allen
    Thursday, December 1, 2011 11:27 PM
  • My entry to December Easy Challenge Number 2.     I hope you consider the shape festive.

    GraphicsWindow.Width = 750
    GraphicsWindow.Height = 500
    
    Turtle.Speed = 10
    i = 40
    
    Turtle.PenUp()
    GraphicsWindow.PenWidth = 70
    Turtle.Turn(250)
    Turtle.Move(100)
    Turtle.Turn(110)
    
    
    For j = 1 to 8
      i = i - 5
      GraphicsWindow.BackgroundColor = GraphicsWindow.GetRandomColor()
      GraphicsWindow.PenColor = GraphicsWindow.GetRandomColor()
      Turtle.PenUp()
      Turtle.Turn(90)
      Turtle.Move(25)
      Turtle.TurnLeft()
      Turtle.Move(2.5)
      Turtle.PenDown()
      Draw()  
    EndFor  
    
    Sub Draw
      For a = 1 To 32
        Turtle.Move(i)
        Turtle.Turn(11.25)
      EndFor  
    EndSub

    Bert

    Friday, December 2, 2011 1:38 AM
  • Advanced Challenge   search maxnumber   MHP128 

    Push run button(F5) 15 times.  (Even if PC stops)

    Friday, December 2, 2011 4:19 AM
    Answerer
  • Intermediate Challenge -

    xmw920-0

    The original code with the bug fixes is still there, its just commented out.  That was easier for me to compare what I was doing with what I still needed when coming up with the re-write.  If you uncomment it, it will still work by itself without even getting to the re-written code.  So no need to copy & paste or anything like that.

    Does anyone know a way to doublecheck the operations input without a subroutine or a goto statement?


    Allen
    • Edited by Allen Shmallen Friday, December 2, 2011 5:06 AM forgot to mention
    Friday, December 2, 2011 4:59 AM
  • Kiwi Bert & NaochanON,

    Both good attempts and you are on the right lines, but can you tell what the largest number actually is.  You can test your value with the code below, which should cause a crash:

    largestNumber = 'Type your integer number here
    largestNumber = largestNumber+1


    Its early in the month to give any substantial clues and it is supposed to be a harder challenge so keep thinking about it!

    The number starts with a 7 and has more than 20 digits.

    Allen Shmallen,

    Very clear and good answers to simple and intermediate questions, you can use a While loop for the input testing (basically keep asking the question while the input doesn't meet the validation) - the recursion you use (calling the routine again is OK, but a While would probably be a little simpler to follow - simple is good).


    Friday, December 2, 2011 6:50 PM
    Moderator
  • Here is my entry for the Advanced Challenge.

    The largest number will be of the form 1111.......11111 in binary.
    First we need to discover the largest power of 2 that can be stored. I experimented with this code (CBV920)

    For x=0 To 95
      TextWindow.WriteLine(x + " : " + Math.Power(2,x))
    EndFor

    and found that the highest value that x could be was 95 before the program crashed.
    Therefore the largest number that can be stored is 2^95 + 2^94 + 2^93 + ... 2^2 + 2^1 + 2^0
    which I calculated with this code (MHP128-0)

    power=1
    sum=0
    For x=0 To 95
      For y=1 To x
        power=power*2
      EndFor
      sum=sum+power
      power=1 
    EndFor
    TextWindow.WriteLine("Largest Number is : " + sum)
    'TextWindow.WriteLine("Largest Number is : " + (sum+1)) This line crashes the program as the number is too big

    which gives the largest number as
    79228162514264337593543950335

    which passes litdev's test code


    TextWindow.WriteLine("This number is OK "+largeNumber)
    largeNumber = LargeNUmber + 1

    Edit: Actually that number does not seem to work with litdev's code, but it does in mine ... strange!

    My code prints out that number and then the last line will crash it when it tries to add 1 but litdev's code thinks that my number is too big before 1 is added!

     



    • Edited by rubikWizard Friday, December 2, 2011 9:14 PM
    Friday, December 2, 2011 8:51 PM
  • Perfect answer, this is 12 bytes of 8 bits each (96 bits) - 1 bit (95) for a + or - , therefore smallest number is -largestNumber.  My code was PFJ454.

    The key is that numbers are stored in binary and in chunks of 8 bits (bytes).

    Now I have to think up new tough challenge! Will post at top when I think it up.

    EDIT

    I see the same issue as rubikWizard with my own test!

    x = 79228162514264337593543950335 'crashes - strange - I never actually tried this since I assumed I knew what was going on - wrong!
    Friday, December 2, 2011 9:46 PM
    Moderator
  • The reason I wrote my own 'power' code was because using math.power seems to give severe rounding errors (see my first bit of code), whereas doing it 'manually' gave a better result. I think there must be something going on with SmallBasic changing data types from integer to floating or something, but I can't think what it is actually doing! It never seems to output numbers in standard (exponent) form when they get too big ... will have to think a bit more!
    Friday, December 2, 2011 11:38 PM
  • I see you used my question as the basis for this month's challenge. That is far beyond me as i started programming only in november. Is there actually any language that can handle infinite numbers? I have an idea for a challenge-write a program to assign seats in aeroplane.
    “Computers are like Old Testament gods: lots of rules and no mercy.” – Joseph Campbell
    Saturday, December 3, 2011 11:08 AM
  • No, most languages have a maximum number, usually it is at least 10^100, 1 with 100 zeros after it - this is a Google (company named after it).

    Challenge

    Estimate the number of cubic centimeters in the observable universe.  Speed of light is 300,000,000 meter/sec, age of Universe is about 13,000,000,000 years, 100 cm in a meter and volume is distance*distance*distance (cubed).

    Eventually it is possible to exceed the maximum number on any language I have have come across, perhaps simply with 1/0.

    When this happens most languages treat the number as undefined (infinity if you like) and call it something like NaN (Not a Number) or just crash.

    You can't really do normal arithmetic with infinity so it isn't really a problem not having it.  The number of situations where you actually need numbers bigger than 10^100 are usually quite specific and special methods will be used.

    infinity * anything = infinity

    infinity / anything = infinity

    infinity + anything = infinity

    infinity - anything = infinity

    infinity / infinity = anything

    The bigger problem is the number of digits or precision of a number, for example pi (3.141592653589..) is an infinite non-repeating series of digits which no computer can fully capture, so all calculations using it are approximate.  Usually this is fine, but some big number calculations can suffer due the the precision, just as rubikWizrad pointed out using powers (the rounding errors).

    Saturday, December 3, 2011 1:51 PM
    Moderator
  • i have the solution for the intermediate challenge, but i lost the code for it. I don't understand why that line of code(the label) prevented the multiplication and division of numbers. To me,it was just an unecessary addition that i removed last to find the solution. Is there an explanation for it?
    “Computers are like Old Testament gods: lots of rules and no mercy.” – Joseph Campbell
    Saturday, December 3, 2011 6:06 PM
  • keg504,

    There were no unnecessary lines in this challenge sample code - there were some deliberate errors but no whole lines that should be removed.

    Because it was so badly written with all the GoTo statements out of order and no comments is is hard to decipher and easily can lead to confusion or making errors editing the code, hence the second part of the challenge to rewrite in a much better way so the code does the same thing but is much easier to understand and follow.

    PS to all

    New advanced challenge added at top of thread.

    Saturday, December 3, 2011 6:28 PM
    Moderator
  • No, most languages have a maximum number, usually it is at least 10^100, 1 with 100 zeros after it - this is a Google (company named after it).


    Actually 10^100 is called a googol (different spelling) and a googolplex is 10^googol (which is quite a large number!!!)
    Saturday, December 3, 2011 10:18 PM
  • Challenge

    Estimate the number of cubic centimeters in the observable universe.  Speed of light is 300,000,000 meter/sec, age of Universe is about 13,000,000,000 years, 100 cm in a meter and volume is distance*distance*distance (cubed).

    So are we looking to calculate the volume of the sphere of light from the Big Bang, in which case the volume would be (4/3)*pi*r^3 ?
    Saturday, December 3, 2011 10:22 PM
  • i have the solution to the intermediate challenge = vzg671. I'm not sure if thats exactly what you wanted, but i think that's what the program is supposed to do. as for the quoted challenge, the volume of the universe is 7.79295685x10^78(assuming the universe expanded equally in all directions).
    “Computers are like Old Testament gods: lots of rules and no mercy.” – Joseph Campbell
    Sunday, December 4, 2011 9:48 AM
  • keg504,

    For the intermediate challenge you have corrected all the errors and ordered the code well.  Can you write it with no GoTo statements.  GoTo's are generally considered bad programming practice because the can lead to unreadable spaghetti code like the challenge sample, although the odd GoTo can be very useful.

    Your answer for the size of the observable universe looks about right - I got 7.8*10^84 cm^3, perhaps the difference is cm^3 rather than m^3.  They are still much smaller than a Googol (now spelt right), but bigger than SmallBasic can cope with.  The actual universe may actually be infinite or at least very much bigger than anything we can possibly observe with the speed of light limit.

    The correct formula is that of a sphere as you used, but given other approximations or assumptions (age of the universe, speed of light has always been constant, even that a sphere is the correct shape to use for Universe scales where General Relativity or something else may distort geometry and others) a cube would be reasonable, the difference only being a factor of about 2 (6/pi).  The important number is the number of zeros (84 give or take) not the value 7.8.

    Sunday, December 4, 2011 1:12 PM
    Moderator
  • I removed all the goto statements changed the loop to while with the following lines:

    TextWindow.WriteLine("Would you like to end the program?[yes/no]")

    end = TextWindow.Read()

    While end = no

    (main program)

    EndWhile

    Is there any way to make this code more efficient, as in it keeps asking you if you want to end?


    “Computers are like Old Testament gods: lots of rules and no mercy.” – Joseph Campbell
    Monday, December 5, 2011 11:21 AM
  • keg504,

    Can you post a publish code for the full program please, sine the segment above shouldn't keep repeating the question sine it is outside the main while loop.

    Monday, December 5, 2011 6:28 PM
    Moderator
  • keg504,

    Can you post a publish code for the full program please, sine the segment above shouldn't keep repeating the question sine it is outside the main while loop.

    TextWindow.WriteLine("Would you like to end the program?[yes/no]: ")
    end = TextWindow.Read()
    while end = "no"
    TextWindow.PauseIfVisible()
    TextWindow.Clear()
    TextWindow.WriteLine("Enter a number")
    num1 = TextWindow.ReadNumber()
    TextWindow.WriteLine("Enter another number")
    num2 = TextWindow.ReadNumber()
    getOperation:
    TextWindow.WriteLine("Enter an operation (+,-,*,/)")
    operation = Textwindow.Read()
    If operation = "+" Then
      result = num1 + num2
     ElseIf operation = "-" Then
      result = num1 - num2
    ElseIf operation = "/" Then
      result = num1 / num2
    ElseIf operation = "*" Then
      result = num1 * num2
    Else
      Program.End()
    EndIf
    TextWindow.WriteLine(num1 + operation + num2 + "=" + result)
    EndWhile

    “Computers are like Old Testament gods: lots of rules and no mercy.” – Joseph Campbell
    Tuesday, December 6, 2011 12:27 PM
  • The TextWindow.PauseIfVisible() is pausing the window, delete this - to ask the question after every sum, try the following:

    end = "no"
    while end = "no"
      'TextWindow.PauseIfVisible()
      TextWindow.Clear()
      TextWindow.WriteLine("Enter a number")
      num1 = TextWindow.ReadNumber()
      TextWindow.WriteLine("Enter another number")
      num2 = TextWindow.ReadNumber()
      getOperation:
      TextWindow.WriteLine("Enter an operation (+,-,*,/)")
      operation = Textwindow.Read()
      If operation = "+" Then
        result = num1 + num2
      ElseIf operation = "-" Then
        result = num1 - num2
      ElseIf operation = "/" Then
        result = num1 / num2
      ElseIf operation = "*" Then
        result = num1 * num2
      Else
        Program.End()
      EndIf
      TextWindow.WriteLine(num1 + operation + num2 + "=" + result)
      TextWindow.WriteLine("Would you like to end the program?[yes/no]: ")
      end = TextWindow.Read()
    EndWhile


    Tuesday, December 6, 2011 7:11 PM
    Moderator
  • Thanks, it worked like a charm

    “Computers are like Old Testament gods: lots of rules and no mercy.” – Joseph Campbell

    Edit: would it be possible to use a for loop in this case and are there any other loops than the goto, the for and the while?

    • Edited by keg504 Friday, December 9, 2011 11:08 AM
    Wednesday, December 7, 2011 12:00 PM
  • My entry in the December Advanced Challenge 2.   It ran for 2831 seconds on my Win 7 32 bit quad core i5 PC and found 48 solutions.  I would be most interested in any tips to improve the speed.

    start = Clock.Hour * 3600 + Clock.Minute * 60 + Clock.Second
    For x = 1 To 1050
      For y = 1 To 1050
        For z = 1 To 1050
          mult = x*y*z
          calc = 1000 + x + y + z
          If calc = mult Then
            Count = Count + 1
            TextWindow.WriteLine((" x = ") + x + "   " + ("y = ") + y + "   " + (" z = ") + z)
          EndIf
        EndFor
      EndFor
    EndFor
    end = Clock.Hour * 3600 + Clock.Minute * 60 + Clock.Second
    elapsed = end - start
    TextWindow.WriteLine("Found " + Count + " occurances in " + elapsed  + " Seconds")

    Bert 

    Thursday, December 15, 2011 9:03 PM
  • Congratulations, you have the right answer!

    There are many things you can do to improve the performance, perhaps by a factor of about 100000 by careful thought.

    Things to consider are:

    1] For any given x and y we can calculate z and then check if it is an integer. 'If (z = Math.Floor(z)) Then'

    2] Use symmetry (we can exchange any of x,y,z and the problem is the same) So if we find x,y,z, then y,x,z is also a solution.  So we only need to check for y >= x and when we find a solution x,y,z then y,x,z is also a solution.  If x=y has a solution, then there is not a second distinct solution.

    3] We can prove that z decreases as x or y increase and conversely z increases as x or y decrease

    4] If we find a value for z using [1] that is less than 1 then we can stop checking the current y using [3]

    5] We can prove using [3] what the largest and second largest values can possibly be so we can skip all values for x or y that lie between these two.

    6] We can prove that x=y=1 cannot have a solution for z

    Start by rewriting the equation z = ... This is the biggest key.  Then try putting in a few values by hand such as x=y=1, x=1 & y=2, x=1 & y=3, x=2 & y=2 etc.  Try to prove some of these.

    • Edited by litdevModerator Thursday, December 15, 2011 10:35 PM Simplify and clarify
    Thursday, December 15, 2011 9:35 PM
    Moderator
  • Hi litdev

    I´ve posted  yesterday my BWN338 program.

    Didn´t you received it ?

    Regards,

     


    carlosfmur
    Sunday, December 18, 2011 1:04 PM
  • carlosfmur,

    Just seen it now - very festive - Merry Christmas.

    Sunday, December 18, 2011 4:20 PM
    Moderator
  • Many thanks, litdev
    carlosfmur
    Sunday, December 18, 2011 7:24 PM
  • NVD600 -0  Christmas tree and other festive shape .

    A song is added.
    Wednesday, December 21, 2011 1:55 PM
    Answerer
  • Nice, really...very nice
    carlosfmur - Buenos Aires
    Wednesday, December 21, 2011 3:45 PM
  • Not sure if this is the right place to post it, but I have an idea for a "hard" challenge for Jan 2012.

    Any entrants to the hard challenge should attempt to create something like a basic compression method, and have a threshold for size. E.g. it must make the file a minimum of 10% smaller.

    But I don't know, maybe it's too hard?
    I think a rule would have to be "No Extensions", so people can't just use the compression method in Data extension. 

    There should also be sub-challenges; how fast can you make it? How high can you make the compression ratio? How small can you make the executable? Et cetera.
    • Edited by LMCSHERRY Thursday, December 22, 2011 4:40 PM
    Thursday, December 22, 2011 4:36 PM
  • This is the right place - thanks for the suggestion.

    Can you also provide a sample of reasonable size text (say ~0.1MB) file (uploaded somewhere to compress).  Since at one extreme a very large file just filled with 0s can be compressed very easily and a similar large file filled with random numbers cannot be compressed smaller than the original (if you include the compression algorithm in the size of the compressed file). 

    If you have other challenge ideas including basic ones, then compile them together and post them as next month's challenge towards the end of the year and I will make it the sticky for Jan 2012.

    Thursday, December 22, 2011 6:35 PM
    Moderator
  • Possibly some code, or WPF XAML?

    How about using this sample of XAML from an application I was making that reads specifications (hence the names):

                <TabItem Header="Processor" Name="tabItem1" IsSelected="False" IsEnabled="True" Background="{x:Null}">
                    <Grid>
                        <Label Content="Name" Height="28" HorizontalAlignment="Left" Margin="6,6,0,0" Name="label1" VerticalAlignment="Top" Width="48" />
                        <Rectangle HorizontalAlignment="Left" Margin="60,10,0,212" Name="rectangle1" Stroke="Black" Width="403" Fill="#FFE2E2E2" Height="20" />
                        <Label Content="null" Height="28" Margin="60,6,26,0" Name="processorNameLabel" VerticalAlignment="Top" />
                        <Label Content="Manufacturer" Height="28" HorizontalAlignment="Left" Margin="6,36,0,0" Name="label3" VerticalAlignment="Top" />
                        <Rectangle Fill="#FFE2E2E2" Height="20" HorizontalAlignment="Left" Margin="90,40,0,182" Name="rectangle2" Stroke="Black" Width="48" />
                        <Label Content="null" Height="28" Margin="90,36,331,0" Name="processorManufacturerLabel" VerticalAlignment="Top" />
                        <Label Content="Core #" Height="28" HorizontalAlignment="Left" Margin="144,36,0,0" Name="label2" VerticalAlignment="Top" />
                        <Rectangle Fill="#FFE2E2E2" Height="20" HorizontalAlignment="Left" Margin="195,40,0,182" Name="rectangle3" Stroke="Black" Width="29" />
                        <Label Content="0" Height="28" HorizontalAlignment="Left" Margin="196,36,0,0" Name="processorCoreNumberLabel" VerticalAlignment="Top" />
                        <Label Content="Thread #" Height="28" HorizontalAlignment="Left" Margin="231,36,0,0" Name="label4" VerticalAlignment="Top" />
                        <Rectangle Fill="#FFE2E2E2" Height="20" HorizontalAlignment="Left" Margin="292,40,0,182" Name="rectangle4" Stroke="Black" Width="29" />
                        <Label Content="0" Height="28" HorizontalAlignment="Left" Margin="292,36,0,0" Name="processorThreadNumberLabel" VerticalAlignment="Top" />
                        <Label Content="IHT" Height="28" HorizontalAlignment="Left" Margin="327,36,0,0" Name="label5" VerticalAlignment="Top" />
                        <Rectangle Fill="#FFE2E2E2" Height="20" HorizontalAlignment="Left" Margin="361,40,0,0" Name="rectangle5" Stroke="Black" Width="38" VerticalAlignment="Top" />
                        <Label Content="No" Height="28" HorizontalAlignment="Left" Margin="361,36,0,0" Name="processorHasHyperthreadingLabel" VerticalAlignment="Top" />
                        <Label Content="Revision" Height="28" HorizontalAlignment="Left" Margin="29,65,0,0" Name="label6" VerticalAlignment="Top" />
                        <Rectangle Fill="#FFE2E2E2" Height="20" HorizontalAlignment="Left" Margin="90,69,0,153" Name="rectangle6" Stroke="Black" Width="48" />
                        <Label Content="U/A" Height="28" HorizontalAlignment="Left" Margin="90,66,0,0" Name="processorRevisionLabel" VerticalAlignment="Top" />
                        <Label Height="28" HorizontalAlignment="Left" Margin="154,65,0,0" Name="label7" VerticalAlignment="Top" Content="Type" />
                        <Rectangle Fill="#FFE2E2E2" Height="20" HorizontalAlignment="Left" Margin="196,69,0,153" Name="rectangle7" Stroke="Black" Width="51" />
                        <Label Content="U/A" Height="28" HorizontalAlignment="Left" Margin="196,66,0,0" Name="processorBitLabel" VerticalAlignment="Top" Width="51" />
                        <Label Content="Clock Speed" Height="28" HorizontalAlignment="Left" Margin="8,130,0,0" Name="label8" VerticalAlignment="Top" />
                        <Rectangle Fill="#FFE2E2E2" Height="20" HorizontalAlignment="Left" Margin="90,134,0,88" Name="rectangle8" Stroke="Black" Width="74" />
                        <Label Content="null" Height="28" HorizontalAlignment="Left" Margin="90,130,0,0" Name="processorClockSpeedLabel" VerticalAlignment="Top" Width="74" />
                        <Label Content="Base Clock" Height="28" HorizontalAlignment="Left" Margin="16,155,0,0" Name="label9" VerticalAlignment="Top" />
                        <Rectangle Fill="#FFE2E2E2" Height="20" Margin="90,159,306,63" Name="rectangle9" Stroke="Black" />
                        <Label Content="null" Height="28" HorizontalAlignment="Left" Margin="90,155,0,0" Name="processorBaseClockLabel" VerticalAlignment="Top" Width="74" />
                        <Label Content="Multiplier" Height="28" HorizontalAlignment="Left" Margin="22,179,0,0" Name="label10" VerticalAlignment="Top" />
                        <Rectangle Fill="#FFE2E2E2" Height="20" HorizontalAlignment="Left" Margin="90,183,0,39" Name="rectangle10" Stroke="Black" Width="74" />
                        <Label Content="null" Height="28" HorizontalAlignment="Left" Margin="90,179,0,0" Name="processorMultiplierLabel" VerticalAlignment="Top" Width="74" />
                        <Label Content="L2 Cache" Height="28" HorizontalAlignment="Left" Margin="179,130,0,0" Name="label11" VerticalAlignment="Top" />
                        <Rectangle Fill="#FFE2E2E2" Height="20" HorizontalAlignment="Left" Margin="243,134,0,88" Name="rectangle11" Stroke="Black" Width="65" />
                        <Label Content="0 KB" Height="28" Margin="243,130,161,0" Name="processorL2CacheLabel" VerticalAlignment="Top" />
                        <Label Content="L3 Cache" Height="28" HorizontalAlignment="Left" Margin="180,155,0,0" Name="label12" VerticalAlignment="Top" />
                        <Rectangle Fill="#FFE2E2E2" Height="20" HorizontalAlignment="Left" Margin="243,159,0,63" Name="rectangle12" Stroke="Black" Width="65" />
                        <Label Content="0 KB" Height="28" Margin="244,155,161,0" Name="processorL3CacheLabel" VerticalAlignment="Top" />
                        <Label Content="Voltage" Height="28" HorizontalAlignment="Left" Margin="257,64,0,0" Name="label21" VerticalAlignment="Top" />
                        <Rectangle Fill="#FFE2E2E2" Height="20" HorizontalAlignment="Left" Margin="314,69,0,153" Name="rectangle21" Stroke="Black" Width="51" />
                        <Label Content="null" Height="28" HorizontalAlignment="Left" Margin="315,66,0,0" Name="processorVoltage" VerticalAlignment="Top" />
                    </Grid>
    


    According to Windows, that's 5.96KB.

    .TXT Download here

    Thursday, December 22, 2011 7:02 PM
  • Good example for compression.  It would be a tough challenge, but perhaps we can add some simpler challenges that involve some of the elements required to solve this like: find repeating texts, count repeating texts, parse a text file etc and perhaps find some web sites on compression to help.  Have a think on it.
    Thursday, December 22, 2011 9:31 PM
    Moderator
  • Oh yes litdev

    Add some simpler challenges, please.

    Many of us are beginners. Isn´t Small Basic for beginners?.

    Welcome and thanks people with high level. I´m learning each day with them. They help me, always.

    But, how many of member´s forum would follow posts/ threads

    Thanks again and regards


    carlosfmur - Buenos Aires
    Friday, December 23, 2011 1:41 AM
  • Good example for compression.  It would be a tough challenge, but perhaps we can add some simpler challenges that involve some of the elements required to solve this like: find repeating texts, count repeating texts, parse a text file etc and perhaps find some web sites on compression to help.  Have a think on it.

    A simpler challenge, using the above XAML, could be to locate and write down all the keywords, and perhaps the total number of them? For example:

    "<Label> Occurs __ Times"

    Friday, December 23, 2011 10:55 AM
  • Hello litdev, perhaps you can consider the following
    This may be a simple challenge to develop. It was solve with MS Excel.
    A company manufactures two types of tiles. Type A has the form of a
    trapezium of bases to 15 cm and 5 cm and its height is 10 cm
    Type B has the shape of parallelogram whose bases measure 14 cm and height 8 cm
    Determine the total cost of labor which is calculated by the square centimetres of tiles produced. In the month of January were 2,500 tile type A at a cost of $5.00 per square centimeter and 3,500 tile type B at a cost of $2,00 per square centimeter.
    In February production increases by 50% over January and maintained  costs per unit.
    In short we need
    -Find the area of the trapezium and the parallelogram to calculate the area of each of the tiles.
    Calculate the monthly cost of labour for the months of January and February for each type of tile
    Calculate the total monthly cost of labour for the months of January and February.
    Thank you very much for your attention

    carlosfmur - Buenos Aires
    Sunday, December 25, 2011 2:45 PM
  • Some possible solutions to intermediate and harder challenges: LTP633, WJB650, SVK916.
    Saturday, December 31, 2011 6:32 PM
    Moderator
  • *jaw drops!*

     

    I ventured back into some c++ (was trying to learn it before) and entered in Kiwi Bert's solution...

    The difference from sb to c++?  The program ran in about 5 seconds!  I'd heard that speed was a big difference between some languages, but I've never seen such an example of it.

    Just thought I'd share that :)


    Allen
    Monday, January 2, 2012 4:28 AM
  • Allen,

    Inspired by you, I also rewrote my entry in the challange in C++.   I have dabbled with C++ over time with some limited success, but I feel I would need another 100 years to come half-way to mastering it.  When I first ran it it ran for 20 odd seconds but found over 17000 false positives.  I looked at the code and could not see where I had gone wrong, it looked like the exact equivilent of the SB code.  I had defined x, y, and z as int and mult and calc as double. I figured that x, y, and z, never got bigger than 1050, but , because I could not think of anything else I changed them to double, recompiled it  and it ran correctly in about the same time you achieved.

    Thank you for the thought.

    Regards

    Bert

    Tuesday, January 3, 2012 6:21 AM
  • Although some SmallBasic code is very slow compared to something like C++, a lot of performance issues can be overcome with good coding - this challenge could be solved in SB in about 25 ms (~200 times faster than C++ doing it the long way) - very fast languages can actually result in very inefficient code because we don't see the inefficiencies immediately.

    So the challenge was not so much about highlighting the speed of SB, as suggesting that how we define algorithms and the thought required before coding something is often more important, it was an advanced challenge.
    Tuesday, January 3, 2012 12:17 PM
    Moderator
  • I got it down to 2 seconds and 8 solutions with this code, but i'm still trying to figure out how to apply the part about making the equation into a 'z = ...' form.   edit:  or the part about using math.floor().

    xLim = 3000

    start = Clock.Hour * 3600 + Clock.Minute * 60 + Clock.Second
    For x = 1 To xLim
      For y = x To xLim
        For z = y To 1050
          mult = x*y*z
          calc = 1000 + x + y + z
          If calc = mult Then
            Count = Count + 1
            TextWindow.WriteLine((" x = ") + x + "   " + ("y = ") + y + "   " + (" z = ") + z)
            xLim = z
          EndIf
        EndFor
      EndFor
    EndFor
    end = Clock.Hour * 3600 + Clock.Minute * 60 + Clock.Second
    elapsed = end - start
    TextWindow.WriteLine("Found " + Count + " occurances in " + elapsed  + " Seconds")


    Allen
    Wednesday, January 11, 2012 6:47 AM
  • 1000 + x + y + z = x*y*z

    1000 + x + y = z*(x*y - 1)

    z = (1000 + x + y) / (x*y - 1)

    Here we can see that x=y=1 has no solution for z.

    A full solution using this was posted as SVK916.

    Wednesday, January 11, 2012 10:48 AM
    Moderator
  • First of all you don't need "largenumber = 0"

    Second of all you don't need to clear the Textwindow every time just make it TextWindow.Writeline

     

    Saturday, January 21, 2012 12:34 PM