Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Programming Challenge #7 (by Plan9)
New Posts  All Forums:Forum Nav:

Programming Challenge #7 (by Plan9) - Page 5

post #41 of 50
Quote:
Originally Posted by Plan9 View Post

he's delete file method doesnt find the file

Ah.
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
post #42 of 50
No, when I try and call the file it doesn't find it.

I think I know why though.

EDIT: Yep.
Code:
using System;
using System.IO;
using System.Diagnostics;




namespace CalculatorPC7
{
    class Program
    {
        static void Main(string[] args)
        {
            File.Delete("C:\\Users\\{user}\\calc.exe");
            args = new string[0];
            Console.WriteLine("Enter a calculation.");
            string calc = Console.ReadLine();
            calc = calc.Trim();
            File.WriteAllText("C:\\Users\\{user}\\calc.cs",
                    "using System; static class Program { static void Main() { Console.WriteLine(\"The calculation equals \" + (" + calc + "));Console.ReadKey(true);}}");
            Process.Start("C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\csc.exe", "/out:C:\\Users\\{user}\\calc.exe C:\\Users\\{user}\\calc.cs");
            Stopwatch stopWtch = new Stopwatch();
            stopWtch.Start();
            while (stopWtch.ElapsedMilliseconds < 500)
            {
                //empty, just waiting for it to compile.
            }
            stopWtch.Stop();
            try
            {
                Process.Start("C:\\Users\\{user}\\calc.exe");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.ReadKey(true);
        }
    }
}
The empty while loop is basically sort of like a BASIC pause.
Very useful biggrin.gif
Edited by 3930K - 12/8/12 at 5:38am
post #43 of 50
Quote:
Originally Posted by 3930K View Post

No, when I try and call the file it doesn't find it.
I think I know why though.
EDIT: Yep.
Code:
using System;
using System.IO;
using System.Diagnostics;
namespace CalculatorPC7
{
    class Program
    {
        static void Main(string[] args)
        {
            File.Delete("C:\\Users\\{user}\\calc.exe");
            args = new string[0];
            Console.WriteLine("Enter a calculation.");
            string calc = Console.ReadLine();
            calc = calc.Trim();
            File.WriteAllText("C:\\Users\\{user}\\calc.cs",
                    "using System; static class Program { static void Main() { Console.WriteLine(\"The calculation equals \" + (" + calc + "));Console.ReadKey(true);}}");
            Process.Start("C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\csc.exe", "/out:C:\\Users\\{user}\\calc.exe C:\\Users\\{user}\\calc.cs");
            Stopwatch stopWtch = new Stopwatch();
            stopWtch.Start();
            while (stopWtch.ElapsedMilliseconds < 500)
            {
                //empty, just waiting for it to compile.
            }
            stopWtch.Stop();
            try
            {
                Process.Start("C:\\Users\\{user}\\calc.exe");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.ReadKey(true);
        }
    }
}
The empty while loop is basically sort of like a BASIC pause.
Very useful biggrin.gif

OUCH! tongue.gif
You should be waiting on the process handle of CSC. You've got a race condition, and you'd be better of solving it by waiting on the process handle (WaitForExit), than while loop hackery smile.gif
Code:
Process.Start( "C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\csc.exe", "/out:C:\\Users\\{user}\\calc.exe C:\\Users\\{user}\\calc.cs" ).WaitForExit();
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
post #44 of 50
Quote:
Originally Posted by tompsonn View Post

Quote:
Originally Posted by 3930K View Post

No, when I try and call the file it doesn't find it.
I think I know why though.
EDIT: Yep.
Code:
using System;
using System.IO;
using System.Diagnostics;
namespace CalculatorPC7
{
    class Program
    {
        static void Main(string[] args)
        {
            File.Delete("C:\\Users\\{user}\\calc.exe");
            args = new string[0];
            Console.WriteLine("Enter a calculation.");
            string calc = Console.ReadLine();
            calc = calc.Trim();
            File.WriteAllText("C:\\Users\\{user}\\calc.cs",
                    "using System; static class Program { static void Main() { Console.WriteLine(\"The calculation equals \" + (" + calc + "));Console.ReadKey(true);}}");
            Process.Start("C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\csc.exe", "/out:C:\\Users\\{user}\\calc.exe C:\\Users\\{user}\\calc.cs");
            Stopwatch stopWtch = new Stopwatch();
            stopWtch.Start();
            while (stopWtch.ElapsedMilliseconds < 500)
            {
                //empty, just waiting for it to compile.
            }
            stopWtch.Stop();
            try
            {
                Process.Start("C:\\Users\\{user}\\calc.exe");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.ReadKey(true);
        }
    }
}
The empty while loop is basically sort of like a BASIC pause.
Very useful biggrin.gif

OUCH! tongue.gif
You should be waiting on the process handle of CSC. You've got a race condition, and you'd be better of solving it by waiting on the process handle (WaitForExit), than while loop hackery smile.gif
Thanks!

EDIT: Updated version:
Code:
using System;
using System.IO;
using System.Diagnostics;

namespace CalculatorPC7
{
    class Program
    {
        static void Main(string[] args)
        {
            File.Delete("C:\\Users\\{user}\\calc.exe");
            args = new string[0];
            Console.WriteLine("Enter a calculation.");
            string calc = Console.ReadLine();
            calc = calc.Trim();
            File.WriteAllText("C:\\Users\\{user}\\calc.cs",
                    "using System; static class Program { static void Main() { Console.WriteLine(\"The calculation equals \" + (" + calc + "));Console.ReadKey(true);}}");
            Process csc = new Process();
            csc.StartInfo = new ProcessStartInfo("C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\csc.exe", "/out:C:\\Users\\{user}\\calc.exe C:\\Users\\{user}\\calc.cs");
            csc.Start();
            csc.WaitForExit();
            try
            {
                Process.Start("C:\\Users\\{user}\\calc.exe");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.ReadKey(true);
        }
    }
}

Edited by 3930K - 12/8/12 at 5:50am
post #45 of 50
So when do we get the next challenge? biggrin.gif
Bandaids
(15 items)
 
  
MotherboardGraphicsHard DriveOptical Drive
Asrock Z77 Extreme 6 GTX 580 WD 10EALX ASUS DRW 
CoolingOSMonitorMonitor
Havik 140 Windows 7 Ultimate ASUS VH228T Toshiba 32RV600A 
MonitorKeyboardPowerCase
Compaq S2021a Microsoft Wired Keyboard 600 Aero Cool Strike X 1100w Asus Antec 
MouseMouse PadAudio
Logitech MX518 Mionix Ensis 320 Creative 2.1 
  hide details  
Reply
Bandaids
(15 items)
 
  
MotherboardGraphicsHard DriveOptical Drive
Asrock Z77 Extreme 6 GTX 580 WD 10EALX ASUS DRW 
CoolingOSMonitorMonitor
Havik 140 Windows 7 Ultimate ASUS VH228T Toshiba 32RV600A 
MonitorKeyboardPowerCase
Compaq S2021a Microsoft Wired Keyboard 600 Aero Cool Strike X 1100w Asus Antec 
MouseMouse PadAudio
Logitech MX518 Mionix Ensis 320 Creative 2.1 
  hide details  
Reply
post #46 of 50
This seems like a good place to comment on Ken Thompson's paper "Reflections on Trusting Trust" (Warning: PDF) where he uses source outputting code to prove that real trust is a myth where code is concerned.

Maybe I'll post a solution later.
post #47 of 50
Thread Starter 
Quote:
Originally Posted by hajile View Post

This seems like a good place to comment on Ken Thompson's paper "Reflections on Trusting Trust" (Warning: PDF) where he uses source outputting code to prove that real trust is a myth where code is concerned.
Maybe I'll post a solution later.

funny enough that article touched on a subject that i was considering for the next challenge (subject to anyone jumping in before me with a better challenge)
post #48 of 50
Fairly easy.

User modifying code while program is running:
Code:
#!/usr/bin/mumps

write "Enter code to execute: "
read word
set code = word
xecute @code

Edited by Bobicon - 4/7/13 at 12:45am
Bob's Computer
(16 items)
 
  
CPUMotherboardGraphicsRAM
Intel i5 2500K MSI P67A-G45 MSI 6970 Lightning 2GB G Skill Ripjaws X (2x4GB) 1866mhz 9-10-9-28 
Hard DriveOptical DriveCoolingOS
Corsair Force 3 SSD (60GB), X1 WD5000AAKS, X1 W... ASUS DRW-24B1ST/BLK/B/AS Black SATA 24X DVD Burner Noctua NH-C14 Windows 7 64 bit 
MonitorKeyboardPowerCase
Asus VH238H Logitech G510 HALE90 750W NZXT Phantom Black 
MouseMouse PadAudioOther
Logitech G9x SteelSeries 4HD ASUS Xonar DGX / Audio-Technica ATH-AD700 Hauppauge! HVR-1250 TV Tuner 
  hide details  
Reply
Bob's Computer
(16 items)
 
  
CPUMotherboardGraphicsRAM
Intel i5 2500K MSI P67A-G45 MSI 6970 Lightning 2GB G Skill Ripjaws X (2x4GB) 1866mhz 9-10-9-28 
Hard DriveOptical DriveCoolingOS
Corsair Force 3 SSD (60GB), X1 WD5000AAKS, X1 W... ASUS DRW-24B1ST/BLK/B/AS Black SATA 24X DVD Burner Noctua NH-C14 Windows 7 64 bit 
MonitorKeyboardPowerCase
Asus VH238H Logitech G510 HALE90 750W NZXT Phantom Black 
MouseMouse PadAudioOther
Logitech G9x SteelSeries 4HD ASUS Xonar DGX / Audio-Technica ATH-AD700 Hauppauge! HVR-1250 TV Tuner 
  hide details  
Reply
post #49 of 50
Can anyone beat this (an assembly code):

label: mov [label],0


^^^ the shortest self-modifying code biggrin.gif

Greets,
Tomo
post #50 of 50
Thread Starter 
Quote:
Originally Posted by tomo70 View Post

Can anyone beat this (an assembly code):

label: mov [label],0


^^^ the shortest self-modifying code biggrin.gif

Greets,
Tomo

Nice introductory post. Have some rep smile.gif
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Programming Challenge #7 (by Plan9)