From 17a81b9fea1ad3d3de465956dd0bdbf333a32d80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Wed, 3 Jan 2018 00:55:15 +0100 Subject: [PATCH] bef runner bug fixes --- www/data/css/styles.css | 2 ++ www/data/css/styles_befungerunner.scss | 2 ++ www/data/javascript/blogpost_bef93runner.js | 28 +++++++++++-------- www/fragments/befunge93_runner.php | 2 +- www/fragments/blogview_euler_single.php | 4 +-- .../euler/Euler_Problem-011_explanation.md | 3 +- 6 files changed, 25 insertions(+), 16 deletions(-) diff --git a/www/data/css/styles.css b/www/data/css/styles.css index 0a125cb..7ecf9af 100644 --- a/www/data/css/styles.css +++ b/www/data/css/styles.css @@ -623,6 +623,8 @@ html, body { padding: 5px 9.5px; line-height: 12pt; font-size: 10pt; } + .bce_code .bce_code_data { + white-space: pre; } .bce_code .bce_code_editarea { display: block; resize: none; diff --git a/www/data/css/styles_befungerunner.scss b/www/data/css/styles_befungerunner.scss index 86bb20e..3cf32a8 100644 --- a/www/data/css/styles_befungerunner.scss +++ b/www/data/css/styles_befungerunner.scss @@ -14,6 +14,8 @@ font-size: 10pt; } + .bce_code_data { white-space: pre; } + .bce_code_editarea { display: block; resize: none; diff --git a/www/data/javascript/blogpost_bef93runner.js b/www/data/javascript/blogpost_bef93runner.js index 9d1b2fd..20a8691 100644 --- a/www/data/javascript/blogpost_bef93runner.js +++ b/www/data/javascript/blogpost_bef93runner.js @@ -33,7 +33,7 @@ function BefObject(domBase) { this.state = BefState.INITIAL; this.initial = atob(this.pnlCode.getAttribute('data-b93rnr_code')); - this.simspeed = BefSpeed.get(domBase.hasAttribute('data-b93rnr_initialspeed') ? domBase.getAttribute('data-b93rnr_initialspeed') : '4'); + this.simspeed = BefSpeed.get(domBase.hasAttribute('data-b93rnr_initialspeed') ? domBase.getAttribute('data-b93rnr_initialspeed') : BefSpeed.SUPERFAST.val); this.code = []; this.width = 0; this.height = 0; @@ -172,7 +172,7 @@ BefObject.prototype.step = function() { let t0 = performance.now(); let stepc = 0; - while(this.state=== BefState.RUNNING && (stepc===0 || (performance.now() - t0 < 16)) && stepc < 128) // 16ms == 60FPS + while(this.state=== BefState.RUNNING && (stepc===0 || (performance.now() - t0 < 16)) && stepc < 1024) // 16ms == 60FPS { this.stepSingle(); stepc++; @@ -364,13 +364,16 @@ BefObject.prototype.getDisplayHTML = function() { for (let x=0; x < this.width; x++) { let cc = this.code[y][x]; let chr = String.fromCharCode(cc); - if (chr === '&') chr = '&'; - if (chr === '<') chr = '<'; - if (chr === '>') chr = '>'; - if (chr === ' ') chr = ' '; - if (cc===0) chr = '0'; - else if (cc>127 || cc<32) chr = '?'; - if (x === this.position[0] && y === this.position[1]) chr = '' + chr + ''; + + if (chr === '&') chr = '&'; + else if (chr === '<') chr = '<'; + else if (chr === '>') chr = '>'; + else if (cc === 32 ) chr = ' '; + else if (cc<10 && cc>=0 ) chr = ''+cc+''; + else if (cc<32 && cc>=10) chr = ''+String.fromCharCode(65+cc)+''; + else if (cc>127 || cc<0 ) chr = 'X'; + + if (x === this.position[0] && y === this.position[1]) chr = '' + chr + ''; str += chr; } str += '
'; @@ -400,18 +403,19 @@ BefObject.prototype.updateDisplay = function() { }; BefObject.prototype.parseBef = function(str) { - const lines = str.replace('\r\n', '\n').split('\n').map(function(str){return str.replace(/\s+$/, '')}); + const lines = str.replace('\r', '').split('\n'); let max = 0; for (let line of lines) max = Math.max(max, line.length); let result = []; - for (let line of lines) + for (let _line of lines) { + let line = _line.replace('\r', '').replace('\n', ''); let row = []; for(let i=0; i < max; i++) { - row.push((i < line.length ? (line[i]) : ' ').charCodeAt(0)); + row.push((i < line.length ? (line[i].charCodeAt(0)) : 32)); } result.push(row) } diff --git a/www/fragments/befunge93_runner.php b/www/fragments/befunge93_runner.php index 67591dc..914bdc2 100644 --- a/www/fragments/befunge93_runner.php +++ b/www/fragments/befunge93_runner.php @@ -11,7 +11,7 @@ $editable = $PARAM_BEFUNGE93RUNNER['editable']; function fmtBef($str) { $str = htmlspecialchars($str); - $str = str_replace("\r\n", "\n", $str); + $str = str_replace("\r", "", $str); $str = join("\n", array_map(function($p){return rtrim($p);}, explode("\n", $str))); $str = str_replace(' ', ' ', $str); $str = nl2br($str); diff --git a/www/fragments/blogview_euler_single.php b/www/fragments/blogview_euler_single.php index 4a380b6..2cafa19 100644 --- a/www/fragments/blogview_euler_single.php +++ b/www/fragments/blogview_euler_single.php @@ -53,7 +53,7 @@ $max = ceil($max / 20) * 20; 'code' => file_get_contents($problem['file_code']), 'url' => $problem['url_raw'], 'interactive' => !$problem['abbreviated'], - 'speed' => null, + 'speed' => $problem['steps'] < 500000 ? 2 : 3, 'editable' => false, ]; echo require (__DIR__ . '/../fragments/befunge93_runner.php'); @@ -73,7 +73,7 @@ $max = ceil($max / 20) * 20; Execution time (BefunExec): - (=' . (($problem['time']===0) ? '?' : number_format(($problem['steps']/$problem['time'])/1000, 2, '.', '')) . ' MHz)'; ?> + (' . (($problem['time']===0) ? '?' : number_format(($problem['steps']/$problem['time'])/1000, 2, '.', '')) . ' MHz)'; ?> Program size: diff --git a/www/statics/euler/Euler_Problem-011_explanation.md b/www/statics/euler/Euler_Problem-011_explanation.md index 9a8b9c4..2035829 100644 --- a/www/statics/euler/Euler_Problem-011_explanation.md +++ b/www/statics/euler/Euler_Problem-011_explanation.md @@ -1 +1,2 @@ -The idea here was to first move the numbers into a *real* 20x20 grid where every field represents a single number, the rest was not that hard. \ No newline at end of file +The idea here was to first move the numbers into a *real* 20x20 grid where every field represents a single number, +the rest was just brute-forcing all possible products and outputting the biggest. \ No newline at end of file