## Really cool Lego robots

Following from the post on Lego marble runs, here you will find a some videos of really cool #Lego #robots (and some more marble runs). +1 geek experience points for all the programmers and creators.

As awesome as they come

Lego car factory, wheelchair, rubix cube solver, gun and more

Cool Lego floor cleaning robot

Lego Coffee vending machine...

...and tea maker

Bridging robot

Sudoku solver

The sort of music that robots listen to

#lego #robots

## Shakespearean Insult Generator

Introducing the Shakespearean Insult Generator - thou puking bat-fowling puttock!

 Press the button, insult your friends.

This insult generator is based on Shakespeare Insult Kit which is widely attributed to an English teacher from Center Grove High School in Greenwood Indiana named Jerry Maguire. I have not seen a statement by Mr. Maguire regarding intellectual property, but I (and many others who use his list) assume that it is in the public domain.

Bored already? Check out the Tabloid News Generator, or the Random Movie Generator.

#insults
#shakespeare

## What time is it (as a hexadecimal background colour)?

A short program that displays the current time as a hexadecimal background colour.  Source code is below, or you can download the executable for Windows.

 Time is displayed as a hex colour (or 'color' if you prefer the incorrect American spelling)

REM Hex colour clock
REM T Street
REM 2015-03-22
REM based on idea by http://whatcolourisit.scn9a.org/

MODE 10: OFF
PROC
_preventResize
COLOUR 2, 180,180,180
REPEAT

REM get the current time

a\$ =  RIGHT\$(TIME\$,8)

REM find hexidecimal rgb

r\$ = MID\$(a\$, 1, 2)
g\$ = MID\$(a\$, 4, 2)
b\$ = MID\$(a\$, 7, 2)

REM find denary colour value

red%   = VALLEFT\$(r\$,1)*16 + VALRIGHT\$(r\$,1)
green% = VALLEFT\$(g\$,1)*16 + VALRIGHT\$(g\$,1)
blue%  = VALLEFT\$(b\$,1)*16 + VALRIGHT\$(b\$,1)

REM clear the screen to required colour

COLOUR 1, red%, green%, blue%
COLOUR 1+128:CLS

REM display time

COLOUR 2
*font Arial, 16b
PRINTTAB(30,6)"The time is"
*font Arial, 60b
PRINTTAB(05,2)r\$":"g\$":"b\$
*font Arial, 32b
PRINTTAB(07,7)"The colour is #"r\$g\$b\$

REM wait a mo'

OSCLI "refresh"
WAIT 100
OSCLI "refresh off"
UNTIL FALSE

DEF PROC_preventResize
REM prevent user resizing window

PRIVATE ws%
SYS "GetWindowLong", @hwnd%, -16 TO ws%
REM prevent user maximising window

SYS "SetWindowLong", @hwnd%, -16, ws% AND NOT &50000
ENDPROC

## A feast of awesome Lego train sets

+1 geek experience point for all the contributors

Some Arduino controlled train sets

Space Lego train given suitable sci-fi editing

Longest Lego train world record attempts

A full Lego city

Lego Mindstorms sliding doors

Mindsotrms Lego train

Getting Candy - the long version

#arduino #lego #mindstorms

An ISBN number is a unique identification number for commercial books.  The listing below is for an ISBN-13 validation program in BBC BASIC.  If a valid book number is found the program then performs a Google search (probably bringing up a link to Amazon.com - not that they really need the support).

The algorithm works as follows:

1. Each of the first 12 digits starting from the left to right, is multiplied by 1 or 3 alternatively.
2. The sum of the products modulo 10 gives us either zero or a number between 1 to 9.
3. Subtract the number from 10 and it gives us the checksum.

REM ISBN-13 Validator program
REM T Street
REM 2015-03-19

INSTALL @lib\$+"stringlib"
REM main program loop

REPEAT
PRINT
'"ISBN-13 validator."
PRINT "------------------"'
REPEAT
INPUT
"Enter a 13 digit ISBN number : " isbn\$

isbn\$ = FN_convertInput( isbn\$ )

UNTIL LEN(isbn\$)=13

IF FN_validISBN13( isbn\$ ) THEN
PRINT
"VALID ISBN-13 - opening your browser..."
SYS "ShellExecute",@hwnd%,0,"https://www.google.co.uk/search?q=ISBN "+isbn\$, 0, "", 1
ELSE
PRINT
"INVALID ISBN-13 :-("
ENDIF
UNTIL FALSE

DEFFN_validISBN13( num\$ )
REM validates an isbn number
REM pass a 13 digit string as parameter
REM returns true if the string represents a valid ISBN-13
REM
REM Each digit, starting from the left to right, is multiplied by 1 or 3 alternatively.
REM The sum of the products modulo 10 gives us either zero or a number between 1 to 9.
REM Subtract the number from 10 and it gives us the checksum.

LOCAL i% : REM iterator

LOCAL calcCheck% : REM running calculation

LOCAL checksum%  : REM checksum

LOCAL multiplier% : multiplier% = 3
i% = 1
WHILE i%<13
calcCheck% = calcCheck% + VAL(MID\$(num\$, i%, 1))
i% += 1
calcCheck% = calcCheck% + VAL(MID\$(num\$, i%, 1)) * multiplier%
i% += 1
ENDWHILE

calcCheck% = calcCheck% MOD 10

checksum% = 10 - calcCheck%

IF checksum% = VAL(RIGHT\$(num\$,1)) THEN

TRUE
ENDIF

FALSE

DEFFN_convertInput( astring\$ )
REM pass an ISBN-13 number as a string
REM removes any spaces or dashes
REM which are sometimes located
REM in ISBN numbers
REM returns the string with dash/space removed

LOCAL a\$ : a\$ = astring\$
IF FN_findreplacei( a\$, "-""", 0)
IF FN_findreplacei( a\$, " """, 0)
= a\$

#isbn #bbcbasicforwindows #algoithms

## Reading a text file into a string byte by byte

A BBC BASIC demo showing byte-by-byte input from a file.

The following demo takes a single text file as input and reads it into a single string variable.  The work is done by the bget# function which reads a single byte from the file and adds it to the string.

 My test file used for input.  We shall read this in byte by byte (carriage returns and all)
 The program running.  Here we decided to do something useful with the data, ie split it up into  individual records.

REM reading an entire file into a string
REM and outputing one line at a time
REM T Street
REM 2015-03-18

INSTALL @lib\$+"stringlib" : REM used by the split function

fulltext\$ = "" : REM string to hold all the input

CRLF\$ = CHR\$(13)+CHR\$(10) : REM carriage return line feed

DIM eachline\$(1) : REM array to store each line of the input
REM I don't know how big this should be yet

REM read the input file into the string
REM -----------------------------------

infile% = OPENIN("textfile.txt")
WHILE NOT(EOF#infile%)
REM read each byte from the text file
REM and convert to ASCII character
REM append to the text string

fulltext\$ += CHR\$(BGET#infile%)
ENDWHILE

REM now we have the full text file in a single string

PRINT "The full text is"
PRINT "----------------"
PRINT fulltext\$
PRINT "----------------"

REM split the textfile at the carriage returns
REM to create an array
REM we can then do what we like with the array

parts% = FN_split( fulltext\$, CRLF\$, eachline\$() )

PRINT "There are "STR\$(parts% DIV 3)" record(s) in the file"

n% = 0
WHILE n% < parts%
PRINT "-------------------------"
PRINT "RECORD #"STR\$(n% DIV 3+1)
PRINT "Dinoaur : ", eachline\$(n%)
n% += 1
PRINT "name means '" eachline\$(n%) "'"
n% += 1
PRINT "length : " eachline\$(n%)
n% += 1
PRINT
ENDWHILE

 Diplodocus - spending his days one bite to the next.

## Castle Grim

Back in the early nineties, and long before I had a home computer to entertain me, I used to follow the adventures of Sir Eric the Unready and his adventures in Castle Grim to retrieve 'a stolen amulet'.  created by G Harvey, the series appeared in a leading UK broadsheet weekend newspaper (I forget which one) and each week featured a new puzzle.

Presented here are some of the Castle Grims that I have managed to keep for over twenty years.  I hope a new generation of kids can enjoy Sir Eric's adventures.

 The first ever Castle Grim.

 Apologies for the Tipex-TM on this one.  Thanks to Richard for providing it.

## A whole load of linear search algorithm videos

The linear search: a simple algorithm for searching for something.  It is what you do when you are searching for a matching sock in your sock drawer.  Nevertheless, students find it difficult to code, so presented here is a load of videos to help.

In its simplest form, the linear search is as follows.

i = 0         // the first item in your list
found = false // you haven't found it yet
answer = null // you haven't found it
while i < numberOfItems and not(found)
if currentItem(i) == theThingYouAreLookingFor then
found = true  // you found it
answer = i    // the position of the thing
else
i ++          // increment i
endif
endwhile

In English:

Look through all the items in your list in turn, from the start, until you find the one you are looking for.  There are two ways a linear search can end: either you find the thing (so you stop searching), or you check everything and don't find it.

#linearSearch #algorithms

dd

## Kids Code with SHAPES (part two)

Last time I posted some SHAPES code written by year 7 children.  Today I am posting some code written by year 6 children.  The one major difference here is that the year 6 children have been shown how to create subroutines - reusable patterns that can be invoked over and over.

Children did find this task difficult as the use of subroutines necessarily requires the use of relative coordinates, rather than absolute coordinates.  For example:

moveto(x,y)
colour green
circle huge
colour yellow
moveby (-200, 100)
circle small

The code fragment describes the positioning of the large green circle, followed by a movement of the cursor by negative 200 units (move by 200 left), and positive 100 units vertically.  This positions the left eye of the dog.

 The dog subroutine invoked several times with random parameters.

Here, the main program invokes the random subroutine (100 times).  The random subroutine invokes the dog subroutine by passing random parameters to it.  The dog subroutine displays the dog on the screen at the coordinates passed as parameters.

@@main program
{
[ ]
@random (100)

}

@@random
{
[x,y]
x:= rnd 1600
y:= rnd 1400
@dog [x,y]
wait 20
}

@@dog [x,y]
{
[ ]
moveto(x,y)
colour green
circle huge
colour yellow
moveby (-200, 100)
circle small
colour yellow
moveby (400, 0)
circle small
colour white
moveby (-400, 0)
circle tiny
colour white
moveby (400, 0)
circle tiny
colour blue
moveby (-200, -150)
circle small
colour cyan
moveby (10, -200)
circle medium
colour seagreen
moveby (200, 550)
square medium
colour seagreen
moveby (-550, 0)
square medium
colour lime
moveby (50, 0)
square small
colour lime
moveby (550, 0)
square small
}

 Subroutines invoked with fixed parameters.

Here the snowman subroutine has been invoked four times using fixed parameters.

@@main program
{
[ ]
fill royalblue
@snowman[100,508]
@snowman[1300,503]
@snowman[900,506]
@snowman[500,503]
}
@@ snowman[x,y]
{
[  ]
moveto(x,y)
moveby (100,-65)
colour white
circle huge
moveby (0,505)
colour white
circle big
moveby (90,55)
colour black
circle small
moveby (-170,0)
colour black
circle small
moveby (190,-110)
colour black
circle tiny
moveby (-40,-40)
colour black
circle tiny
moveby (-55,-20)
colour black
circle tiny
moveby (-55,20)
colour black
circle tiny
moveby (-50,25)
colour black
circle tiny
moveby (100,-220)
colour black
circle small
moveby (0,-140)
colour black
circle small
moveby (0,-140)
colour black
circle small
moveby (0,-140)
colour black
circle small
}

#shapes
#codinginschools