
I don't have interrupts (so no disk, or keyboard) and I can't create processes, but I can (almost) print "Hello world".
Except, I can't print capital letters, or spaces...
Have a seat in the comfy chair. Or log into the supercomputing cluster and check your 'weezy-mail'.
set $var $tm
lappend ::dl $var
lappend ::al $var
pack [frame .tMain.f$var] -side top -expand 1 -fill x
pack [label .tMain.lT$var -text $tx] -in .tMain.f$var -side left
pack [label .tMain.l$var] -in .tMain.f$var -side right
proc decList {il} {
upvar $il l
# foreach variable in the list
foreach iu $l {
upvar $iu i
# decrement it
incr i -1
# update the GUI
.tMain.l$iu configure -text [tformat $i]
# check for timer expire
if {$i == 0} {
# remove the timer from the list
set idx [lsearch $l $iu]
set l [lreplace $l $idx $idx]
# flash the text
after 1000 ".tMain.lT$iu configure -fg #008800"
after 5000 ".tMain.lT$iu configure -fg #000000"
playSound
}
}
}
$ cat orders_P2_2400.tcl
set owd [pwd]
cd ../../../gui/tcl
load ./nstclgui.so
source nsCli.tcl
set nsGui::playerNum [newStars $::ns_open $owd/tiny_sparse_P2_Y2400.xml]
buildMyPlanetMap
set hwPID $nsGui::myPlanetMap(0)
set fid [findFleetByName "Armed Probe #2443026239740"]
sendFleetToPlanet "Armed Probe #2443026239740" [findPlanetByName Pervo]
sendFleetToPlanet "Armed Probe #2443026239740"
sendFleetToPlanet "Armed Probe #2443026239740"
# get a useful scout
newStars $::ns_design $::ns_loadPre scout "Smaugarian Peeping Tom"
newStars $::ns_design $::ns_save
# build it
newStars $::ns_planet $hwPID $::ns_addAtIndex 0 0 1 $::designMap(3)
# set orders for max growth
for {set i 0} {$i < 100} {incr i} {
newStars $::ns_planet $hwPID $::ns_addAtIndex 1 1 3
newStars $::ns_planet $hwPID $::ns_addAtIndex 2 1 4
}
newStars $::ns_save $owd/tiny_sparse_P2_Y2400.xml
for {set i 0} {$i < $numDesigns} {incr i} {
pack [frame .tSplitter.fTop.fRow$i] -side top
set shipName [newStars $::ns_planet $fid $::ns_design $i $::ns_getName]
pack [label .tSplitter.fTop.fRow$i.lL -text $shipName] -side left
set shipCt [newStars $::ns_planet $fid $::ns_design $i $::ns_getNumFleets]
pack [label .tSplitter.fTop.fRow$i.lLC -text $shipCt] -side left
pack [button .tSplitter.fTop.fRow$i.bL -text "<" -command "adjustSplitRes $i -1"] -side left
pack [button .tSplitter.fTop.fRow$i.bR -text ">" -command "adjustSplitRes $i 1"] -side left
pack [label .tSplitter.fTop.fRow$i.lRC -text 0] -side left
lappend ::splitRes [list $shipCt 0]
}
proc adjustSplitRes {row val} {
set left [.tSplitter.fTop.fRow$row.lLC cget -text]
set rght [.tSplitter.fTop.fRow$row.lRC cget -text]
if {$left < $val} {return}
if {$rght < -$val} {return}
set left [expr $left - $val]
set rght [expr $rght + $val]
lset ::splitRes $row 0 $left
lset ::splitRes $row 1 $rght
.tSplitter.fTop.fRow$row.lLC configure -text $left
.tSplitter.fTop.fRow$row.lRC configure -text $rght
}
Phalanx | 1 | 2 |
Musketeer | 2 | 3 |
Rifleman | 3 | 5 |
Mechanized Infantry | 6 | 6 |
Horseman | 2 | 1 |
Legion | 3 | 1 |
Chariot | 4 | 1 |
Catapult | 6 | 1 |
Cannon | 9 | 1 |
Tank | 10 | 5 |
Artillery | 12 | ? |
Chance of win = attack / (attack + defense)So, a horseman attacking a phalanx has a 50% chance of winning. Of course, as a military option, a 50% chance isn't very attractive. I'm going to need an equal number of attackers as defenders, and defenders get an advantage for terrain and digging in ("fortifying").
#!/usr/bin/bash
for i in {1..100}
do
./d_prime.exe > /dev/null
done
uint ct = 0;
uint sqr = 4;
if( i >= sqr )
{
ct++;
sqr = primes[ct] * primes[ct];
}
if( isPrime(i, primes[0..ct+1]) )
bool isPrime(unsigned n, const std::vector<unsigned>::const_iterator b,
const std::vector<unsigned>::const_iterator e)
for(std::vector<unsigned>::const_iterator i = b; i != e; ++i)
if( isPrime(i, primes.begin(), primes.begin()+ct+1) )
import std.stdio;
bool isPrime(uint n, uint[] curPrimes)
{
foreach(i; curPrimes)
{
if( n % i == 0 )
{
return false;
}
}
return true;
}
void main(char[][] args)
{
uint[] primes;
primes ~= 2;
uint i = 3;
while( i < 1000 )
{
if( isPrime(i, primes) )
{
primes ~= i;
}
i += 2;
}
writefln(primes.length);
writefln(1);
foreach(j; primes)
{
writefln(j);
}
}
#include <iostream>
#include <vector>
bool isPrime(unsigned n, const std::vector<unsigned> &curPrimes)
{
for(std::vector<unsigned>::const_iterator i = curPrimes.begin();
i != curPrimes.end(); ++i)
{
if( n % *i == 0 )
{
return false;
}
}
return true;
}
int main(int argc, char **argv)
{
std::vector<unsigned> primes;
primes.push_back(2);
unsigned i = 3;
while( i < 1000 )
{
if( isPrime(i, primes) )
{
primes.push_back(i);
}
i += 2;
}
std::cout << primes.size() << std::endl;
std::cout << 1 << std::endl;
for(std::vector<unsigned>::const_iterator i = primes.begin();
i != primes.end(); ++i)
{
std::cout << *i << std::endl;
}
return 0;
}
main.cpp: In member function `void Test<t>::test()':
main.cpp:11: error: expected `;' before "i"
main.cpp:11: error: `i' undeclared (first use this function)
main.cpp:11: error: (Each undeclared identifier is reported only once for each function it appears in.)
main.cpp: In member function `void Test<t>::test() [with T = int]':
main.cpp:20: instantiated from here
main.cpp:11: error: dependent-name ` std::vector<t,std::allocator<_chart> >::const_iterator' is parsed as a non-type, but instantiation yields a type
main.cpp:11: note: say `typename std::vector<t,std::allocator<_chart> >::const_iterator' if a type is meant
#include <vector>
#include <cstdio>
template<typename T>
class Test
{
public:
void test(void)
{
std::vector<T> v;
for(std::vector<T>::const_iterator i = v.begin(); i != v.end(); ++i)
printf("%p\n", &*i);
}
};
int main(int argc, char **argv)
{
Test<int> t;
t.test();
return 0;
}
$ diff main.bad.cpp main.cpp
11c11
< for(std::vector<T>::const_iterator i = v.begin(); i != v.end(); ++i)
---
> for(typename std::vector<T>::const_iterator i = v.begin(); i != v.end(); ++i)
"The main contenders were Tcl and, far behind, Forth and Perl."That's pretty interesting to see. What made them not use Tcl?
"In 1993, Tcl and Perl ran only on Unix platforms."That's a real shame. I was introduced to Tcl in 1999, when there was already a Windows version. I'm not sure when the code was first ported to Windows, I found a Usenet post from comp.lang.tcl called "New Release of TkWin -- Tk for Windows" discussing version 0.2, from Jul 18 1994. Incredible to think there may not have been a Lua by so slim a margin...
std::vector<MyCoolType*> myVec;
myVec.push_back(new MyCoolType);
for(std::vector<MyCoolType*>::const_iterator i = myVec.begin(); i != myVec.end(); ++i)
(**i).print();
MyCoolType[] myVec;
myVec ~= new MyCoolType
foreach(i; myVec)
i.print();
char[][char[]] strStrMap; // a map from string to string
int[int] intIntMap; // a map from int to int
char[][int] intStrMap; // a map from int to string
strStrMap["hello"] = "world";
intintMap[6] = 4; // Craw Giant
intStrMap[0] = "trample";
"the implementation of a string type in STL is over two thousand lines of code, using every advanced feature of templates. How much confidence can you have that this is all working correctly, how do you fix it if it is not, what do you do with the notoriously inscrutable error messages when there's an error using it, how can you be sure you are using it correctly"Vectors are built in to D:
char str1[8]; // eight chars, enough to hold a string of length 7 and the 0 terminator
char str2[]; // a variable size string
char *str3; // a C style unknown length string
std::string arg("Hi me");
if( "Hi me" == arg ) { printf("Yup"); }
operator==(const char*, std::string &);
Ret myFun(const char *charp)
{
FX::FXString foxStr(charp);
randomFoxFun(&foxStr);
std::string stlStr(foxStr.text());
randomStlFun(&stlStr);
// convert STL string to Fox String
// convert STL string to char*
}
if {![file exists [file join ~ $resourceFileName]]} {
close [open [file join ~ $resourceFileName] w]
} else {
eval [read [open [file join ~ $resourceFileName]]]
}
rename exit origExit
proc exit {} {
set f [open [file join ~ $::resourceFileName] w]
foreach n [lsort [array names nsGui::prevFiles]] {
puts $f "set nsGui::prevFiles($n) \{$nsGui::prevFiles($n)\}"
}
origExit
}