@justyy 's series of Logits Tests: - [Introduction to Logic Tests Series](https://helloacm.com/introduction-to-logic-tests-series/) What you can do with this tiny programming language with only 4 instructions? Today, we are going to implement the DECR function which decrements the variable by one, for example, DECR(X) where X=5 will make X=4. ``` DECR(X) { } ``` The only 4 instructions are: INCR, LOOP, ZERO and ASGN. And all variables hold non-negative integers. To make X decremented by 1, we can increment a temp variable by (X-1) times.. ``` DECR(X) { ZERO(V1) LOOP(X) { ASGN(X, V1) INCR(V1) } } ``` We translate this to [C++](https://helloacm.com/c-coding-exercise-use-hashtablepriority-queue-to-compute-the-relative-ranks/), which might be a bit easy to understand. ``` void decr(unsigned int &x) { int v1 = 0; int xx = x; for (; x > 0; -- x) { xx = v1; v1 ++; } x = xx; } ``` If you change the value of the loop variable x, the loop iteration count may be altered. Therefore, we declare a temp variable xx and assign the xx to X after loop when it gets incremented (x-1) times.  *Image Credit: pixabay.com* @justyy 的逻辑测试系列: - [逻辑测试系列 - 一种只有4种语句的编程语言 - (1)](https://justyy.com/archives/5320) 这种只有4条语句的语言能做什么呢?今天我们来定义一个DECR函数,该函数就是把 变量 X 减一。 ``` DECR(X) { } ``` 要求填写函数体,使用 INCR、LOOP、ZERO、和 ASGN 仅有的4个语句。我们不妨想一下,已知变量 X 是非负整数,那么我们只需要 循环 X-1次,每次把X从0加1即可。 ``` DECR(X) { ZERO(V1) LOOP(X) { ASGN(X, V1) INCR(V1) } } ``` 我们翻译成 [C++](https://justyy.com/archives/2257), 可能比较好懂一些: ``` void decr(unsigned int &x) { int v1 = 0; int xx = x; for (; x > 0; -- x) { xx = v1; v1 ++; } x = xx; } ``` 由于C++的 for 里改变 x 值会改变循环次数,所以我们用了一个临时变量 xx。  STEEMIT 中文区 RSS 工具和名单: - [SteemIt 好友微信群排行榜](https://helloacm.com/tools/steemit/wechat/) - [SteemIt 好友微信群文章列表](https://helloacm.com/tools/steemit/wechat/rss/) - [SteemIt 好友微信群评论列表](https://helloacm.com/tools/steemit/wechat/rss/comments/) Chrome 插件: - [隐藏收益,专注写作!](https://justyy.com/archives/5269) - [简繁体自动转换](https://justyy.com/archives/5016) Steem API: - [获取微信群成员关注和粉丝的API](https://justyy.com/archives/5241) - [SteemIt API/transfer-history 最简单获取帐号钱包记录的API](https://justyy.com/archives/5070) - [简单封装了一下 steemit/account](https://justyy.com/archives/5063) 最近帖子: - [CN 每日排行榜](https://steemit.com/cn/@justyy/daily-cn-updates---cn72017-09-18) - [记一次通过手机TeamViewer远程登陆家里服务器再远程登陆VPS敲命令在STEEMIT上发贴的经历](https://steemit.com/cn/@justyy/teamviewer-vps-steemit-the-experience-of-using-teamviewer-on-iphone-se-connecting-to-desktop-and-ssh-to-vps-in-order-to-make-a) - [即使你不打算换工作,你每年也得去面试](https://steemit.com/cn/@justyy/go-to-an-interview-even-if-you-are-not-changing-your-job) - [STEEM中文区剪刀石头布大赛 - 第一期 (奖金30 SBD + 帖子SBD收益)](https://steemit.com/cn/@justyy/steem-50-sbd) STEEMIT CN RSS Tools: - [SteemIt Daily Wechat Group Ranking ](https://helloacm.com/tools/steemit/wechat-ranking/) - [SteemIt CN RSS for Posts](https://helloacm.com/tools/steemit/wechat-ranking/rss/) - [SteemIt CN RSS for Comments](https://helloacm.com/tools/steemit/wechat-ranking/rss/comments/) Chrome Extensions: - [Hide Steemit Payout](https://helloacm.com/hide-steemit-payout/) - [Simplified to Traditional Switch](https://helloacm.com/chrome-extension-to-switch-between-simplified-chinese-and-traditional-chinese-automatically/) Steem API: - [Two APIs to get the followers and following list in the Wechat Group](https://helloacm.com/steemit-api-two-apis-to-get-the-followers-and-following-list-in-the-wechat-group/) - [SteemIt API/transfer-history](https://helloacm.com/how-to-get-transfer-history-of-steemit-accounts-via-steemit-apitransfer-history/) - [steemit/account](https://helloacm.com/how-to-retrieve-steemit-account-information-via-api-steemitaccount/) Recent Posts: - [Daily Top 30 Authors by Pending Payout in Last 7 Days](https://steemit.com/stats/@dailystats/daily-top-30-authors-pending-payout-in-the-last-7-days-2017-09-17) - [The experience of using Teamviewer on iPhone SE, connecting to desktop, and SSH to VPS, in order to make a Robot Python script up running.](https://steemit.com/cn/@justyy/teamviewer-vps-steemit-the-experience-of-using-teamviewer-on-iphone-se-connecting-to-desktop-and-ssh-to-vps-in-order-to-make-a) - [Go to an Interview even if you are not changing your job.](https://steemit.com/cn/@justyy/go-to-an-interview-even-if-you-are-not-changing-your-job) - [Rock-Paper-Scissors Gaming Contest for SteemIt CN Community](https://steemit.com/cn/@justyy/steem-50-sbd) // Later, it may be reposted to my blogs: [justyy.com](https://justyy.com), [helloacm.com](https://helloacm.com) and [codingforspeed.com](https://codingforspeed.com) 稍后同步到我的[中文博客](https://justyy.com)和英文[计算机](https://helloacm.com)[博客](https://codingforspeed.com)。 - [逻辑测试系列之二 – DECR](https://justyy.com/archives/5339) - [Logic Tests Series (2) – DECR](https://helloacm.com/logic-tests-series-2-decr/) - [记一次通过手机TeamViewer远程登陆家里服务器再远程登陆VPS敲命令在STEEMIT上发贴的经历](https://justyy.com/archives/5322) - [The experience of using Teamviewer on iPhone SE, connecting to desktop, and SSH to VPS, in order to make a Robot Python script up running.](https://helloacm.com/the-experience-of-using-teamviewer-on-iphone-se-connecting-to-desktop-and-ssh-to-vps-in-order-to-make-a-robot-python-script-up-running/) Originally published at https://steemit.com Thank you for reading my post, feel free to Follow, Upvote, Reply, ReSteem (repost) @justyy which motivates me to create more quality posts. 原文首发于 https://Steemit.com 首发。感谢阅读,如有可能,欢迎Follow, Upvote, Reply, ReSteem (repost) @justyy 激励我创作更多更好的内容。
author | justyy |
---|---|
permlink | logic-tests-series-2-decr-decr |
category | cn |
json_metadata | {"tags":["cn","cn-programming","steemstem","interview","coding"],"users":["justyy"],"image":["https://cdn.pixabay.com/photo/2016/11/19/14/00/code-1839406_960_720.jpg","https://justyy.com/wp-content/uploads/2017/07/justyy-steemit.png"],"links":["https://helloacm.com/introduction-to-logic-tests-series/","https://helloacm.com/c-coding-exercise-use-hashtablepriority-queue-to-compute-the-relative-ranks/","https://justyy.com/archives/5320","https://justyy.com/archives/2257","https://helloacm.com/tools/steemit/wechat/","https://helloacm.com/tools/steemit/wechat/rss/","https://helloacm.com/tools/steemit/wechat/rss/comments/","https://justyy.com/archives/5269","https://justyy.com/archives/5016","https://justyy.com/archives/5241","https://justyy.com/archives/5070","https://justyy.com/archives/5063","https://steemit.com/cn/@justyy/daily-cn-updates---cn72017-09-18","https://steemit.com/cn/@justyy/teamviewer-vps-steemit-the-experience-of-using-teamviewer-on-iphone-se-connecting-to-desktop-and-ssh-to-vps-in-order-to-make-a","https://steemit.com/cn/@justyy/go-to-an-interview-even-if-you-are-not-changing-your-job","https://steemit.com/cn/@justyy/steem-50-sbd","https://helloacm.com/tools/steemit/wechat-ranking/","https://helloacm.com/tools/steemit/wechat-ranking/rss/","https://helloacm.com/tools/steemit/wechat-ranking/rss/comments/","https://helloacm.com/hide-steemit-payout/","https://helloacm.com/chrome-extension-to-switch-between-simplified-chinese-and-traditional-chinese-automatically/","https://helloacm.com/steemit-api-two-apis-to-get-the-followers-and-following-list-in-the-wechat-group/","https://helloacm.com/how-to-get-transfer-history-of-steemit-accounts-via-steemit-apitransfer-history/","https://helloacm.com/how-to-retrieve-steemit-account-information-via-api-steemitaccount/","https://steemit.com/stats/@dailystats/daily-top-30-authors-pending-payout-in-the-last-7-days-2017-09-17","https://justyy.com","https://helloacm.com","https://codingforspeed.com","https://justyy.com/archives/5339","https://helloacm.com/logic-tests-series-2-decr/","https://justyy.com/archives/5322","https://helloacm.com/the-experience-of-using-teamviewer-on-iphone-se-connecting-to-desktop-and-ssh-to-vps-in-order-to-make-a-robot-python-script-up-running/","https://steemit.com","https://Steemit.com"],"app":"steemit/0.1","format":"markdown"} |
created | 2017-09-18 11:30:42 |
last_update | 2017-09-18 21:52:33 |
depth | 0 |
children | 3 |
last_payout | 2017-09-25 11:30:42 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 21.497 HBD |
curator_payout_value | 5.589 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 5,743 |
author_reputation | 280,616,224,641,976 |
root_title | "Logic Tests Series (2) - DECR 逻辑测试系列之二 - DECR" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 15,218,122 |
net_rshares | 10,564,292,194,507 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
abit | 0 | 3,843,238,025,261 | 10% | ||
fundurian | 0 | 34,823,941,278 | 25% | ||
arcange | 0 | 33,478,268,209 | 10% | ||
raphaelle | 0 | 5,486,686,308 | 10% | ||
quigua | 0 | 601,695,799 | 100% | ||
ace108 | 0 | 229,073,909,186 | 15% | ||
tensaix2j | 0 | 2,890,305,300 | 100% | ||
myfirst | 0 | 82,056,586,576 | 100% | ||
cryptoninja | 0 | 254,357,752 | 2% | ||
elfkitchen | 0 | 13,034,810,414 | 100% | ||
archiles | 0 | 126,330,788 | 100% | ||
ericsim1991 | 0 | 121,583,794 | 100% | ||
ericsim1989 | 0 | 126,856,568 | 100% | ||
tumutanzi | 0 | 1,270,414,781,595 | 7% | ||
justyy | 0 | 68,218,039,991 | 100% | ||
anomaly | 0 | 365,785,924 | 1% | ||
lotol | 0 | 122,771,947 | 100% | ||
ceredarhukelv | 0 | 122,687,632 | 100% | ||
birds90 | 0 | 15,478,880,340 | 100% | ||
rach | 0 | 12,583,920,753 | 100% | ||
dapeng | 0 | 78,164,997,699 | 100% | ||
happyukgo | 0 | 577,389,753 | 100% | ||
anbatamers | 0 | 335,267,277 | 100% | ||
zhuchok | 0 | 533,785,558 | 100% | ||
bilo | 0 | 535,278,704 | 100% | ||
sansay | 0 | 534,737,188 | 100% | ||
ananasik | 0 | 537,962,822 | 100% | ||
daio | 0 | 16,047,198,731 | 100% | ||
jonahyates | 0 | 538,605,709 | 100% | ||
hammadakhtar | 0 | 1,276,325,691 | 10% | ||
htliao | 0 | 1,886,558,011,763 | 11% | ||
sv67216721 | 0 | 4,531,176,116 | 5% | ||
frankintaiwan | 0 | 88,324,461 | 20% | ||
unatalmaria | 0 | 2,549,639,577 | 20% | ||
followbtcnews | 0 | 3,130,275,082 | 5% | ||
marcevhc | 0 | 2,446,225,311 | 50% | ||
monoc | 0 | 1,438,571,695 | 100% | ||
nanosesame | 0 | 15,508,062,553 | 100% | ||
linuslee0216 | 0 | 2,809,540,883,017 | 15% | ||
viralcutz | 0 | 553,905,055 | 10% | ||
suitablybored | 0 | 324,122,544 | 100% | ||
anfitriones | 0 | 294,459,307 | 50% | ||
ronel | 0 | 1,548,317,933 | 85.55% | ||
rjhisle1973 | 0 | 621,340,000 | 100% | ||
cardumen | 0 | 323,352,602 | 60% | ||
shenchensucc | 0 | 17,098,174,519 | 100% | ||
lesya97 | 0 | 620,923,670 | 100% | ||
sanks7 | 0 | 253,113,613 | 5% | ||
walkinharmony | 0 | 9,599,372,642 | 85.55% | ||
nataliejohnson | 0 | 2,937,868,533 | 5% | ||
mady27 | 0 | 12,307,083,742 | 100% | ||
minnowpond | 0 | 1,214,224,590 | 1% | ||
minnowpond1 | 0 | 147,240,329 | 1% | ||
colmanlamkh | 0 | 2,366,645,947 | 100% | ||
andrey32 | 0 | 627,786,013 | 100% | ||
levmue | 0 | 3,513,126,489 | 85.55% | ||
thomasmmaker | 0 | 1,165,735,349 | 100% | ||
seyico2011 | 0 | 263,349,893 | 50% | ||
hannahwu | 0 | 9,180,253,320 | 51% | ||
davidzack | 0 | 381,235,795 | 100% | ||
hawk1987 | 0 | 70,108,121 | 85.55% | ||
jackyx2clic | 0 | 105,409,599 | 85.55% | ||
kangnajiang | 0 | 2,139,777,621 | 100% | ||
dombievich | 0 | 620,303,941 | 100% | ||
geass | 0 | 752,609,690 | 100% | ||
moonvoid | 0 | 607,452,884 | 100% | ||
karasui | 0 | 4,252,977,612 | 100% | ||
ghady | 0 | 638,364,372 | 100% | ||
shepilvika | 0 | 620,840,121 | 100% | ||
tvb | 0 | 6,020,830,855 | 100% | ||
goldminevoyager | 0 | 627,664,361 | 100% | ||
tinkatinka | 0 | 620,551,194 | 100% | ||
skenan | 0 | 1,565,382,157 | 100% | ||
sunnyjolly | 0 | 6,878,565,939 | 100% | ||
iravolsha | 0 | 620,014,968 | 100% | ||
tirudimich | 0 | 616,832,789 | 100% | ||
brazh | 0 | 611,405,692 | 100% | ||
ericsim | 0 | 319,052,800 | 100% | ||
deskart | 0 | 337,896,416 | 100% | ||
lyubavirz | 0 | 617,366,291 | 100% | ||
dreevashey | 0 | 1,162,836,794 | 100% | ||
danielfinn | 0 | 262,081,608 | 20% | ||
tetayvale | 0 | 1,145,757,989 | 100% | ||
kihase | 0 | 110,340,739 | 10% | ||
tednion | 0 | 1,162,089,139 | 100% | ||
sabbir24 | 0 | 192,186,041 | 85.55% | ||
salaheldeen0 | 0 | 230,229,137 | 85.55% | ||
xeyez | 0 | 887,885,728 | 100% | ||
fury123 | 0 | 1,526,688,994 | 100% | ||
xuran | 0 | 2,656,227,723 | 100% | ||
awiwea1974 | 0 | 1,213,114,442 | 100% | ||
eduardpot | 0 | 1,160,631,473 | 100% | ||
cezah | 0 | 829,851,496 | 100% | ||
superbing | 0 | 2,239,345,900 | 100% | ||
drag0nballsuper | 0 | 197,994,107 | 85.55% | ||
dailyfortune | 0 | 1,320,837,696 | 100% | ||
sohel7421 | 0 | 286,561,086 | 85.55% | ||
qaismx | 0 | 879,736,807 | 85.55% | ||
ren64 | 0 | 1,154,825,237 | 100% | ||
xiaoshancun | 0 | 89,850,486 | 100% | ||
damitri | 0 | 1,160,627,806 | 100% | ||
onur1s | 0 | 637,914,435 | 100% | ||
dailystats | 0 | 1,154,540,797 | 100% | ||
saeedshaikh | 0 | 87,683,895 | 10% | ||
philiparniebinag | 0 | 1,892,711,712 | 100% | ||
thegoliath | 0 | 1,606,382,473 | 100% | ||
zaven | 0 | 806,631,476 | 100% | ||
paustov | 0 | 1,149,014,559 | 100% | ||
ckargatzis | 0 | 725,875,907 | 85.55% | ||
garalev | 0 | 1,131,603,752 | 100% | ||
vibelita | 0 | 313,367,066 | 55.5% | ||
technicalpaul | 0 | 407,427,534 | 85.55% | ||
quazonx | 0 | 576,661,084 | 100% | ||
dennisphillips | 0 | 145,077,042 | 25% | ||
navskiy | 0 | 1,160,615,961 | 100% | ||
medracen | 0 | 313,366,148 | 85.55% | ||
albart | 0 | 278,546,411 | 85.55% | ||
sumisristi | 0 | 63,833,375 | 85.55% | ||
eliry | 0 | 493,257,022 | 50% |
This post recieved an upvote from minnowpond. If you would like to recieve upvotes from minnowpond on all your posts, simply FOLLOW @minnowpond
author | minnowpond |
---|---|
permlink | re-logic-tests-series-2-decr-decr-20170918t114153 |
category | cn |
json_metadata | "{"app": "pysteem/0.5.4"}" |
created | 2017-09-18 11:41:54 |
last_update | 2017-09-18 11:41:54 |
depth | 1 |
children | 0 |
last_payout | 2017-09-25 11:41:54 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 143 |
author_reputation | 13,239,048,956,578 |
root_title | "Logic Tests Series (2) - DECR 逻辑测试系列之二 - DECR" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 15,218,939 |
net_rshares | 0 |
This post recieved an upvote from minnowpond. If you would like to recieve upvotes from minnowpond on all your posts, simply FOLLOW @minnowpond
author | minnowpond1 |
---|---|
permlink | re-logic-tests-series-2-decr-decr-20170918t220308 |
category | cn |
json_metadata | "{"app": "pysteem/0.5.4"}" |
created | 2017-09-18 22:03:09 |
last_update | 2017-09-18 22:03:09 |
depth | 1 |
children | 0 |
last_payout | 2017-09-25 22:03:09 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 143 |
author_reputation | 383,828,786,455 |
root_title | "Logic Tests Series (2) - DECR 逻辑测试系列之二 - DECR" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 15,269,027 |
net_rshares | 0 |
Thanks for the information. I'm eager to learn from this programming.
author | philiparniebinag |
---|---|
permlink | re-justyy-logic-tests-series-2-decr-decr-20170918t113350863z |
category | cn |
json_metadata | {"tags":["cn"],"app":"steemit/0.1"} |
created | 2017-09-18 11:33:51 |
last_update | 2017-09-18 11:33:51 |
depth | 1 |
children | 0 |
last_payout | 2017-09-25 11:33:51 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 69 |
author_reputation | 8,329,454,120,249 |
root_title | "Logic Tests Series (2) - DECR 逻辑测试系列之二 - DECR" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 15,218,347 |
net_rshares | 0 |