So you've downloaded the swi-prolog package from http://www.swi-prolog.org/Download.html and you need to run it.
It runs in the terminal but you need to run, opt/local/bin/swipl
If you have a folder with your file in, e.g. Download/myfile.pl then why not navigate to that folder in terminal before running swipl. That way you can edit and create files easily in your editor of choice and load the file easily in SWI-prolog.
By the way, to load a file type, ['my file.pl'].
You can, if you want, run the PCEemacs editor. You'll want to do this sooner or later.
To run this you should type, emacs.
It may ask you to load X11. Just follow the instructions.
Wednesday, April 24, 2013
Sunday, January 20, 2013
Saturday, January 5, 2013
A grid where rows, columns and diagonals are equal
My son showed me trick where I chose a number between 20 and 99 (inclusive) and he would then create a 4-by-4 grid of numbers where all the numbers would equal that number.
I thought I would write the algorithm. I thought it might be interesting for him to see how how a computer program worked. I thought C# would be easy so I used Mono on the mac.
[Main.cs]
[NumberGrid]
using System;
namespace AllWaysAddUp
{
public class NumberGrid
{
private int[,] _grid;
{
_grid = new int [4,4] {{-1, 1, 12, 7} , {11, 8, -1, 2} ,{5, 10, 3,-1} ,{4,-1, 6, 9}} ;
}
public int GetCell(int rowNumber, int columnNumber)
{
return _grid[rowNumber, columnNumber];
}
public void calculate(int number)
{
_grid[0,0] = number -20;
_grid[1,2] = _grid[0,0] - 1;
_grid[3,1] = _grid[0,0] + 1;
_grid[2,3] = _grid[3,1] + 1;
}
}
}
I thought I would write the algorithm. I thought it might be interesting for him to see how how a computer program worked. I thought C# would be easy so I used Mono on the mac.
[Main.cs]
using System;
namespace AllWaysAddUp
{
class MainClass
{
private static NumberGrid _numberGrid;
public static void Main (string[] args)
{
Console.WriteLine ("Enter a number between 20 and 99 and this will calculate"+ '\n' +
"a grid of 4 rows and 4 columns where all the rows, columns"+ '\n' +
"and diagonals all add up to that number"+ '\n' + '\n'+
"Enter a number between 20 and 99...");
string s = Console.ReadLine();
int i;
if(!int.TryParse(s, out i))
Console.WriteLine("You did not enter a number");
else {
if( i < 20 || i > 99)
Console.WriteLine("Number not in range. Number must be between 20 and 99.");
else {
_numberGrid = new NumberGrid();
_numberGrid.calculate(i);
PrintNumberGrid();
}
}
Console.ReadLine();
}
private static void PrintNumberGrid()
{
for (int row = 0; row < 4; row++) {
Console.WriteLine();
for (int col = 0; col < 4; col++) {
int num = _numberGrid.GetCell(row, col);
Console.Write (" {0}" + '\t', num.ToString());
}
}
}
}
}
{
public class NumberGrid
{
private int[,] _grid;
// Array format: {row0 col0, row0 col1, row0 col2, row0 col3 }
// {row1 col0, row1 col1, row1 col2, row1 col3 }
// {row2 col0, row2 col1, row2 col2, row2 col3 }
// {row3 col0, row3 col1, row3 col2, row3 col3 }
public NumberGrid (){
_grid = new int [4,4] {{-1, 1, 12, 7} , {11, 8, -1, 2} ,{5, 10, 3,-1} ,{4,-1, 6, 9}} ;
}
{
return _grid[rowNumber, columnNumber];
}
{
_grid[0,0] = number -20;
_grid[1,2] = _grid[0,0] - 1;
_grid[3,1] = _grid[0,0] + 1;
_grid[2,3] = _grid[3,1] + 1;
}
}
}
How to test memory in OSX
If your are experiencing an occasional random rebooting then maybe there is a memory gremlin.
A pretty good old-school memory test can be done by downloading memtest and installing it, then starting your Mac in command line mode (single user mode), and then running memtest.
Multiple tests?
:/ root# memtest all 5
(Running 5 times took over 5 hours)
Example Output
Memtest version 4.22 (64-bit)
Copyright (C) 2004 Charles Cazabon
Copyright (C) 204-2008 Tony Scaminaci (Macintosh port)
Licensed under the GNU General Public Licence version 2 only
Max OS X 10.8.2 (12C60) running in single user mode
Memory Page Size: 4096
System has 2 Intel core(s) with SSE
Requested memory: 3864MB (4052697088 bytes)
Available memory: 3864MB (4052697088 bytes)
NOTE: Memory request is too large, reducing to acceptable value...
Allocating memory: 3756MB (3939221568 bytes) at local address 0x0000000101000000
Attempting memory lock...locked successfully
Partitioning memory into 2 comparison buffers...
Buffer A: 1878MB (196910784 bytes) starts at local address 0x0000000101000000
Buffer B: 1878MB (196910784 bytes) starts at local address 0x000000017665e020
Running 5 test sequences... (CTRL-C to quit)
Test sequence 1 of 5:
Running tests on full 3756MB region...
Stuck Address : ok
Linear PRN : ok
Running comparison tests using 1878MB buffers...
Random Value : ok
Compare XOR : ok
Compare SYB : ok
Compare MUL : ok
Compare DIV : ok
Compare OR : ok
Compare AND : ok
Sequential Increment: ok
Solid bits : ok
Block Sequential : ok
Checkerboard : ok
Bit Spread : ok
Bit Flip : ok
Walking Ones : ok
Walking Zeroes : ok
A pretty good old-school memory test can be done by downloading memtest and installing it, then starting your Mac in command line mode (single user mode), and then running memtest.
- Download memtest
- Install. It will be placed in /usr/bin/
- Shut down the mac and restart keeping the cmd and s keys depressed. It will boot into single user mode.
- Run memtest by typing, memtest all
Where to get memtest
It can be found in a few places and I have used it from here before, http://www.optilabs.eu/download/memtest_422.zip
Multiple tests?
memtest all n
:/ root# memtest all 5
(Running 5 times took over 5 hours)
Example Output
Memtest version 4.22 (64-bit)
Copyright (C) 2004 Charles Cazabon
Copyright (C) 204-2008 Tony Scaminaci (Macintosh port)
Licensed under the GNU General Public Licence version 2 only
Max OS X 10.8.2 (12C60) running in single user mode
Memory Page Size: 4096
System has 2 Intel core(s) with SSE
Requested memory: 3864MB (4052697088 bytes)
Available memory: 3864MB (4052697088 bytes)
NOTE: Memory request is too large, reducing to acceptable value...
Allocating memory: 3756MB (3939221568 bytes) at local address 0x0000000101000000
Attempting memory lock...locked successfully
Partitioning memory into 2 comparison buffers...
Buffer A: 1878MB (196910784 bytes) starts at local address 0x0000000101000000
Buffer B: 1878MB (196910784 bytes) starts at local address 0x000000017665e020
Running 5 test sequences... (CTRL-C to quit)
Test sequence 1 of 5:
Running tests on full 3756MB region...
Stuck Address : ok
Linear PRN : ok
Running comparison tests using 1878MB buffers...
Random Value : ok
Compare XOR : ok
Compare SYB : ok
Compare MUL : ok
Compare DIV : ok
Compare OR : ok
Compare AND : ok
Sequential Increment: ok
Solid bits : ok
Block Sequential : ok
Checkerboard : ok
Bit Spread : ok
Bit Flip : ok
Walking Ones : ok
Walking Zeroes : ok
Saturday, November 17, 2012
NSLog Format Specifiers
These formatters are used with NSLog, and also Logging.h mentioned in a previous post. Take a look.
Examples:
(1)
int num=9;
NSLog(@"The value of the integer is %i", num);
Result: The value of the integer is 9
(2)
NSDate *today= [NSDate date];
NSLog(@"the date is %@",today);
Result: the date is 2012-11-17 01:15:00 +0000
%d, %i signed int %u unsigned int %f float or double %e float or double in standard form or scientific notation %x hex int %X hex int %o octal int %c character %C unichar %@ object
Examples:
(1)
int num=9;
NSLog(@"The value of the integer is %i", num);
Result: The value of the integer is 9
(2)
NSDate *today= [NSDate date];
NSLog(@"the date is %@",today);
Result: the date is 2012-11-17 01:15:00 +0000
Monday, November 12, 2012
How to add an existing Xcode project to Source control
If you create a project in Xcode and later you want to add it to source control then you need to run a couple of command line controls. But it's easy.
1. Quit Xcode.
2. Open terminal and navigate to your directory. Using something like:
3. Type the find command to find the file file.
4. Place the file name into an exclude file.
This will create the file gitignore
5. Initialise Git
6. Add the files
7. Commit the files to the repository
Problem with Git?
Are you getting the command not found?
1. Quit Xcode.
2. Open terminal and navigate to your directory. Using something like:
cd Developer/myprojectnameThere is a file in Xcode that we do not want to add to source control. This records the Xcode environment state. Because we're doing this adding manually, we have to tell Git manually to ignore it. If we had told Xcode to add the project to source control when we created the project it would have ignored this file automatically.
3. Type the find command to find the file file.
find .The file we are looking for is UserInterfaceState.xcuserstate
4. Place the file name into an exclude file.
echo myproject.xcodeproj/project.xcworkspace/xcuserdata/John.xcuserdatad/UserInterfaceState.xcuserstate >.gitignore
This will create the file gitignore
5. Initialise Git
git initDid you get an error? (See bottom of post)
6. Add the files
git add .
7. Commit the files to the repository
git commit -m "write a short comment here"
Problem with Git?
Are you getting the command not found?
bash: git: command not foundThis can be solved by:
- Open Xcode
- Open Preferences
- Chose the Downloads tab, choose components
- Instal the Command line tools.
Bob's your uncle.
Saturday, November 10, 2012
How & why incentives do not work
Firstly, if you have 18 minutes to spare, then rather than read this, go and watch Dan Pink's video at TED.com. It really is food for thought.
In short, Dan says that proof exists to support the statement that incentives - the carrot or the sharp stick - do not work.
They do not work in many types of work. Not all, but most that we are likely to deal with.
But, and here's an interesting thing. Not only do they not work, they actually do harm. They give the opposite of the desired effect.
The candle problem
Dan starts by looking at the the candle problem.
If you give people the following: a candle, a box of pins and some matches, and you then ask them to fix the candle to the wall so that the lit candle's wax doesn't drip onto the table. How could this be done? and do they perform?
(A clue. To solve this you over come functional fixedness)
Do incentives work
If you incentivise this task, i.e. if you give a group incentives such as, 'if you're the fastest you'll get £50, if you're in the top 10% you'll get £20'. Then you get interesting results. (these £ values were not the ones used in the quoted experiement but I have adjusted for inflation :). I'm sure the experiment holds)
The team that were given the financial incentives actually did a lot worse, and this is not a freak of this experiment or of this challenge. There are many more examples and experiments that back this up.
The solution to the candle problem?
It is at the bottom of the blog page.
Restate the problem and...
If you restate the problem as in this diagram and still give incentives, then the incentives make a significant difference. They have the desired effect and deliver an improvement in performance.
I think it's clear to see why when you realise the pins are no longer in the tray that was being used to collect them together.
So incentives appear to work for mechanistic, well defined tasks, but not for jobs that require creative thought. If the work is clearly defined and has an easy to see goal then the incentives work. It is almost as if the value of the incentive narrows the focus through a fear of losing the sweet carrot or money, or fear of meeting the pointy end of the stick.
This kind of left-brain work seems ideally suited to incentives but more and more our work is right-brain - creative, inventive.
A couple of quotes:
As long as the task involved only mechanical skill, bonuses worked as they would be expected: the higher the pay , the better the performance.
But once the task called for "even rudimentary cognitive skill," a larger reward "led to poorer performance."
D. Ariely, U. Gneezy, G. Lowenstein, & N. Mazar, Federal Reserve Bank of Boston Working Paper No. 05-11, July 2005; NY Times, 20 Nov. 08
Autonomy - Mastery - Purpose
If we can no longer motivate using incentives or threats then what can motivates?
Dan suggests:
Autonomy - the urge to direct our own lives
Mastery - to get better and better at something
Purpose - the urge to be a art of something bigger than ourselves.
Traditional management
Management is a recent concept and it did not emanate from nature. It's an invention from mankind. It's ideal for compliance but it does not mean that it's always right. Maybe, at times, we need to rethink the management styles based on the three themes above.
I currently work in a very traditional environment and have found myself in a team of dispirited developers that distrust management, distrust each other, and are distrusted by management. I'm stuck in the middle as a Development Manager. My approach has been to apply two themes to improve things. One, traditional management - that is, clearly manage the tasks, the projects and the list of work. Senior management folk like that and the developers do too. The estimates are still off a bit but we can work on that.
The other theme is non-traditional. I encourage Mastery and Autonomy in the way I treat developer tasks and collaboration. I expand their range of influence and never pass on their successes as my own up the traditional management line. I motivate by letting them motivate themselves.
Warning. Senior management don't get this. Not mine anyway and that's probably why my days will be numbered. But I'll keep on trying. It's the only right way.
The answer.
Friday, November 9, 2012
Pages 4.2 not linking to iCloud - This is not your primary account
I have Pages on my iPad and Mac mini, and also my iMac. But I have recently upgraded the OS on my Mac Book Pro to Mountain Lion and Pages and Numbers don't connect to iCloud.
I checked the version of Pages - 4.2. So that should be ok.
I tried to update it from App store and of course it said don't be silly.
I went to iCloud in System Preferences and signed in. All I saw was the oportunity to select Mail, Contacts, Calendars and Notes. What I really wanted was shown below.
The iCloud form told me that I was not logged in with my primary account. But I was.
The task is to delete the iCloud account from the Preferences and log in again.
To do this un-tick the Contacts, Calendars and Notes. Try to untick Mail but it might complain.
If it does complain go to mail and remove the mail account.
Then go to Preferences again and untick the Mail. Now remove the iCloud account by using the "-".
Now add your iCloud account and ensure you tick "Documents & Data".
Now go to Pages etc and when you start it should let you look at your iclid files.
Just the ticket.
I checked the version of Pages - 4.2. So that should be ok.
I tried to update it from App store and of course it said don't be silly.
I went to iCloud in System Preferences and signed in. All I saw was the oportunity to select Mail, Contacts, Calendars and Notes. What I really wanted was shown below.
The iCloud form told me that I was not logged in with my primary account. But I was.
The task is to delete the iCloud account from the Preferences and log in again.
To do this un-tick the Contacts, Calendars and Notes. Try to untick Mail but it might complain.
If it does complain go to mail and remove the mail account.
Then go to Preferences again and untick the Mail. Now remove the iCloud account by using the "-".
Now add your iCloud account and ensure you tick "Documents & Data".
Now go to Pages etc and when you start it should let you look at your iclid files.
Just the ticket.
Friday, October 26, 2012
Create an ISO image of a DVD on Mac OS X
It seems to be a bit more difficult to create ISO images on the recent Mac Mountain Lion. Though I never did it before, it seems that an option to create an ISO was a part of the Disk Utiltiy application. Now though you can only make a .dmg.
You can try to copy all the files from a DVD to a folder and use Disk Utility to create an ISO but you'll have problems with extended attributes if copying a Mac OS X Install disc.
This works ok.
1. Open Terminal.
2. Now find where the DVD is mounted.
We can check using: mount
I notice that in my example mount gave:
You need to unmount the DVD drive by running: umount
This will need to be run as super user (sudo) and this will require your password.
You now need to run the dd command:
You can try to copy all the files from a DVD to a folder and use Disk Utility to create an ISO but you'll have problems with extended attributes if copying a Mac OS X Install disc.
This works ok.
1. Open Terminal.
2. Now find where the DVD is mounted.
Type :
drutil statusThis will tell us where the drive is mounted. It will look something like:
John-Mac-mini:Desktop John$ drutil status Vendor Product Rev HL-DT-ST DVDRW GA32N KC12
Type: DVD-ROM Name: /dev/disk1 Sessions: 1 Tracks: 1 Overwritable: 00:00:00 blocks: 0 / 0.00MB / 0.00MiB Space Free: 00:00:00 blocks: 0 / 0.00MB / 0.00MiB Space Used: 843:15:63 blocks: 3794688 / 7.77GB / 7.24GiB Writability: Book Type: DVD-ROM (v1)
We can check using: mount
John-Mac-mini:Desktop John$ mount/dev/disk0s2 on / (hfs, local, journaled)devfs on /dev (devfs, local, nobrowse)map -hosts on /net (autofs, nosuid, automounted, nobrowse)map auto_home on /home (autofs, automounted, nobrowse)/dev/disk2s3 on /Volumes/My Book Time Machine (hfs, local, nodev, nosuid, journaled)/dev/disk1s3 on /Volumes/Mac OS X Install DVD (hfs, local, nodev, nosuid, read-only, noowners)
I notice that in my example mount gave:
/dev/disk1s3and drutil gave:
/dev/disk1
You need to unmount the DVD drive by running: umount
This will need to be run as super user (sudo) and this will require your password.
sudo umount /dev/disk1
Password:
You now need to run the dd command:
sudo dd if=/dev/disk1s3 of="my file name.iso"
Copy DVD contents to a folder on OSX using Terminal
Open, Terminal
Job done.
Type
df
This will give us the device names.
You will see something like:
/dev/disk1s3 13158216 12992304 165912 99% 1624036 20739 99% /Volumes/My DVD stuff
You can highlight and copy the DVD information using cmd C.
Copy your equivalent to this:
/Volumes/My DVD stuff
Then navigate to the target folder (using the cd command) such as:
cd /Users/John/Desktop/my target folder/
Now we can do the copying from the DVD to where we are.
cp -rpv "/Volumes/My DVD stuff" ./If you want it to run quietly, then leave of the v option for verbose. Then if it will only report errors to the screen.
cp -rp
Job done.
Subscribe to:
Posts (Atom)




